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

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 f.saeidi, Today, 05:56 AM
          1 response
          3 views
          0 likes
          Last Post Jltarrau  
          Started by Jltarrau, Today, 05:57 AM
          0 responses
          4 views
          0 likes
          Last Post Jltarrau  
          Started by Stanfillirenfro, Yesterday, 09:19 AM
          7 responses
          51 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by TraderCro, 04-12-2024, 11:36 AM
          4 responses
          70 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Mindset, Yesterday, 02:04 AM
          1 response
          15 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X