Indicator that draws horizontal lines on the high/low

Created at 31 Aug 2022, 17:46
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

waym77

Joined 22.07.2021

Indicator that draws horizontal lines on the high/low
31 Aug 2022, 17:46


Hi,

I am trying to make an indicator that draws horizontal lines on the high/low for the specified number of days. Can anyone assist?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class DailySR : Indicator
    {
        [Parameter("Period", Group = "Default", DefaultValue = 5, MinValue = 1)]
        public int Period { get; set; }
        
        Bars _bars;
        double[] min, max;

        protected override void Initialize()
        {
            _bars = MarketData.GetBars(TimeFrame.Daily);
        }

        public override void Calculate(int index)
        {
            for (int i = 0; i < Period; i++)
            {
                min[i] = _bars.LowPrices.Last(i++);
                max[i] = _bars.HighPrices.Last(i++);
                Chart.DrawHorizontalLine("Upline_" + i++.ToString(), max[i], Color.White, 1, LineStyle.DotsRare);
                Chart.DrawHorizontalLine("Downline_" + i++.ToString(), min[i], Color.White, 1, LineStyle.DotsRare);
            }
        }
    }
}

Thanks,


@waym77