Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Instruments Error.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Multi Instruments Error.

    Hello NinjaTrader Community,

    Help me !

    I simplify my code as much as possible.My code applyes to 6B. My problem is: When I apply to main chart*(6B) then I Add(one more instrument) everything works great. But when I add 3rd instrument (6b-main, 6c- second and 6j third) even if I do not do anthing in code, just "Add("6J 06-17",PeriodType.Tick,2);" then it doesnt work.
    Please help me how can I analyze, for example, according to MACD more than 2 pairs at the same time.
    One more question. How can I analyze, for example, the last 10 bars has range no more than 10 ticks.Demonstrate me the code please.

    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Add("6C 06-17",PeriodType.Tick,2);
    Add("6J 06-17",PeriodType.Tick,2);
    }
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 1)
    {
    if (CrossBelow(MACD(12, 26, 9).Avg, 0, 1))
    {
    EnterShort(2,10,"test1");
    }
    }



    Thank you guys In advance,
    Hope you have a great day
    Regards,
    Max

    #2
    Hello maxjoyce,

    Thanks for your post and welcome to the forums!

    Your example code does not show any exits.

    If I add an ExitShort to your code based on a crossbelow of the same macd I see orders on the 6J.

    What code are you using for exits?

    To see the range of the last 10 bars you could look at the differnce between the MAX(10)[0] and the MIN(10)[0]. References:
    http://ninjatrader.com/support/helpG...aximum_max.htm
    http://ninjatrader.com/support/helpG...inimum_min.htm

    Comment


      #3
      Thank you for MAX and MIN advice, it is clear for me now.
      But you didnt get me right. I got my code backtesting successfuly, placing orders and doing great,even if I have no "exit". Position ends at the end of every day. I think it stands for default.
      So I back test my strategy and it doing great but when I change my Initialize () from
      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      Add("6C 06-17",PeriodType.Tick,2);
      }

      to
      protected override void Initialize()
      {
      CalculateOnBarClose = true;
      Add("6C 06-17",PeriodType.Tick,2);
      Add("6J 06-17",PeriodType.Tick,2);
      }

      And run backtest it does not open any position. Like something wrong, EVEN if I make my enter position to my first instrument !
      Do you have any ideas why is that? At the beginnign backtest right, but when I add one line in "initialize" and run backtest it stops doing positions!? I have no clue why is that Heeelp )

      Comment


        #4
        Hello maxjoyce,

        Thanks for your post.

        Do you know if you have the needed historical data for backtesting for all three instruments for the duration of the backtest?

        You can check this a couple of ways:

        Easiest is to backtest the strategy SampleMACrossover on each individual instruments over the same period for all three. If each run shows trades then that would verify that you have some data for each.

        The other more thorough way to check is to go to Tools>Historical data manager and in the Historical data manager window click on the "edit" tab then search for each instrument and click the "+" to the left of the instument and drill down until you get to Tick and then you can go through each month/day as needed to validate that you have the historical tick data needed.

        Using your strategy, and removing the exitshort, I do get a single trade per day on 6J that ends on the exit on close. (see attached)
        Attached Files

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        558 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X