• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsRequiredToPlot and AddChartIndicator in Strategy

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

    BarsRequiredToPlot and AddChartIndicator in Strategy

    When I add indicator charts to a Strategy via AddChartIndicator, I can't figure out how to make it plot on any bars less than the 20th bar.

    I set BarsRequiredToPlot to smaller values for the strategy and the indicators, but it doesn't change anything.

    Is this a hard limit?

    Try this, for example.

    Modify the built-in SMA by adding the following code in the Configure state.

    Code:
    BarsRequiredToPlot = Period;
    Now, when you add an SMA indicator by itself (no strategy) with a Length=5, to a chart, it will display on bars before the 20th.

    However, now add the built-in SampleMACrossOver strategy to a chart. The SMAs that are added via AddChartIndicator in that strategy do not chart below the 20th bar.

    I've tried setting BarsRequiredToPlot in code to a lesser value for the strategy, but this doesn't make any difference either.

    Thanks,


    #2
    Hello BarzTrading,

    This is likely that you are trying to pass the Period as the value and set it from Configure, do you see this working correctly if you do the following test?
    1. In the strategy State.SetDefaults set its BarsRequiredToPlot = 0.
    2. In the indicator State.SetDefaults set its BarsRequiredToPlot = 0.
    3. Apply the strategy to a chart, is the indicator plotting on bar 0 now?

    Are you also completely removing the strategy between tests and re applying it? Because properties in OnStateChange are being modified, this would be needed to see the change.


    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you, Jesse.

      This got me back on track. I think the greater part of my problem was not consistently removing and replacing the strategy on the chart after making changes.

      After some testing this morning I've noticed one odd thing. Can you confirm it is expected behavior?

      If I do as you instructed above, then I see the fast sma and slow sma both charted from the first bar as expected.

      I then changed the SMA back to what I had in my original post:

      Code:
      else if (State == State.Configure)
      {
          BarsRequiredToPlot = Period;
          priorSum = 0;
          sum = 0;
      }
      If you plot just the SMA indicator on the chart, this works great and the plot displays after Period bars.

      I kept the following in the MA CrossOver Strategy:

      Code:
                  
      if (State == State.SetDefaults)
      {
          Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver;
          Name = "Barz Sample MA CrossOver";
          Fast = 10;
          Slow = 25;
          // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
          // See the Help Guide for additional information
          IsInstantiatedOnEachOptimizationIteration = false;
          BarsRequiredToPlot = 0;
      }
      When I add the strategy to the chart, I still get SMA plots all the way back to the first bar.

      Click image for larger version  Name:	Capture.PNG Views:	1 Size:	24.8 KB ID:	1057815

      So, it appears that the BarsRequiredToPlot=0 setting in the strategy overrides the setting on the indicators.

      Is this normal and expected?




      Comment


        #4
        Hello BarzTrading,

        I believe this is expected however I don't know that this would be specifically documented. In general most properties that your strategy shares with the indicator are passed to the hosted indicator. A good example of this is the Calculate setting, if you use OnEachTick from the host the hosted script will take that value. This is noted in the Calculate help guide page, and also has a note about the host/hosted properties. https://ninjatrader.com/support/help.../calculate.htm



        If you would like further clarification that this is specifically expected, I can put in a question to development to get confirmation on that. I would guess this is expected though.

        I look forward to being of further assistance.
        Last edited by NinjaTrader_Jesse; 05-17-2019, 09:13 AM.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks, Jesse. That all makes sense and gives me the understanding I I was looking for. I don't need any further details at this point.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by RtelTrade, Today, 01:27 PM
          0 responses
          2 views
          0 likes
          Last Post RtelTrade  
          Started by NinjaTrader_Brandon, Today, 01:19 PM
          0 responses
          6 views
          0 likes
          Last Post NinjaTrader_Brandon  
          Started by nedstrader, Today, 01:01 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by tvaughan4, Today, 01:02 PM
          0 responses
          7 views
          0 likes
          Last Post tvaughan4  
          Started by RolloHarper, Today, 12:59 PM
          0 responses
          5 views
          0 likes
          Last Post RolloHarper  
          Working...
          X