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 bortz, 11-06-2023, 08:04 AM
    47 responses
    1,602 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    8 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    4 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    12 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X