Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Indicators in Multi-Time Frame Strategies

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

    Plotting Indicators in Multi-Time Frame Strategies

    I am launching a strategy on a 1 min chart, and have the following code in initialize():

    Code:
    Add(SMA(10);
    Add(SMA(20);
    Add(PeriodType.Minute, 5);
    I expected the two SMA indicators to begin plotting on the 1 min chart, but they do not. Will they not plot if you are running strategies with an additional bars object?

    kc

    #2
    Hi KC,

    These add statements work differently.
    Add(SMA(10);
    Add(SMA(20);

    These add the indicators for visualization only, and is always based on the primary series unless the actual indicator (SMA in your example) is coded for multiple series.

    Add(PeriodType.Minute, 5);

    This adds a 5 minute series to the script, but you would need to work the series into your code to have any use from it. There is a sample multiTimeFrame strategy built into all NinjaScript installations through Tools > Edit NinjaScript > Strategy menu. Documentation for this is available here:


    To set a plot based on the first added series, you would use something like:
    Value.Set(SMA(Closes[1], 14)[0]);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan. I understand that the first add calls are for visualization only, and that the other add call is for adding another time frame. The issue is that the SMA indicators are not showing up on the chart (i.e. no visualization) as expected on the primary bars object (i.e. 1 min time frame chart that the strategy is loaded on). I'm not trying to plot anything related to the secondary bars object.

      I am able to get them to show up on a basic strategy where I've simplified the code, so it is isolated to just one strategy...nothing in the logs...I'll have to keep troubleshooting to see if I can isolate where the issue is occuring...

      Comment


        #4
        I see, thanks for the reply. Would normally expect to see something in the logs if it doesn't display the indicators. If you have a simple script where this can be seen I'm happy to give it a run here to see if I'm able to spot it.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ok, the issue seems to be with ForceMaximumBarsLookBack256 = true. There are plenty of bars on the chart to draw the indicators. Testing this on ES 1-Min time frame with ESignal data feed. If you copy the following into initialize, it does not plot the indicators. Then uncomment out the top block of code and comment out the bottom and it does plot the indicators

          Code:
          [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// This code plots the indicators[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// Add(SMA(10));[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// Add(SMA(20));[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// SMA(10).Plots[0].Pen.Color = Color.Red;[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// SMA(20).Plots[0].Pen.Color = Color.Blue;[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// Add(PeriodType.Minute, 5);[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// //ForceMaximumBarsLookBack256 = true;[/COLOR][/FONT][/SIZE]
          [SIZE=2][FONT=Courier New][COLOR=#008000]// CalculateOnBarClose = true;[/COLOR][/FONT][/SIZE]
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]
          [/SIZE][/FONT]
          [FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// This code does not[/COLOR][/SIZE][/FONT]
          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]Add(SMA([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Add(SMA([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]));[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]SMA([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).Plots[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Pen.Color = Color.Red;[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]SMA([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]20[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).Plots[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].Pen.Color = Color.Blue;[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]Add(PeriodType.Minute, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]ForceMaximumBarsLookBack256 = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
          [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
          [/SIZE][/FONT]

          Comment


            #6
            Great, thanks for identifying this. I've confirmed on my side and reported to development. I will update this thread with any new information.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Development looked at this and this is expected with this property. This property is designed to save performance, so added indicators will not display as a result.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Ryan,

                I am a little confused with the response above. I am having the same issues are the original poster where I have a strategy that adds a visual indicator in the Initialize method in addition to a second bar series (different timeframe). The indicator only shows when I a comment out the second timeseries.

                <code>
                Add(SMA(10));
                Add(PeriodType.Minute, 1);
                </code>

                I am running on a 5 minute primary bar timeframe

                Comment


                  #9
                  Hi dnoff,

                  When it doesn't plot -- are there any error messages available in the log tab of the control center?

                  Are you having general issues with multiseries indicators or something specific to the ForceMaximumBarsLookBack property brought up by the original poster here?
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    I'm having a similar issue... and per your recommendation, when I add "Value.Set(SMA(Closes[1], 14)[0]);" into my code, I get the "The name 'Value' does not exist in the curr..."

                    All I want to do is plot the MAs I'm using for trade generation.

                    Comment


                      #11
                      Hello,

                      Thanks for the forum post.

                      You most likely are missing the parts of the below sample that create Value for you to be able to set it, this needs to be added since you are doing this inside a strategy. If you are not doing this inside of a strategy please let me know and ignore the following. This is only if you are running in a strategy and not an indicator.

                      In summary what you are doing is adding a plot from inside the strategy the values of the secondary series SMA.

                      You need to insure you have all the code in the following sample:

                      When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


                      Including:

                      Add(StrategyPlot(0));
                      StrategyPlot(0).PanelUI = 1;


                      StrategyPlot(0).Value.Set(SMA(Closes[1], 14)[0]);

                      And also importing in the indicator in that sample into your indicator list called StrategyPlot for the strategy plot to work correctly.

                      Let me know if any questions.
                      BrettNinjaTrader Product Management

                      Comment


                        #12
                        Is there any reason that the SampleStrategyPlot wouldn't plot when run as a backtest? I can't get it to plot the two StrategyPlots? All I get back is a plot of the candles.

                        Thanks in advance,
                        darmbk.

                        Comment


                          #13
                          Hello darmbk,

                          This is because this technique has limited functionality. It will NOT work for charts in the Strategy Analyzer during backtesting, but it will work on real-time charts.

                          This is apart of the notes at the top of the reference page.

                          Let us know if we can be of any further assistance
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            So I suppose my next question is obvious enough... how do I accomplish this in Strategy Analyzer when backtesting? An example might be, plot a 14 period daily SMA on a 1 minute chart.

                            Comment


                              #15
                              Hello darmbk,

                              If you are placing your strategy on a 1 Minute chart (meaning that 1 Minute is your Primary Series) I would normally expect this to plot.

                              Can you answer the same questions on Post #9 if you are not seeing them plot?
                              JCNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

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