Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time frame of Multi Instruments strategy does not match

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

    time frame of Multi Instruments strategy does not match

    Hello,

    A Multi instrument strategy:
    Primary bar: MSFT Daily

    Add("AAPL",PeriodType.Day, 1);

    if (BarsInProgress == 0)
    {
    Closes[0][0]-Closes[1][0]
    }

    Does Closes[1][0] soppose to be the current close price of AAPL? My test shows it is the close price of yesterday's AAPL, how to get today's close of AAPL? Thank you.

    #2
    stephen,

    It will give you the latest that is processed. When you are in BarsInProgress == 0 this may not necessarily be the latest at that moment in time.

    For instance, this is the sequence of events.
    1. BIP0 - 6/15/2009 MSFT
    2. BIP1 - 6/15/2009 AAPL
    3. BIP0 - 6/16/2009 MSFT
    4. BIP1 - 6/16/2009 AAPL

    When you are on #3 and you check Closes[1][0], the most recent information for AAPL is not 6/16 but rather 6/15. If you want the most recent information you should wait till the end of BIP1 to do it.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hello Josh,
      Thank you very much, I understand the problem. But I don't know how to wait until BIP1 ends. I am trying to plot the result.

      if (BarsInProgress == 0)
      {
      double priceRatio= Close[0]/Closes[1][0];
      StrategyPlot(0).Value.Set(priceRatio);
      }
      This work, but the price of secondary instrument is previous days's data.

      if (BarsInProgress == 1)
      {
      double priceRatio= Closes[0][0]/Close[0];
      StrategyPlot(0).Value.Set(priceRatio);
      }
      This does not work.

      Comment


        #4
        You can wait for BIP1 just by using if (BarsInProgress == 1). That should do it for you. What do you see when you use the code you are using?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,
          if (BarsInProgress == 1)
          {
          double priceRatio= Closes[0][0]/Close[0];
          StrategyPlot(0).Value.Set(priceRatio);
          }

          This does not work at all, nothing show up.

          I tried this:
          if (BarsInProgress == 0)
          {
          double priceRatio= Close[1]/Closes[1][1];
          StrategyPlot(0).Value.Set(priceRatio);
          }

          Based on your sequence, if I run it on #5, Close[1] should refer to #3 and Closes[1][1] should refer to #4. But it looks like Closes[1] refer to #2. Any idea?

          1.BIP0-6/14/2009 MSFT
          2.BIP1-6/14/2009 AAPL
          3. BIP0 - 6/15/2009 MSFT
          4. BIP1 - 6/15/2009 AAPL
          5. BIP0 - 6/16/2009 MSFT
          6. BIP1 - 6/16/2009 AAPL

          Comment


            #6
            stephen_mcse,

            No no. Closes[1][1] refers to #2 when you are on step #5 because step #6 has not happened yet. Closes[1][0] refers to step #4.

            If you see nothing charted, please check your Control Center logs for errors.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh,
              I tried this:
              protected override void OnBarUpdate()
              {
              if (BarsInProgress == 1)
              {
              priceRatio= Closes[0][0]/Closes[1][0];
              }
              StrategyPlot(0).Value.Set(priceRatio); // line A
              }

              plotted value of both primary and secondary instruments are data of one bar ago.
              Is this because line A get called before BIP1? If I put line A inside BIP1, nothing showup. The log does not show any error message. Is there a way to plot correctly? Thank you.

              Comment


                #8
                stephen_mcse,

                I am unsure what you are seeing. Please instead of trying to use StrategyPlot which comes with many limitations you just use Print() to check the timestamp of the bar you are accessing. Then you will know which values you are using in the calculations and then we can proceed from there.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                646 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                367 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                107 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                569 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                573 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X