C# code question for automated system

Discussion in 'Automated Trading' started by abikambic, May 28, 2007.

  1. abikambic


    Would anyone know the C# code for the note in parenthesis that follows each enter long and enter short. Can not figure it out. Thanx Much.......

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    public override void Initialize()

    InitInstrument("GBPUSD"); Type.Minute1440;
    InitInstrument("GBPJPY"); Type.Minute720;
    InitInstrument("USDJPY"); Type.Minute720;

    CalculateOnBarClose = false;

    protected override void OnInstrumentUpdate(string instrument)

    // trading strategy
    if (High[0] > High[1])


    EnterLong(); This note in the parenthesis that follows must be coded.(Enter a long position if not long already,and if a short position is open,than (exit) the short position first than Enter the long position at the same price).

    // trading strategy
    if (Low[0] < Low[1])
    EnterShort(); This note in the parenthesis that follows must be coded.(Enter a short position if not short already,and if a long position is open,than sell(exit) the long position first than Enter the short position at the same price).

    #region Properties
  2. rickty


    You don't provide enough information to answer your questions.

    You need to look at the functions that are provided and give the prototype of the "enterlong" and "entershort" functions you would like to use. You will also need to determine what function is provided to determine the current market position.

    Alternatively, if you can you tell us where this C# code comes from, someone might be able to help you.

  3. What lib are you using?

    It's very very very... scary... when I see a newbie trying to run an ATS...
  4. promagma


    I hope this is a school project :D
  5. Is this NinjaScript?
  6. If you use the "CODE" tag the posted code will be more readable.
  7. cber


    Assuming this is a C# NinjaScript I believe what you're attempting to do is default behavior with EnterLong() and EnterShort(). You can always use Position.MarketPosition != MarketPosition.(Long,Short,Flat) in your if statement. You can also set EntriesPerDirection if you need to limit double entries in the same direction to 1.

    I'd recommend checking out http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html

    Good luck.
  8. if I were to make a suggestion I would not use Ninja Trader and instead use Open Quant. I used to have ninja trader until I switched. Ninja trader is just so limited in the amount of things you can do
  9. cber


    What is is about NT that is limited and/or makes Open Quant less limited? I'm certainly not being defensive or argumenative as I have never used Open Quant, but from my limited experience with NinjaTrader and NinjaScripts (C#) I seem to be limited only by my own imagination and logic ability. I'm relatively new to trading so perhaps there's more than I'm aware of that one would desire their script to be able to do.