access to indicator values not as expected.....

Created at 23 Feb 2015, 21:27
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!
CI

cicondo

Joined 18.12.2012

access to indicator values not as expected.....
23 Feb 2015, 21:27


Hi @all,

I'm using a HeikinAshi indicator within a robot. I'd like to access a indicator propertie called "CurrentTrend", surprisingly I'm not getting any correct value. Using the indicator on a chart it works as designed. I don't understand what goin wrong. Please look at this small expample implementations ... Maybe someone find the bug :-)

Many thxs

*******************************************Indicator

namespace cAlgo.Indicators
{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class HeikinAshi : Indicator
    {
        private IndicatorDataSeries _haOpen;
        private IndicatorDataSeries _haClose;

        public int CandleWidth { get; set; }

        //public IndicatorDataSeries Result { get; set; }

        public int CurrentTrend { get; private set; }


        private Colors _upColor = Colors.Blue;
        private Colors _downColor = Colors.Red;

        protected override void Initialize()
        {
            CandleWidth = 5;
            _haOpen = CreateDataSeries();
            _haClose = CreateDataSeries();
            //Result = CreateDataSeries();

            CurrentTrend = 0;
        }

        public override void Calculate(int index)
        {
            var open = MarketSeries.Open[index];
            var high = MarketSeries.High[index];
            var low = MarketSeries.Low[index];
            var close = MarketSeries.Close[index];

            var haClose = (open + high + low + close) / 4;
            double haOpen;
            if (index > 0)
                haOpen = (_haOpen[index - 1] + _haClose[index - 1]) / 2;
            else
                haOpen = (open + close) / 2;

            var haHigh = Math.Max(Math.Max(high, haOpen), haClose);
            var haLow = Math.Min(Math.Min(low, haOpen), haClose);

            var color = Colors.White;
            // bearish
            if (haOpen > haClose)
            {
                CurrentTrend = -1;
                color = _downColor;
            }
            // bullischer Trend
            else
            {
                CurrentTrend = 1;
                color = _upColor;
            }
            ChartObjects.DrawLine("candle" + index, index, haOpen, index, haClose, color, CandleWidth, LineStyle.Solid);
            ChartObjects.DrawLine("line" + index, index, haHigh, index, haLow, color, 1, LineStyle.Solid);

            _haOpen[index] = haOpen;
            _haClose[index] = haClose;
            //Result[index] = CurrentTrend;
            Print("Currenttrend: {0}", CurrentTrend);
        }
    }
}

 

*************************************** Robot **********************************************************

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class HeikinAshiRobot : Robot
    {
        private HeikinAshi _ha4h;
        private HeikinAshi _ha1h;
        private HeikinAshi _haCurrent;

        private MacdCrossOver _macd;

        private MarketSeries _ms4h;
        private MarketSeries _ms1h;


        protected override void OnStart()
        {
            _ms4h = MarketData.GetSeries(TimeFrame.Hour4);
            _ms1h = MarketData.GetSeries(TimeFrame.Hour);

            //_ha4h = Indicators.GetIndicator<cAlgo.Indicators.HeikinAshi>(_ms4h);
            //_ha4h.TrendChange += TrendChangeH4;

            //_ha1h = Indicators.GetIndicator<cAlgo.Indicators.HeikinAshi>(_ms1h);
            //_ha1h.TrendChange += TrendChangeH1;

            _haCurrent = Indicators.GetIndicator<cAlgo.Indicators.HeikinAshi>(MarketSeries);
            //_haCurrent.TrendChange += TrendChangeCurrent;
            //_macd = Indicators.MacdCrossOver(26, 12, 9);
        }

        protected override void OnTick()
        {
        }
        protected override void OnBar()
        {
            ChartObjects.DrawText("Trend: ", string.Format("Current {0}", _haCurrent.CurrentTrend), StaticPosition.TopRight, Colors.Red);
        }
        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }


@cicondo
Replies

cicondo
24 Feb 2015, 08:29

Maybe I did not describe what's going wrong.

I expect that in the OnBar-Method of the robot that _haCurrent.CurrentTrend gets -1 or 1 depending on what the HeikinAshi Indikator displays for a trend. But I receive alweas 0. What's going wrong or better where I'm wrong.

Many Thx guys


@cicondo

Spotware
27 Feb 2015, 14:32

Spotware doesn't provide cBot development support. We can recommend you to contact one of our Partners or post a job in Development Jobs section.

 


@Spotware