• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 mittie3, Today, 03:33 AM
    0 responses
    5 views
    0 likes
    Last Post mittie3
    by mittie3
     
    Started by Againmain1, Today, 03:04 AM
    0 responses
    7 views
    0 likes
    Last Post Againmain1  
    Started by tonytimpa, Today, 01:33 AM
    0 responses
    5 views
    0 likes
    Last Post tonytimpa  
    Started by kiwidtrader, Yesterday, 11:49 PM
    0 responses
    5 views
    0 likes
    Last Post kiwidtrader  
    Started by jmahon, Yesterday, 11:44 PM
    0 responses
    7 views
    0 likes
    Last Post jmahon
    by jmahon
     
    Working...
    X