Replies

masedir
02 Jan 2025, 16:46

RE: RE: Custom indicators not appearing under reference manager

masedir said: 

PanagiotisCharalampous said: 

Hi there,

Do your custom indicators have source code?

Best regards,

Panagiotis

No, I don't have source codes. I downloaded one of them  (Nonlag Schaff Trend Cycle) from clickalgo.com; The other ones I downloaded from different sites on the web.

The two indicators that I have provided source code for can be referenced after compiling them, however the NRTRChannel gives an error below when referencing it: 

Error MSB4006: There is a circular dependency in the target dependency graph involving target "_GenerateRestoreProjectPathWalk". (/usr/local/share/dotnet/sdk/8.0.303/NuGet.targets, line: 1196, column: 5)

As for the other indicators that I don't have source code for, I'm still having no luck. 


@masedir

masedir
30 Dec 2024, 15:10 ( Updated at: 02 Jan 2025, 07:06 )

RE: Custom indicators not appearing under reference manager

PanagiotisCharalampous said: 

Hi there,

Do your custom indicators have source code?

Best regards,

Panagiotis

 

Trend_Intensity-Index Source Code

 

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Trend_intensity_index : Indicator
    {
        [Parameter("Period", DefaultValue = 30)]
        public int Period { get; set; }

        [Parameter("MA Method", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MAMethod { get; set; }

        [Parameter("Upper Level", DefaultValue = 80.0)]
        public double LevelHigh { get; set; }

        [Parameter("Lower Level", DefaultValue = 20.0)]
        public double LevelLow { get; set; }

        [Output("tii", LineColor = "Gray", PlotType = PlotType.Line, Thickness = 2)]
        public IndicatorDataSeries TII { get; set; }

        [Output("upperBand", LineColor = "DeepSkyBlue", PlotType = PlotType.Line)]
        public IndicatorDataSeries UpperBand { get; set; }

        [Output("lowerBand", LineColor = "SandyBrown", PlotType = PlotType.Line)]
        public IndicatorDataSeries LowerBand { get; set; }

        [Output("level", LineColor = "DarkGray", PlotType = PlotType.Line)]
        public IndicatorDataSeries Level { get; set; }

        private MovingAverage maa;
        private MovingAverage map;
        private int maPeriod;

        protected override void Initialize()
        {
            maPeriod = Period * 2;
            maa = Indicators.MovingAverage(Bars.ClosePrices, maPeriod, MAMethod);
            map = Indicators.MovingAverage(Bars.ClosePrices, 1, MAMethod);
        }

        public override void Calculate(int index)
        {
            if (index < Period)
                return;

            double sumUpDeviations = 0;
            double sumDnDeviations = 0;

            for (int k = 0; k < Period && index >= k; k++)
            {
                double diff = map.Result[index - k] - maa.Result[index];
                if (diff > 0)
                    sumUpDeviations += diff;
                else
                    sumDnDeviations -= diff;
            }

            double value;
            if ((sumUpDeviations + sumDnDeviations) != 0)
                value = 100 * sumUpDeviations / (sumUpDeviations + sumDnDeviations);
            else
                value = 0;

            TII[index] = value;
            Level[index] = (value > LevelHigh) ? 100 : (value < LevelLow) ? 0 : 50;
            
            // Set upper and lower bands for filling
            if (value > 50)
            {
                UpperBand[index] = value;
                LowerBand[index] = Math.Min(value, LevelHigh);
            }
            else
            {
                UpperBand[index] = value;
                LowerBand[index] = Math.Max(value, LevelLow);
            }
        }
    }
}

@masedir

masedir
30 Dec 2024, 15:08 ( Updated at: 02 Jan 2025, 07:06 )

RE: Custom indicators not appearing under reference manager

PanagiotisCharalampous said: 

Hi there,

Do your custom indicators have source code?

Best regards,

Panagiotis

 

NRTR Channel source code

Please receive attachedusing System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NRTRChannel : Indicator
    {
        [Parameter("ATR Period", DefaultValue = 40)]
        public int ATRPeriod { get; set; }

        [Parameter("ATR Multiplier", DefaultValue = 2.0)]
        public double ATRMultiplier { get; set; }

        [Parameter("Show Price Labels", DefaultValue = true)]
        public bool ShowLabels { get; set; }

        [Output("longResistance", LineColor = "DeepSkyBlue", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries CeilingBuffer { get; set; }

        [Output("longSupport", LineColor = "DeepSkyBlue", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries BuyBuffer { get; set; }

        [Output("shortSupport", LineColor = "LightSalmon", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries SellBuffer { get; set; }

        [Output("shortResistance", LineColor = "LightSalmon", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Dots, Thickness = 2)]
        public IndicatorDataSeries FloorBuffer { get; set; }

        private IndicatorDataSeries trendBuffer;
        private AverageTrueRange atr;
        private const int UP_TREND = 1;
        private const int DOWN_TREND = -1;

        protected override void Initialize()
        {
            trendBuffer = CreateDataSeries();
            atr = Indicators.AverageTrueRange(ATRPeriod, MovingAverageType.Simple);
        }

        public override void Calculate(int index)
        {
            if (index <= ATRPeriod)
                return;

            if (index == ATRPeriod + 1)
            {
                if (Bars.ClosePrices[index] > Bars.LowPrices[index])
                {
                    trendBuffer[index] = UP_TREND;
                    CeilingBuffer[index] = Bars.ClosePrices[index];
                    BuyBuffer[index] = Bars.ClosePrices[index] - ATRMultiplier * atr.Result[index];
                }
                else
                {
                    trendBuffer[index] = DOWN_TREND;
                    FloorBuffer[index] = Bars.ClosePrices[index];
                    SellBuffer[index] = Bars.ClosePrices[index] + ATRMultiplier * atr.Result[index];
                }
                return;
            }

            if (trendBuffer[index - 1] > 0)
            {
                if (Bars.LowPrices[index] > CeilingBuffer[index - 1])
                {
                    CeilingBuffer[index] = Bars.ClosePrices[index];
                    FloorBuffer[index] = double.NaN;
                    BuyBuffer[index] = Bars.ClosePrices[index] - ATRMultiplier * atr.Result[index];
                    SellBuffer[index] = double.NaN;
                    trendBuffer[index] = UP_TREND;
                }
                else if (Bars.ClosePrices[index] < BuyBuffer[index - 1])
                {
                    trendBuffer[index] = DOWN_TREND;
                    FloorBuffer[index] = Bars.ClosePrices[index];
                    SellBuffer[index] = Bars.ClosePrices[index] + ATRMultiplier * atr.Result[index];
                    CeilingBuffer[index] = double.NaN;
                    BuyBuffer[index] = double.NaN;
                }
                else
                {
                    CopyPreviousValues(index);
                }
            }
            else
            {
                if (Bars.HighPrices[index] < FloorBuffer[index - 1])
                {
                    FloorBuffer[index] = Bars.ClosePrices[index];
                    CeilingBuffer[index] = double.NaN;
                    SellBuffer[index] = Bars.ClosePrices[index] + ATRMultiplier * atr.Result[index];
                    BuyBuffer[index] = double.NaN;
                    trendBuffer[index] = DOWN_TREND;
                }
                else if (Bars.ClosePrices[index] > SellBuffer[index - 1])
                {
                    trendBuffer[index] = UP_TREND;
                    CeilingBuffer[index] = Bars.ClosePrices[index];
                    BuyBuffer[index] = Bars.ClosePrices[index] - ATRMultiplier * atr.Result[index];
                    FloorBuffer[index] = double.NaN;
                    SellBuffer[index] = double.NaN;
                }
                else
                {
                    CopyPreviousValues(index);
                }
            }

            if (ShowLabels && index == Bars.ClosePrices.Count - 1)
            {
                ShowPriceLevels(index);
            }
        }

        private void CopyPreviousValues(int index)
        {
            SellBuffer[index] = SellBuffer[index - 1];
            BuyBuffer[index] = BuyBuffer[index - 1];
            CeilingBuffer[index] = CeilingBuffer[index - 1];
            FloorBuffer[index] = FloorBuffer[index - 1];
            trendBuffer[index] = trendBuffer[index - 1];
        }

        private void ShowPriceLevels(int index)
        {
            var existingLabels = Chart.Objects.Where(obj => obj.Name.StartsWith("NRTR_"));
            foreach (var label in existingLabels)
            {
                Chart.RemoveObject(label.Name);
            }

            cAlgo.API.Color color;
            double upperLevel, lowerLevel;

            if (trendBuffer[index] == UP_TREND)
            {
                color = cAlgo.API.Color.DeepSkyBlue;
                upperLevel = CeilingBuffer[index];
                lowerLevel = BuyBuffer[index];
            }
            else
            {
                color = cAlgo.API.Color.LightSalmon;
                upperLevel = SellBuffer[index];
                lowerLevel = FloorBuffer[index];
            }

            if (!double.IsNaN(upperLevel))
            {
                var upperText = Chart.DrawText(
                    "NRTR_Res_" + index,
                    upperLevel.ToString("F5"),
                    index,
                    upperLevel,
                    color
                );
                upperText.VerticalAlignment = VerticalAlignment.Center;
                upperText.HorizontalAlignment = HorizontalAlignment.Right;
            }

            if (!double.IsNaN(lowerLevel))
            {
                var lowerText = Chart.DrawText(
                    "NRTR_Sup_" + index,
                    lowerLevel.ToString("F5"),
                    index,
                    lowerLevel,
                    color
                );
                lowerText.VerticalAlignment = VerticalAlignment.Center;
                lowerText.HorizontalAlignment = HorizontalAlignment.Right;
            }
        }
    }
}

@masedir

masedir
30 Dec 2024, 11:35 ( Updated at: 02 Jan 2025, 07:06 )

RE: Custom indicators not appearing under reference manager

PanagiotisCharalampous said: 

Hi there,

Do your custom indicators have source code?

Best regards,

Panagiotis

No, I don't have source codes. I downloaded one of them  (Nonlag Schaff Trend Cycle) from clickalgo.com; The other ones I downloaded from different sites on the web.


@masedir