Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Timeframe OnEachTick

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

    Multi-Timeframe OnEachTick

    I'm struggling with a Multi-timeframe indicator. I want it to work the same as the Ninjatrader CurrentDayOHLC indicator, but for other periods. 30min, 60min, 240min.

    I've added a secondary series for the period I want to plot the high and low of. And I have OnEachTick set. I'm assigning Highs[1][0] and Lows[1][0] to the plots expecting the in-progress bars high and low to be plotted, but it doesn't plot the high and low of the in-progress bar, it plots the closed bar.

    What am I doing wrong here?
    Attached Files

    #2
    Can anyone help with this?

    Comment


      #3
      Hello reach4thelasers,

      We have received your inquiry and will follow up when we have a moment to review your code.

      Thank you for your patience.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        I looked at it for a little, I did have to fix the source by moving the enum outside of the class. The code does work going forward. I was getting updated before 30 minutes from what I saw on 3 minute chart.

        I opened up the OHLC indicator which was very different.

        Not sure exactly what you are looking for requirements wise.

        Code:
        #region Using declarations
        #endregion
        		public enum BreakoutTimeframeEnum
        		{
        			Day, Hour, FourHour, ThirtyMinute
        		}
        //This namespace holds Indicators in this folder and is required. Do not change it. 
        namespace NinjaTrader.NinjaScript.Indicators.Volatility
        {

        Comment


          #5
          Hey Slege!

          Thanks for looking for me! Yeah I looked at the CurrentDayOLHC it basically keeps track highest high and lowest low for the day based on the Input series, and resets each day.

          I could do it this way, but thought it would be easier to do with Multi-timeframes.

          Yes it does update, but the values of the plot are showing the prior period rather than the current period. The bars breakout above the plot rather than pushing the ceiling higher.

          The screenshot I attached shows what CurrentDayOHL does compared to my version. Any ideas what I'm doing wrong?
          Attached Files

          Comment


            #6
            By the way what was the issue with the nested enum?

            Comment


              #7
              Originally posted by reach4thelasers View Post
              By the way what was the issue with the nested enum?
              Compiler error. undefined down below at the bottom.

              Comment


                #8
                Hello Sledge,

                To get around that error I had to amend the code with,
                Code:
                 NinjaTrader.NinjaScript.Indicators.Volatility.PeriodHigh
                in-front of,
                Code:
                BreakoutTimeframeEnum
                I have attached a file which compiles and am able to replicate the issue however have not found a way to have the plot shifted 1 secondary series bar back just yet.
                Attached Files
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Hello reach4thelasers,

                  I have put together a sample which contains two ways of resolving the issue. 1 solution is commented out the other is not.

                  Pleas let us know if you need further assistance.
                  Attached Files
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Alan - that works great!!

                    Comment


                      #11
                      Hello,

                      I've been struggling with a very similar problem: trying to access a secondary time series in a strategy, and it keeps plotting the closed bar rather than the in-progress bar. I've tried implementing the fix here, but it now just makes the entire strategy "stall" (as in do nothing in the Strategy Analyzer) although the script does compile.

                      Could you please tell me what I have done incorrectly? I would truly appreciate this help!

                      Also, I've attached a photo to illustrate the issue which I'm trying to address.

                      Thank you very much!

                      #region Using declarations
                      using System;
                      using System.Collections.Generic;
                      using System.ComponentModel;
                      using System.ComponentModel.DataAnnotations;
                      using System.Linq;
                      using System.Text;
                      using System.Threading.Tasks;
                      using System.Windows;
                      using System.Windows.Input;
                      using System.Windows.Media;
                      using System.Xml.Serialization;
                      using NinjaTrader.Cbi;
                      using NinjaTrader.Gui;
                      using NinjaTrader.Gui.Chart;
                      using NinjaTrader.Gui.SuperDom;
                      using NinjaTrader.Gui.Tools;
                      using NinjaTrader.Data;
                      using NinjaTrader.NinjaScript;
                      using NinjaTrader.Core.FloatingPoint;
                      using NinjaTrader.NinjaScript.Indicators;
                      using NinjaTrader.NinjaScript.DrawingTools;
                      #endregion

                      //This namespace holds Strategies in this folder and is required. Do not change it.
                      namespace NinjaTrader.NinjaScript.Strategies
                      {
                      public class A1TEST3 : Strategy
                      {

                      private Series<double> test;
                      int cacheHigh;
                      int cacheLow;
                      private Series<double> barHigh;
                      private Series<double> barLow;

                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = @"Enter the description for your new custom Strategy here.";
                      Name = "A1TEST3";
                      Calculate = Calculate.OnEachTick;
                      EntriesPerDirection = 1;
                      EntryHandling = EntryHandling.AllEntries;
                      IsExitOnSessionCloseStrategy = true;
                      ExitOnSessionCloseSeconds = 30;
                      IsFillLimitOnTouch = false;
                      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                      OrderFillResolution = OrderFillResolution.Standard;
                      Slippage = 0;
                      StartBehavior = StartBehavior.AdoptAccountPosition;
                      TimeInForce = TimeInForce.Gtc;
                      TraceOrders = false;
                      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
                      StopTargetHandling = StopTargetHandling.PerEntryExecution;
                      BarsRequiredToTrade = 20;
                      AddPlot(new Stroke(Brushes.Blue), PlotStyle.Line, "StrategyPlot");
                      // Disable this property for performance gains in Strategy Analyzer optimizations
                      // See the Help Guide for additional information
                      IsInstantiatedOnEachOptimizationIteration = true;


                      }
                      else if (State == State.Configure)
                      {
                      AddDataSeries(Data.BarsPeriodType.Minute, 5);

                      }
                      else if (State == State.DataLoaded)
                      {
                      test = new Series<double>(this, MaximumBarsLookBack.Infinite);
                      int cacheHigh = 0;
                      int cacheLow = 0;
                      barHigh = new Series<double>(this, MaximumBarsLookBack.Infinite);
                      barLow = new Series<double>(this, MaximumBarsLookBack.Infinite);
                      }


                      }
                      protected override void OnBarUpdate()
                      {
                      if (BarsInProgress != 0)
                      return;

                      if (CurrentBars[0] < 5
                      || CurrentBars[1] < 5)
                      return;

                      if(CurrentBars[0]<10 || CurrentBars[1]<10) return;

                      int cacheHigh = BarsArray[1].GetBar(Times[0][0]);
                      int cacheLow = BarsArray[1].GetBar(Times[0][0]);

                      double barHigh = BarsArray[1].GetHigh(cacheHigh);
                      double barLow = BarsArray[1].GetLow(cacheLow);

                      {
                      Values[0][0] = barHigh;
                      Values[1][0] = barLow;
                      }

                      StrategyPlot[0] = Values[0][0];
                      Plots[0].Width = 4;

                      // Set 1
                      if (Close[0] > Close[1])
                      {
                      EnterLongLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (-2 * TickSize)) , "");
                      }

                      // Set 2
                      if (Close[0] < Close[1])
                      {
                      ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
                      }

                      // Set 3

                      }

                      #region Properties

                      public Series<double> StrategyPlot
                      {
                      get { return Values[0]; }
                      }
                      #endregion

                      }
                      }

                      Comment


                        #12
                        Hi catinabag, thanks for the follow-up.

                        The 5 minute series time stamps will only go in 5-minute increments. So a tick update at 1:43:50:000 PM on the 5-minute series will have a timestamp of 1:45. If you need a more granular timestamp you would need to reference the 1 minute series, or even a 1 tick series to get milliseconds.

                        Please let me know if this does not resolve your inquiry.

                        Comment


                          #13
                          Hello catinabag,

                          Thanks for your post.

                          You have a lot of thing going on in your code, lets simplify and get one thing working first.

                          As a suggestion work on just the plot line first and try doing it this way:

                          protected override void OnBarUpdate()
                          {
                          if(CurrentBars[0]<10 || CurrentBars[1]<10) return;

                          if (BarsInProgress != 0)
                          return;

                          cacheHigh = BarsArray[1].GetBar(Times[0][0]);

                          StrategyPlot[0] = BarsArray[1].GetHigh(cacheHigh);
                          }


                          NOTE: 1) You have already defined cacheHigh at the class level so no need to use int cacheHigh in the OnBarUpdate().
                          2) Set this in State.DataLoaded: Plots[0].Width = 4;

                          Comment


                            #14
                            Thank you so much for your clear and concise script! I get it now!

                            [I'd just come up with a similar solution after scanning through GitHub via Google. Yours is much cleaner and clearer for me.]

                            I truly appreciate your and Chris L's help! Thanks a bunch, and have a great day!

                            Comment


                              #15
                              Hello catinabag,

                              Thanks for your reply.

                              Glad we were able to help.

                              For future reference, please do not add into another forum thread when you have already created another thread on the same subject as this can be confusing and duplicating of time/effort. We appreciate your understanding and help to keep the forums organized going forward.

                              reference: https://ninjatrader.com/support/foru...torical-candle

                              Comment

                              Latest Posts

                              Collapse

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