Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Plotting Indicators in Multi-Time Frame Strategies

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

    #16
    Hi JC,

    I don't see any error messages and I'm not making any edits to ForceMaximumBarsLookBack. If I plot the daily time frame indicator in the window below the price window then that window comes back empty.

    Thanks,
    darmbk.

    Comment


      #17
      Hello darmbk,

      NinjaTrader is only going to Plot an Indicator based on the Primary Series. What time frame are you setting your Strategy to?

      Also, could you post a screenshot?
      JCNinjaTrader Customer Service

      Comment


        #18
        Hi JC,

        Thanks for your help. I attach a plot and a portion of the code. My primary time frame in this case is 1min and I am adding the daily time frame. As you can see the panels below the price panel remain blank. I have tried removing a secondary time frame and using StrategyPlot for the primary time frame and I get the same blank result. NOte that the code here is looking at the primary data, I would otherwise use Closes[1] instead of Close.

        Thanks,
        darmbk.


        Code:
                protected override void Initialize()
                {
        			// Process entries up to a max including all entry types
        			EntryHandling = EntryHandling.AllEntries; 
        			// Max allowable entries in total
        			EntriesPerDirection = 1; 
        			
        			// Slippage in ticks for every order that trades, both entry and exit
        			Slippage = 1; 
        			// Commission specified either per exchange or product in Historical Data Manager
        			IncludeCommission = true; 
        			
        			// Add secondary timeframes
        			//     BarsArray[0] is defined by the UI for the strategy, e.g. 1min in backtester
        			// BarsArray[1] set to 'days', 
        			Add(PeriodType.Day, 1);
        			
        			// Add primary timeframe indicators to chart
        			// Guppy
        			Add(EMA(10));
        			EMA(10).Plots[0].Pen.Color = Color.Red;
        			Add(EMA(25));
        			EMA(25).Plots[0].Pen.Color = Color.DarkOrange;
        			Add(EMA(50));
        			EMA(50).Plots[0].Pen.Color = Color.Gold;
        			Add(EMA(75));
        			EMA(75).Plots[0].Pen.Color = Color.Green;
        			Add(EMA(100));
        			EMA(100).Plots[0].Pen.Color = Color.Blue;
        			Add(EMA(150));
        			EMA(150).Plots[0].Pen.Color = Color.Violet;
        			// Volume
        			//Add(VOL());
        			
        			// Add placeholders for secondary timeframe indicators
        			// Placeholder plot objects
        			Add(StrategyPlot(0));
        			Add(StrategyPlot(1));
        			// Set the color for the indicator plots
        			StrategyPlot(0).Plots[0].Pen.Color = Color.Blue;
        			StrategyPlot(1).Plots[0].Pen.Color = Color.YellowGreen;
        			// Set the panel which the plots will be placed on
        			//     1 = price panel, 2 = panel under the price panel, etc.
        			StrategyPlot(0).PanelUI = 2;
        			StrategyPlot(1).PanelUI = 3;
        			
        			// Calculations using close prices
        			// Else on each tick, this property should be the last statement in Initialize()
        			CalculateOnBarClose = true; 
                }
        
                /// <summary>
                /// Called on each bar update event (/incoming tick)
                /// </summary>
                protected override void OnBarUpdate() // OnBarUpdate() is called on bar 20, this can be edited
                {
        			// Check if main time frame is at the minimum bar required to start
        			// BarsRequired defaulted to 20
        			if(CurrentBars[0] < BarsRequired) 
        					// Indicators require BarsRequired bars so we do nothing until we reach that bar
        					return; 
        			
        			#region Plotting
        			StrategyPlot(0).Value.Set(SMA(Close, 20)[0]);
        			StrategyPlot(1).Value.Set(SMA(Close, 50)[0]);
        				#endregion
        			
        			if(BarsInProgress == 0)
        			{ //Rest of OnBarUpdate code here
        Attached Files
        Last edited by darmbk; 03-04-2014, 06:57 AM.

        Comment


          #19
          Hello darmbk,

          The StrategyPlot() method will NOT work for charts in the Strategy Analyzer window during Backtests so I would expect them to be blank.

          If you are wanting to view the StrategyPlot() method then you may want to apply your Strategy to a Chart by going to File -> New -> Chart then add and enable your Strategy.
          JCNinjaTrader Customer Service

          Comment


            #20
            Hi JC,

            Thanks for getting back to me. Yes I understand that from post #13. My post #14 was asking how might I otherwise accomplish this in Strategy Analyser. That is...

            [1] How can I plot indicators based on time frames other than the primary time frame in Strategy Analyser?

            [2] I have read several posts that mention this issue. In the post linked to below, the solution was to rebuild standard indicators so that they operate as if they are referring to other timeframes. For instance, looking at a 13 period EMA from a 3-min time frame is plotted on a 1min chart by using a 39 period EMA from a 1min time frame. Is this the simplest solution to my problem? I say simple but this may run into difficulties depending on the indicator.



            [3] As StrategyPlot does not work in Strategy Analyser then how do users backtest strategies that have been coded to use StrategyPlot in live trading? Do they have to manage two different sets of code, one to use in live and one workaround copy that can operate in Strategy Analyzer like the example mentioned in [2]?

            Many thanks,
            darmbk.

            Comment


              #21
              Hello darmbk,

              1. The only ways that I can think of to plot you an indicators values from a different Data Series would be to either use a DrawObject method or to create a custom indicator from the original one and add your time frame logic to that.

              2. That would be the simplest method that I can think of yes. Just note that it is "near-identical" as Harry has stated in post #12 as the moving averages use the previous value which makes them slightly different.

              3. Plotting a Strategy on a Chart will do exactly what a Backtest will do and it will allow you to see the StrategyPlot(). You may just want to increase the amount of days loading back on your chart when you are viewing the results.
              JCNinjaTrader Customer Service

              Comment


                #22
                Hi,

                [1] I have found that using DrawObject for each bar was a neat solution but there appears to be a performance reduction as a bi-product. I have added a test parameter that simply prints a dot under each bar's low and as a result the backtest takes approximately twice as long. Navigating around the resultant chart I also notice some lag.

                [2] This seems to be the best solution then.

                Comment


                  #23
                  Hello Darmbk,

                  DrawObjects take up a portion of memory for use on the chart.The you add such as every bar can cause a performance issue moving back and forth.

                  As JC suggested, you may want to create a custom indicator that plots all this lines and values and then call that indicator from the Strategy so that when you back test it will plot the lines of the indicator.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #24
                    In closing, I found this post helpful for plotting higher time frame data in the way you suggest:



                    Cheers,
                    darmbk.

                    Comment


                      #25
                      Originally posted by NinjaTrader_JC View Post
                      Hello darmbk,

                      1. The only ways that I can think of to plot you an indicators values from a different Data Series would be to either use a DrawObject method or to create a custom indicator from the original one and add your time frame logic to that.

                      2. That would be the simplest method that I can think of yes. Just note that it is "near-identical" as Harry has stated in post #12 as the moving averages use the previous value which makes them slightly different.

                      3. Plotting a Strategy on a Chart will do exactly what a Backtest will do and it will allow you to see the StrategyPlot(). You may just want to increase the amount of days loading back on your chart when you are viewing the results.
                      Hi JC,

                      I am successfully using option 2 that you suggested. However another idea occurred to me which I tried and found it does not work and I was hoping you could explain why.

                      My alternative suggestion came to me because I was hoping to get rid of the steps of values that are plotted because the higher time frame value does not change for a repeating series of lower time frame bars over which they are plotted.

                      I added a Boolean that was set to true upon each higher time frame bar in BarsInProgress == 1. This Boolean would then permit the lower time frame to access the Plot dataseries in BarInProgress == 0 underneath and then reset the Boolean to false. In this way, I thought I was getting the primary time series to do the plotting but that it would skip the unnecessary plot points when the higher time frame holds the same value. However, nothing plotted.

                      I am happy using option 2 above but I am curious as to why this idea didn't work? Is it that every primary dataseries bar requires a value in order to plot correctly so skipping them with the Boolean breaks the link of values to plot?

                      Thanks,
                      darmbk.

                      Comment


                        #26
                        Darmbk,

                        Can you post the code you are using in the OnBarUpdate() for the boolean switch?
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #27
                          Hi JC,

                          I include the snippets involved here. My interpretation of what is going wrong is that I require a value to plot for each bar as the dataseries is the same length as the timeseries. However I am only adding values to the dataseries when my Boolean flag is true and this is would only be after every 5 bars in the example where I am plotting a 5min indicator on a 1min chart. Here BarsArray[1] refers to the 5min time frame. As a result, I see no way to plot a higher time frame indicator line on a lower frame chart without the plot having steps of values, which is fine.


                          Code:
                          if(BarsInProgress ==1) plotHigherFrameMA = true;
                          
                          if(BarsInProgress ==0)
                          {
                               if(plotHigherFrameMA == true) 
                               {
                                    Plot1.Set(SMA(BarsArray[1], MAPeriod)[0]);
                                    plotHigherFrameMA = false;
                               }
                          }

                          Comment


                            #28
                            Hello darmbk,

                            Thank you for your response.

                            We would need to change the PlotStyle to Dot in this case as the Line would not plot correctly in this case. The following code will work:
                            Code:
                                    protected override void Initialize()
                                    {
                            			Add(new Plot(Color.Blue, PlotStyle.Dot, "Plot"));
                                      	Add(PeriodType.Minute, 60);
                                    }
                            
                                    /// <summary>
                                    /// Called on each bar update event (incoming tick)
                                    /// </summary>
                                    protected override void OnBarUpdate()
                                    {
                            			if(CurrentBars[0] <= 14 || CurrentBars[1] <= 14)
                            				return;
                            			if(BarsInProgress == 1) test = true;
                            			if(BarsInProgress == 0 && test)
                            			{
                            				Value.Set(SMA(BarsArray[1], 14)[0]);
                            				test = false;
                            			}
                                    }

                            Comment

                            Latest Posts

                            Collapse

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