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

Muti TimeFrame Indictor

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

    Muti TimeFrame Indictor

    I've written a short indicator to draw a line 2 Standard Deviations form the 1 Tick data, regardless of what the primary time frame is. But for some reason despite the fact I have set the calculations to always use 1 Tick Data it is using the Primary Bars series and I cant figure out why??

    Thanks in advance for any help.

    Here is the code:-

    Code:
      {
            #region Variables
            	private double sndDev;
                private int myInput0 = 1; // Default setting for MyInput0
    			private int tBIP; //  tick bars BIP Series variable
           
            #endregion
    
            protected override void Initialize()
            {
    			Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "Mean"));
    			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "+2Std"));
    			Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "-2Std"));
    			Add(PeriodType.Tick, 1); // add 1 Tick data series
    			
                Overlay				= true;
    			
    			// sets 1 Tick bars in Progress series
    			if(BarsPeriod.Id == PeriodType.Tick && BarsPeriod.BasePeriodValue == 1)
    			{
    				tBIP = 0;
    			}
    			else
    				tBIP = 1;	
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if( CurrentBars[tBIP] < sDPeriod)
    				return;
    			
    			if( BarsInProgress == tBIP ); // always use 1 tick data for calculations
    			{
    				sndDev = StdDev( Closes[tBIP], sDPeriod )[0];
    				Values[0].Set( SMA( Closes[tBIP], sDPeriod )[0] );
    				Values[1].Set( SMA( Closes[tBIP], sDPeriod  )[0] + 2*sndDev );
    				Values[2].Set( SMA( Closes[tBIP], sDPeriod  )[0] - 2*sndDev );
    			}
            }
    
            #region Properties
            [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
            {
                get { return Values[0]; }
            }
    
    		private int sDPeriod;
            [Description("")]
            [GridCategory("Parameters")]
            public int SDPeriod
            {
                get { return sDPeriod; }
                set { sDPeriod = Math.Max(1, value); }
            }
            #endregion
        }

    #2
    Hello GKonheiser,

    Thank you for your note.

    This is due to the nature of the Sync data for the Plots and Set()

    These items are only updated by the primary series. You are only accessing the data for the tick series and then assigning those values to the Plot series.

    When the primary bar updates for the next bar then these will get updated to the new values.

    You cannot change the plotting of the Plot series to another time-frame other than primary

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 04-23-2024, 09:53 PM
    2 responses
    49 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    193 views
    0 likes
    Last Post Hasadafa  
    Started by GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,235 views
    0 likes
    Last Post xiinteractive  
    Working...
    X