Indicator not showing

Created at 09 May 2025, 09:30
FL

florent.herb

Joined 04.02.2022

Indicator not showing
09 May 2025, 09:30


Hi,

I don't know if anyone can help me on this issue. my custom indicator cannot display itself anymore on ctrader. Here is the code source…. I am a bit stuck here.

 

Best Regards,

Florent 

using cAlgo.API;
using cAlgo.API.Indicators;
using System.Runtime.InteropServices;

namespace cAlgo.Indicators
{
    [Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
    public class CustomSupertrendIndicator : Indicator, Supertrend
    {
        private IndicatorDataSeries _upBuffer;
        private IndicatorDataSeries _downBuffer;
        private AverageTrueRange _averageTrueRange;
        private IndicatorDataSeries _trend;

        [Parameter()]
        public TimeFrame Timeframe { get; set; }

        [Parameter(DefaultValue = 10, MaxValue = 2000, MinValue = 1)]
        public int Periods { get; set; }

        [Parameter(DefaultValue = 3.0)]
        public double Multiplier { get; set; }

        [Parameter()]
        public MovingAverageType MAType { get; set; }

        [Output("Up Trend", LineColor = "Green", PlotType = PlotType.DiscontinuousLine, Thickness = 2f)]
        public IndicatorDataSeries UpTrend { get; set; }

        [Output("Down Trend", LineColor = "Red", PlotType = PlotType.DiscontinuousLine, Thickness = 2f)]
        public IndicatorDataSeries DownTrend { get; set; }

        private Bars _bars;
        protected override void Initialize()
        {
            _bars = MarketData.GetBars(Timeframe);
            _trend = CreateDataSeries();
            _upBuffer = CreateDataSeries();
            _downBuffer = CreateDataSeries();
            _averageTrueRange = Indicators.AverageTrueRange(_bars, Periods, MAType);
        }

        private void InitDataSeries(int index)
        {
            UpTrend[checked(index)] = double.NaN;
            DownTrend[checked(index)] = double.NaN;
        }

        private void CalculateSuperTrendLogic(int index, double median, double averageTrueRangeValue)
        {
            var _tfIndex = _bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            if (_bars.ClosePrices[_tfIndex] > _upBuffer[checked(index - 1)])
                _trend[index] = 1.0;
            else if (_bars.ClosePrices[_tfIndex] < _downBuffer[checked(index - 1)])
            {
                _trend[index] = -1.0;
            }
            else
            {
                IndicatorDataSeries trend = _trend;
                int num1 = index;
                double num2 = _trend[checked(index - 1)];
                double num3 = num2 == -1.0 ? -1.0 : (num2 != 1.0 ? _trend[index] : 1.0);
                int index1 = num1;
                double num4 = num3;
                trend[index1] = num4;
            }
            IndicatorDataSeries upBuffer = _upBuffer;
            int num5 = index;
            double num6;
            if (_trend[index] < 0.0)
            {
                if (_trend[checked(index - 1)] > 0.0)
                {
                    num6 = median + Multiplier * averageTrueRangeValue;
                    goto label_11;
                }
                else if (_upBuffer[index] > _upBuffer[checked(index - 1)])
                {
                    num6 = _upBuffer[checked(index - 1)];
                    goto label_11;
                }
            }
            num6 = _upBuffer[index];
            label_11:
            int index2 = num5;
            double num7 = num6;
            upBuffer[index2] = num7;
            IndicatorDataSeries downBuffer = _downBuffer;
            int num8 = index;
            double num9;
            if (_trend[index] > 0.0)
            {
                if (_trend[checked(index - 1)] < 0.0)
                {
                    num9 = median - Multiplier * averageTrueRangeValue;
                    goto label_17;
                }
                else if (_downBuffer[index] < _downBuffer[checked(index - 1)])
                {
                    num9 = _downBuffer[checked(index - 1)];
                    goto label_17;
                }
            }
            num9 = _downBuffer[index];
            label_17:
            int index3 = num8;
            double num10 = num9;
            downBuffer[index3] = num10;
        }

        private void DrawIndicator(int index)
        {
            if (_trend[index] == 1.0)
            {
                UpTrend[checked(index)] = _downBuffer[index];
            }
            else
            {
                if (_trend[index] != -1.0)
                    return;
                DownTrend[checked(index)] = _upBuffer[index];
            }
        }

        public override void Calculate(int index)
        {
            InitDataSeries(index);
            var _tfIndex = _bars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
            double median = (_bars.HighPrices[_tfIndex] + _bars.LowPrices[_tfIndex]) / 2.0;
            double averageTrueRangeValue = _averageTrueRange.Result[_tfIndex];
            _upBuffer[index] = median + Multiplier * averageTrueRangeValue;
            _downBuffer[index] = median - Multiplier * averageTrueRangeValue;
            if (index < 1)
            {
                _trend[index] = 1.0;
            }
            else
            {
                CalculateSuperTrendLogic(index, median, averageTrueRangeValue);
                DrawIndicator(index);
            }
        }
    }
}

 

 

 


@florent.herb
Replies

firemyst
10 May 2025, 11:41

What does the logs say on the output?

Have you tried putting any print statements to see where it gets to?

Have you tried debugging in Visual Studio to see what happens?

What have you tried?


@firemyst