Information

Username: albatros667
Member since: 29 May 2019
Last login: 17 Dec 2024
Status: Active

Activity

Where Created Comments
Algorithms 0 1
Forum Topics 1 3
Jobs 0 0

Last Algorithm Comments

albatros667's avatar
albatros667 · 1 week ago

Update code

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class Break_Out_Channel : Indicator
    {
        [Output("Up", LineColor = "DarkCyan", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries Up { get; set; }

        [Output("Down", LineColor = "DarkCyan", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries Down { get; set; }

        [Output("Mid", LineColor = "DarkViolet", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, Thickness = 1)]
        public IndicatorDataSeries Mid { get; set; }

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

            if (Bars.ClosePrices[index] < Up[index - 1] && Bars.ClosePrices[index] > Down[index - 1])
            {
                Up[index] = Up[index - 1];
                Down[index] = Down[index - 1];
            }
            else
            {
                Up[index] = Bars.HighPrices[index];
                Down[index] = Bars.LowPrices[index];
            }

            Mid[index] = (Up[index] + Down[index]) / 2;
        }
    }
}