Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Paul H.NinjaTrader Customer Service

    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
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CortexZenUSA, Today, 12:53 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by CortexZenUSA, Today, 12:46 AM
        0 responses
        1 view
        0 likes
        Last Post CortexZenUSA  
        Started by usazencortex, Today, 12:43 AM
        0 responses
        5 views
        0 likes
        Last Post usazencortex  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        168 responses
        2,265 views
        0 likes
        Last Post sidlercom80  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X