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

indicators in different time-frames

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

    indicators in different time-frames

    Hi,

    How I can have CCI (14) 1H and CCI (14) M15 in the same strategy?

    when I code this
    Code:
    Add(CCI(int period));
    I have a CCI in the chart timeframe.

    #2
    Hello jossfx,

    Thank you for posting. If you want a multi-series plot added to your strategy, you would need to create a custom indicator which contains the muti-series logic for the CCI.

    Steps to accomplish:
    1) Tools -> Edit NinjaScript -> Indicator -> CCI
    2) Right click and Save As.. a new name (Something like "MultiTimeCCI" or similar)
    3) Change the #region Variables area to look like the following:
    Code:
    		#region Variables
    		private int			period		= 14;
                    private string              dataInstrument = "ES 12-15";
                    private PeriodType     dataPeriodType = PeriodType.Minute;
                    private int                  dataPeriod        = 60;
    		#endregion
    4) Change the Initialize() method to look like the following:
    Code:
    		protected override void Initialize()
    		{
                            Add(dataInstrument, dataPeriodType, dataPeriod);
    			Add(new Plot(Color.Orange, "CCI"));
    			Add(new Line(Color.DarkGray, 200, "Level 2"));
    			Add(new Line(Color.DarkGray, 100, "Level 1"));
    			Add(new Line(Color.DarkGray, 0, "Zero line"));
    			Add(new Line(Color.DarkGray, -100, "Level -1"));
    			Add(new Line(Color.DarkGray, -200, "Level -2"));
    		}
    5) Change the OnBarUpdate() method to look like the following:
    Code:
    		protected override void OnBarUpdate()
    		{
    			if (CurrentBar == 0)
    				Value.Set(0);
    			else if(CurrentBar > 0 && BarsInProgress == 1)
    			{
    				double mean = 0;
    				for (int idx = Math.Min(CurrentBar, Period - 1); idx >= 0; idx--)
    					mean += Math.Abs(Typical[idx] - SMA(Typical, Period)[0]);
    				Value.Set((Typical[0] - SMA(Typical, Period)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(Period, CurrentBar + 1)))));
    			}
    			else {Value.Set(Value[1]);}
    		}
    6) Change the #region Properties to look like the following:
    Code:
    		#region Properties
    		/// <summary>
    		/// </summary>
    		[Description("Numbers of bars used for calculations")]
    		[GridCategory("Parameters")]
    		public int Period
    		{
    			get { return period; }
    			set { period = Math.Max(1, value); }
    		}
    		[Description("The instrument of the data used for calculations")]
    		[GridCategory("Parameters")]
    		public string DataInstrument
    		{
    			get { return dataInstrument; }
    			set { dataInstrument = value; }
    		}
    		[Description("The period type of the data used for calculations")]
    		[GridCategory("Parameters")]
    		public PeriodType DataPeriodType
    		{
    			get { return dataPeriodType; }
    			set { dataPeriodType = value; }
    		}
    		[Description("The period value of the data used for calculations")]
    		[GridCategory("Parameters")]
    		public int DataPeriod
    		{
    			get { return dataPeriod; }
    			set { dataPeriod = Math.Max(1, value); }
    		}
    		#endregion
    7) Hit F5 on your keyboard to recompile
    8) In your strategy you would use the following to show the new CCI on the chart:
    Code:
    Add(MultiTimeCCI("CL 11-15", 60, PeriodType.Minute, 14));
    //First instrument, then instrument period, then instrument period type, then indicator period
    If you are new to multi-time frame scripts, I recommend reading through the following document: http://ninjatrader.com/support/helpG...lightsub=multi
    Please let me know if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Vietanhnguyen2hotmailcom, Yesterday, 10:29 AM
    4 responses
    23 views
    0 likes
    Last Post Vietanhnguyen2hotmailcom  
    Started by PhillT, 04-19-2024, 02:16 PM
    4 responses
    35 views
    0 likes
    Last Post PhillT
    by PhillT
     
    Started by ageeholdings, 05-01-2024, 05:22 AM
    5 responses
    37 views
    0 likes
    Last Post ageeholdings  
    Started by reynoldsn, Today, 02:34 PM
    0 responses
    13 views
    0 likes
    Last Post reynoldsn  
    Started by nightstalker, Today, 02:05 PM
    0 responses
    21 views
    0 likes
    Last Post nightstalker  
    Working...
    X