Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-time frame help - Indicators on different time frames not lining up

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

    Multi-time frame help - Indicators on different time frames not lining up

    Hello,

    I'm experimenting with multi-time frame in ninjascript and can't seem to figure out this problem. I've got a set of indictors (hand full of EMA and a MACD) on a minute time frame and another set of indicators (a Bollinger and MACD) on a tick time frame. But as you can see in the attachment picture, they're not lining up time wise. Looks like it's plotting based on the bar number. Is there a way to sync this up time wise? I've attached another screenshoot of what I'm expecting, created manual through the chart properties.

    I've gone through Tips for multiseries scripts is available here to get to where I'm at now.

    Thank you,
    Scott

    #2
    Hello Scott,

    You could have one indicator do the plotting and call the other indicators.

    Below is a link to an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the help! I was able to get the EMA indicators working, but I'm having difficulty implementing this for the MACD. The values don't make sense to even guess to what is going wrong.
      Code:
      #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.DrawingTools;
      #endregion
      
      //This namespace holds Indicators in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public class DumbBotHigherTimeFrameMACDIndicator : Indicator
      {
      private Series<double> fastEma, slowEma;
      private double constant1, constant2, constant3, constant4, constant5, constant6;
      
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMACD;
      Name = "DumbBotHigherTimeFrameMACDIndicator";
      Fast = 12;
      IsSuspendedWhileInactive = true;
      Slow = 26;
      Smooth = 9;
      
      AddPlot(Brushes.DarkCyan, NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMACD);
      AddPlot(Brushes.Crimson, NinjaTrader.Custom.Resource.NinjaScriptIndicatorAv g);
      AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.NinjaScriptIndicatorDi ff);
      AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
      }
      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute, 1);
      
      constant1 = 2.0 / (1 + Fast);
      constant2 = (1 - (2.0 / (1 + Fast)));
      constant3 = 2.0 / (1 + Slow);
      constant4 = (1 - (2.0 / (1 + Slow)));
      constant5 = 2.0 / (1 + Smooth);
      constant6 = (1 - (2.0 / (1 + Smooth)));
      }
      else if (State == State.DataLoaded)
      {
      fastEma = new Series<double>(this);
      slowEma = new Series<double>(this);
      }
      }
      
      protected override void OnBarUpdate()
      {
      if (BarsInProgress == 0 && CurrentBars[0] > 0)
      {
      //Values[0][0] = smaA[0];
      
      // extend the larger time frame for each primary bar so there are consecutive bars set so we can see it on the chart
      if (!Values[0].IsValidDataPoint(0))
      {
      Values[0][0] = Values[0][1];
      Avg[0] = Avg[1];
      Diff[0] = Diff[1];
      }
      }
      
      if (BarsInProgress == 1 && CurrentBars[1] > 0)
      {
      //Values[1][0] = smaB[0];
      //Print(Values[1][0]);
      double input0 = Input[0];
      
      if (CurrentBar == 0)
      {
      fastEma[0] = input0;
      slowEma[0] = input0;
      Values[0][0] = 0;
      Avg[0] = 0;
      Diff[0] = 0;
      }
      else
      {
      double fastEma0 = constant1 * input0 + constant2 * fastEma[1];
      double slowEma0 = constant3 * input0 + constant4 * slowEma[1];
      double macd = fastEma0 - slowEma0;
      double macdAvg = constant5 * macd + constant6 * Avg[1];
      
      fastEma[0] = fastEma0;
      slowEma[0] = slowEma0;
      Values[0][0] = macd;
      Avg[0] = macdAvg;
      Diff[0] = macd - macdAvg;
      }
      }
      }
      
      #region Properties
      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Avg
      {
      get { return Values[1]; }
      }
      
      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Default
      {
      get { return Values[0]; }
      }
      
      [Browsable(false)]
      [XmlIgnore]
      public Series<double> Diff
      {
      get { return Values[2]; }
      }
      
      [Range(1, int.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptParameters", Order = 0)]
      public int Fast
      { get; set; }
      
      [Range(1, int.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptParameters", Order = 1)]
      public int Slow
      { get; set; }
      
      [Range(1, int.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "Smooth", GroupName = "NinjaScriptParameters", Order = 2)]
      public int Smooth
      { get; set; }
      #endregion
      }
      }
      
      #region NinjaScript generated code. Neither change nor remove.
      
      namespace NinjaTrader.NinjaScript.Indicators
      {
      public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
      {
      private DumbBotHigherTimeFrameMACDIndicator[] cacheDumbBotHigherTimeFrameMACDIndicator;
      public DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(int fast, int slow, int smooth)
      {
      return DumbBotHigherTimeFrameMACDIndicator(Input, fast, slow, smooth);
      }
      
      public DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(ISeries<double > input, int fast, int slow, int smooth)
      {
      if (cacheDumbBotHigherTimeFrameMACDIndicator != null)
      for (int idx = 0; idx < cacheDumbBotHigherTimeFrameMACDIndicator.Length; idx++)
      if (cacheDumbBotHigherTimeFrameMACDIndicator[idx] != null && cacheDumbBotHigherTimeFrameMACDIndicator[idx].Fast == fast && cacheDumbBotHigherTimeFrameMACDIndicator[idx].Slow == slow && cacheDumbBotHigherTimeFrameMACDIndicator[idx].Smooth == smooth && cacheDumbBotHigherTimeFrameMACDIndicator[idx].EqualsInput(input))
      return cacheDumbBotHigherTimeFrameMACDIndicator[idx];
      return CacheIndicator<DumbBotHigherTimeFrameMACDIndicator >(new DumbBotHigherTimeFrameMACDIndicator(){ Fast = fast, Slow = slow, Smooth = smooth }, input, ref cacheDumbBotHigherTimeFrameMACDIndicator);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
      {
      public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
      {
      public Indicators.DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(int fast, int slow, int smooth)
      {
      return indicator.DumbBotHigherTimeFrameMACDIndicator(Inpu t, fast, slow, smooth);
      }
      
      public Indicators.DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(ISeries<double > input , int fast, int slow, int smooth)
      {
      return indicator.DumbBotHigherTimeFrameMACDIndicator(inpu t, fast, slow, smooth);
      }
      }
      }
      
      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
      {
      public Indicators.DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(int fast, int slow, int smooth)
      {
      return indicator.DumbBotHigherTimeFrameMACDIndicator(Inpu t, fast, slow, smooth);
      }
      
      public Indicators.DumbBotHigherTimeFrameMACDIndicator DumbBotHigherTimeFrameMACDIndicator(ISeries<double > input , int fast, int slow, int smooth)
      {
      return indicator.DumbBotHigherTimeFrameMACDIndicator(inpu t, fast, slow, smooth);
      }
      }
      }
      
      #endregion
      Thank you,
      Scott
      Attached Files

      Comment


        #4
        Hi, thanks for the follow up. Your indicators are both initialized on the primary series. Please have a look at the examples that Chelsea posted, these show how to initialize your indicator on the primary and secondary series. e.g. from HigherTimeFrameIndicatorPlotExample:

        Code:
        else if (State == State.DataLoaded)
                    {
                        smaA    = EMA(14);
                        smaB    = EMA(Closes[1], 14);
                    }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        132 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X