Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Different results from Strategy Analyzer for selected 2 different Data Series

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

    Different results from Strategy Analyzer for selected 2 different Data Series

    Hi,

    I made a strategy that works on 2 different Data Series:
    1. 1 minute
    2. 2500 volume
    The strategy is calculated based on 'on bar close'.
    Click image for larger version

Name:	1_Strategy.png
Views:	128
Size:	160.9 KB
ID:	1229234
    Let's simplify and say, that if the candle is green on Min1 and green on Vol2500 then I go long.


    1. Then I run the Strategy Analyzer and I got different results for Min1 and Vol2500 - why is that? I expected exactly the same results as the strategy work on both series at the same time.
    Click image for larger version

Name:	2_Analyzer.png
Views:	85
Size:	210.8 KB
ID:	1229235

    2. If I have 'On bar close' strategy - would it mean that the strategy will execute on both new bar on 1min and on 2500vol?
    3. Can I analyze the results of the strategy on the chart while having both series open? To see what signals did I get on 1min and 2500vol? Now in the Strategy Analyzer I can see only one chart.

    Thanks for support!

    #2
    Hello iskier,

    The strategy builder only executes logic for the primary series, by changing the primary series you should see different executions because your conditions will evaluate true on different bars and there will be different bar data used for fills. The secondary series are only being used for prices during the primary bar update events.

    Scripts do work like you are thinking but you would need to do that In manual coding. With a manually coded script you could have OnBarUpdate called for the secondary series and you could also choose which series the conditions that you make are being executed on.


    On bar close means the way the script processes data. In historical you can only use On bar close because historical data is not granular, its just OHLC data points. In realtime you can use OnEachTick or OnPriceChange which means each tick or price change calls OnBarUpdate in your script to check your conditions.



    Comment


      #3
      Thanks Jesse! I appreciate your support and prompt reply.
      1. Could you please guide me to some examples of the code to handle multiple series in manual coding?
      2. If I do these changes, I understand that I could backtest this new strategy to check if the results are fine, right?
      3. How can I debug it on chart? What would you recommend?

      Comment


        #4
        Hello iskier,

        1. You can see the following links for some information about multiple series and separating logic.




        2. Yes that would allow any primary series to be used and your conditions could be executed based on the secondary series events. There is a sample of using a secondary series for backtesting purposes here: https://ninjatrader.com/support/help...ipt_strate.htm

        3. You can apply strategies to charts to run backtests or to run in realtime. If you want to view its performance you can right click in the chart and select its performance report.

        Comment


          #5
          Hi Jesse,
          I changed my code as you pointed me.
          MyPrimary bar is 1s, the secondary is volume and 1min. These are all for the same instrument.

          As I tried to check the NinjaScript Output, I see that the code goes only into the condition if (BarsInProgress == 0) and never into other two conditions: if (BarsInProgress == 1) nor if (BarsInProgress == 2).

          Could you please let me know what I am doing wrong?

          Code:
          protected override void OnStateChange()
                  {
                      if (State == State.SetDefaults)
                      {
                          ...
                      }
                      else if (State == State.Configure)
                      {
                          AddDataSeries(Data.BarsPeriodType.Volume, 2500);
                          AddDataSeries(Data.BarsPeriodType.Minute, 1);
                      }
                      else if (State == State.DataLoaded)
                      {                
                          ...
                      }
                  }​
          
          protected override void OnBarUpdate()
                  {
                      if (BarsInProgress != 0)
                          return;
          
                      if (CurrentBars[0] < 1
                      || CurrentBars[1] < 1
                      || CurrentBars[2] < 1
                      )
                          return;
          
                      // Checks if OnBarUpdate() is called from an update on the primary Bars - 1s
                      if (BarsInProgress == 0)
                      {
                          Print("BarsInProgress0 (1s): " + Time[0] + "; " + CurrentBar);
                      }
          
                      // Checks if OnBarUpdate() is called from an update on VOLUME 2500 Bars
                      if (BarsInProgress == 1)
                      {
          
                          Print("BarsInProgress1 (2500VOL): " + Time[0] + "; " + CurrentBar);
                      }
          
                      // Checks if OnBarUpdate() is called from an update on 1 minute Bars
                      if (BarsInProgress == 2)
                      {
                          Print("BarsInProgress2 (1MIN): " + Time[0] + "; " + CurrentBar);
                      }
                  }​

          Comment


            #6
            Hello iskier,

            Part of the code that the strategy builder generates is why it can't use secondary series, you need to rremove the following line:

            Code:
            if (BarsInProgress != 0)
            return;


            BarsInProgress lets you know which series is calling OnBarUpdate. What that condition is saying is if the series calling OnBarUpdate is not 0 then don't execute the code below the return statement.

            Comment


              #7
              Hi Jesse,
              thanks! topic solved

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              66 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              141 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              46 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X