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 AttiM, 02-14-2024, 05:20 PM
    12 responses
    213 views
    0 likes
    Last Post DrakeiJosh  
    Started by cre8able, 02-11-2023, 05:43 PM
    3 responses
    238 views
    0 likes
    Last Post rhubear
    by rhubear
     
    Started by frslvr, 04-11-2024, 07:26 AM
    8 responses
    117 views
    1 like
    Last Post NinjaTrader_BrandonH  
    Started by stafe, 04-15-2024, 08:34 PM
    10 responses
    47 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by rocketman7, Today, 09:41 AM
    3 responses
    12 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X