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

Multi timeframe issue

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

    Multi timeframe issue

    Hello,

    I have an indicator that shows the simple moving average 8 of the chart data and the simple moving average 8 of daily data. To do so, I import in my code the daily close and display my indicator on (for example) a five minuts chart. However, when I compare the SMA 8 daily on a daily chart and my SMA 8 daily on a 5 minuts chart, I don't have the same result (and can't figure out why). Can anyone help ? Thanks a lot !

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    	public class XXXIndicator : Indicator
    	{
    		
    		double Moyenne1;
    		double Moyenne2;
    		private Series<double> CloseJour; 
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Indicator here.";
    				Name										= "XXXIndicator";
    				Calculate									= Calculate.OnBarClose;
    				IsOverlay									= false;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= true;
    				DrawVerticalGridLines						= true;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    				AddPlot(Brushes.Yellow, "Plot1");
    				AddPlot(Brushes.Yellow, "Plot2");
    				AddPlot(Brushes.Yellow, "Plot3");
    				AddPlot(Brushes.Yellow, "Plot4");
    				CloseJour = new Series<double>(this, MaximumBarsLookBack.Infinite);
    
    			}
    			else if (State == State.Configure)
    			{
    				AddDataSeries(BarsPeriodType.Day, 1);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			
    			if  (CurrentBar<15 || CurrentBars[1]<15 ) 
    				return;
    
    			CloseJour[0] = Closes[1][0];
    				
    			Moyenne1 = SMA(Closes[0], 8)[0];
    			Moyenne2 = SMA(CloseJour, 8)[0];
    			
    			Values[0][0] = Moyenne1;
    			Values[1][0] = Moyenne2;
    			
    		}
    	}
    }
    Last edited by WalBen; 01-20-2017, 04:42 AM.

    #2
    After further tests, it appears that my SMA 8 daily (with daily data imported in the code) is the same as the SMA 8 if I plotted my indicator on a daily chart.

    It's only different when I want to display my SMA 8 daily on a lower timeframe, very strange.

    Comment


      #3
      Hello WalBen,

      Thank you for your note.

      Rather than assigning the close of the secondary data series to a new data series, then passing that to the SMA, if you swap,

      Moyenne2 = SMA(CloseJour, 8)[0];

      With,

      Moyenne2 = SMA(Closes[1], 8)[0];

      The second plot should correctly reflect the 8 period SMA of the daily time series.

      Please let us know if you need further assistance.
      Alan P.NinjaTrader Customer Service

      Comment


        #4
        Thanks, it works !

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Barry Milan, Yesterday, 10:35 PM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by DanielSanMartin, Yesterday, 02:37 PM
        2 responses
        13 views
        0 likes
        Last Post DanielSanMartin  
        Started by DJ888, 04-16-2024, 06:09 PM
        4 responses
        12 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        11 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        8 views
        0 likes
        Last Post nandhumca  
        Working...
        X