Multi Time Frame CCI indicator

Created at 02 Apr 2014, 22:03
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
RK

rkokerti

Joined 28.06.2012

Multi Time Frame CCI indicator
02 Apr 2014, 22:03


Hi!

Can anyone help me, why this code doesn't working properly?

I use this indicator on Daily Timeframe. In this case the Indicator shows 3 values / lines for 3 time frames (H4, D1, W1). But if I use this indicator on H4 timeframe or W1 timeframe, than the 3 mentioned values are diffrent. What am I doing wrong?

Thanks for all comments.


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
 
namespace cAlgo.Indicators
{
    [Levels(100, -100)]
    [Indicator(IsOverlay = false, TimeZone = TimeZones.CentralEuropeStandardTime, AccessRights = AccessRights.None)]
    public class MTF_CCI : Indicator
    {
//-----------------------------------------------------------------
    [Output("H4", Color = Colors.DodgerBlue, PlotType = PlotType.Line, Thickness = 1)]
    public IndicatorDataSeries H4 { get; set; }
    
    [Output("D1", Color = Colors.Gray, PlotType = PlotType.Line, Thickness = 1)]
    public IndicatorDataSeries D1 { get; set; }
    	
    [Output("W1", Color = Colors.Gold, PlotType = PlotType.Line, Thickness = 1)]
   	public IndicatorDataSeries W1 { get; set; } 
//-----------------------------------------------------------------
        private MarketSeries seriesH4; 
        private MarketSeries seriesD1; 
        private MarketSeries seriesW1; 
 
        private CommodityChannelIndex cciH4; 
        private CommodityChannelIndex cciD1; 
        private CommodityChannelIndex cciW1;         
//----------------------------------------------------------------- 
        protected override void Initialize()
        {
            seriesH4 = MarketData.GetSeries(TimeFrame.Hour4); 
            seriesD1 = MarketData.GetSeries(TimeFrame.Daily); 
            seriesW1 = MarketData.GetSeries(TimeFrame.Weekly); 
            
            cciH4 = Indicators.CommodityChannelIndex(seriesH4,20);
            cciD1 = Indicators.CommodityChannelIndex(seriesD1,20);
            cciW1 = Indicators.CommodityChannelIndex(seriesW1,20);
        }
//----------------------------------------------------------------- 
        public override void Calculate(int index)
        {

        ChartObjects.DrawHorizontalLine("Zero",0, Colors.Purple,1, LineStyle.Dots);
        
        var indexH4 = seriesH4.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
        H4[index] = cciH4.Result[indexH4];

        var indexD1 = seriesD1.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
        D1[index] = cciD1.Result[indexD1];

        var indexW1 = seriesW1.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
        W1[index] = cciW1.Result[indexW1];

   }
  }
}

 


@rkokerti
Replies

rkokerti
04 Apr 2014, 11:56

Dear Support,

Can you please respond to the above mentioned issue? This code is OK or Not?

Thanks in advance!


@rkokerti