Topics
Replies

PJ_Ctrader
22 Feb 2022, 10:10 ( Updated at: 21 Dec 2023, 09:22 )

RE:

amusleh said:

Hi,

Try this:

using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class QQE : Indicator
    {
        private int _wildersPeriod;
        private int _startBar;
        private const int SF = 1;
        private ExponentialMovingAverage _ema;
        private ExponentialMovingAverage _emaAtr;
        private ExponentialMovingAverage _emaRsi;
        private RelativeStrengthIndex _rsi;

        private IndicatorDataSeries _atrRsi, _main, _signal;

        private ZeroLagMacd _zeroLagMacd;

        [Parameter(DefaultValue = 8)]
        public int Period { get; set; }

        [Parameter("Long Cycle", DefaultValue = 26)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 12)]
        public int ShortCycle { get; set; }

        [Parameter("Signal Periods", DefaultValue = 9)]
        public int SignalPeriods { get; set; }

        [Output("Bullish Dots", LineColor = "Green", LineStyle = LineStyle.Dots, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries BullishDots { get; set; }

        [Output("Bearish Dots", LineColor = "Red", LineStyle = LineStyle.Dots, PlotType = PlotType.Points, Thickness = 3)]
        public IndicatorDataSeries BearishDots { get; set; }

        protected override void Initialize()
        {
            _atrRsi = CreateDataSeries();

            _wildersPeriod = Period * 2 - 1;
            _startBar = _wildersPeriod < SF ? SF : _wildersPeriod;

            _rsi = Indicators.RelativeStrengthIndex(MarketSeries.Close, Period);
            _emaRsi = Indicators.ExponentialMovingAverage(_rsi.Result, SF);
            _emaAtr = Indicators.ExponentialMovingAverage(_atrRsi, _wildersPeriod);
            _ema = Indicators.ExponentialMovingAverage(_emaAtr.Result, _wildersPeriod);

            _zeroLagMacd = Indicators.GetIndicator<ZeroLagMacd>(LongCycle, ShortCycle, SignalPeriods);

            _main = CreateDataSeries();
            _signal = CreateDataSeries();
        }

        public override void Calculate(int index)
        {
            _main[index] = _emaRsi.Result[index];

            if (index <= _startBar)
            {
                _signal[index] = 0;

                return;
            }

            _atrRsi[index] = Math.Abs(_main[index - 1] - _main[index]);

            double tr = _signal[index - 1];

            if (_main[index] < _signal[index - 1])
            {
                tr = _main[index] + _ema.Result[index] * 4.236;

                if (_main[index - 1] < _signal[index - 1] && tr > _signal[index - 1])
                    tr = _signal[index - 1];
            }
            else if (_main[index] > _signal[index - 1])
            {
                tr = _main[index] - _ema.Result[index] * 4.236;

                if (_main[index - 1] > _signal[index - 1] && tr < _signal[index - 1])
                    tr = _signal[index - 1];
            }

            _signal[index] = tr;

            BullishDots[index] = double.NaN;
            BearishDots[index] = double.NaN;

            if (_zeroLagMacd.MACD[index] > _zeroLagMacd.Signal[index] && _main[index] > _signal[index])
            {
                BullishDots[index] = Bars.LowPrices[index];
            }
            else if (_zeroLagMacd.MACD[index] < _zeroLagMacd.Signal[index] && _main[index] < _signal[index])
            {
                BearishDots[index] = Bars.HighPrices[index];
            }
        }
    }
}

The above indicator is QQE and it uses zero lag MACD, you have to reference the zero lag MACD before building it via cTrader automate reference manager.

Thank you so much for the help. It does work but I wanted a DOT on crossover of QMP main above QMP Signal so that only one dot is printed around 1*ATR under the low of the bar at which the first signal occurred. The current code plots a series of dots one signal true. I know the code is very close to what I am looking for but I am new to C completely. thanks

Here is tradingview example,


@PJ_Ctrader

PJ_Ctrader
04 Feb 2022, 20:02

QMP Filter

Hey

Do you happen to have the converted QMP Filter indicator for C trader. The one that shows the dot on chart?

 

THanks

PJ


@PJ_Ctrader