change indicator to cAlgo

Created at 12 Feb 2018, 21:53
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!
WA

waisuklondon@gmail.com

Joined 12.02.2018

change indicator to cAlgo
12 Feb 2018, 21:53


Hi everyone

 

I am totally new in here ,just wondering if someone help how to indicator to cAlgo .

 using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators

namespace cAlgo.Robots
{
    (Robot IsOverlay = false, TimeZone = TimeZones.UTC+1, ScalePrecision = 5 , AccessRights = AccessRights.None)
    public class killerMACD : Indicator
    {
        private ExponentialMovingAverage _emaLong;
        private ExponentialMovingAverage _emaShort;
        private ExponentialMovingAverage _emaSignal;
        private ExponentialMovingAverage _emaLong2;
        private ExponentialMovingAverage _emaShort2;

        [Parameter("Volume", DefaultValue = 1000)]
        public int volume { get; set; }

        [Parameter(DefaultValue = 5000, MinValue = 400)]
        public int StopLoss { get; set; }

        [Parameter(DefaultValue = 5000, MinValue = 400)]
        public int TakeProfit { get; set; }


        [Parameter("MACD LongCycle", DefaultValue = 8, MinValue = 1)]
        public int LongCycle { get; set; }

        [Parameter("MACD ShortCycle", DefaultValue = 5, MinValue = 1)]
        public int ShortCycle { get; set; }

        [Parameter("MACD Period", DefaultValue = 9, MinValue = 1)]
        public int MACDPeriod { get; set; }
        
        [Output("Histogram", Color = Colors.Turquoise, PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Histogram { get; set; }

        [Output("MACD", Color = Colors.Blue)]
        public IndicatorDataSeries MACD { get; set; }

        [Output("Signal", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries Signal { get; set; }

        private IndicatorDataSeries _zeroLagEmaShort;
        private IndicatorDataSeries _zeroLagEmaLong;

        protected override void Onstart()
        {
            _killerEmaShort = CreateDataSeries();
            _killerEmaLong = CreateDataSeries();

            _emaLong = Indicators.ExponentialMovingAverage(MarketSeries.Close, LongCycle);
            _emaLong2 = Indicators.ExponentialMovingAverage(_emaLong.Result, LongCycle);

            _emaShort = Indicators.ExponentialMovingAverage(MarketSeries.Close, ShortCycle);
            _emaShort2 = Indicators.ExponentialMovingAverage(_emaShort.Result, ShortCycle);

            _emaSignal = Indicators.ExponentialMovingAverage(MACD, SignalPeriods);
        }

        public override void OnBar()
        {
            _killerEmaShort[index] = _emaShort.Result[index] * 2 - _emaShort2.Result[index];
            _killerEmaLong[index] = _emaLong.Result[index] * 2 - _emaLong2.Result[index];

            MACD[index] = _zeroLagEmaShort[index] - _zeroLagEmaLong[index];

            Signal[index] = _emaSignal.Result[index];
            Histogram[index] = MACD[index] - Signal[index];
        }
    }
}

I really appreciate 

 

Thank you

Elias


@waisuklondon@gmail.com