Drawing a line at high/low

Created at 28 May 2019, 19:32
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!
AL

alex_mihail

Joined 09.08.2018

Drawing a line at high/low
28 May 2019, 19:32


Specifically high and low for the day on the Hourly chart (between 8am-5pm for e.g.) How would I go about doing that? Here is my template - currently this moves the line on every new bar which I don't want.

 

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

namespace cAlgo
{

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ActiveAreas : Indicator
    {
        public Color _textColor;

        [Parameter("High Color", DefaultValue = "DarkOrange")]
        public string ColorH { get; set; }

        [Parameter("Low Color", DefaultValue = "Orange")]
        public string ColorL { get; set; }

        [Parameter("Low Lookback", DefaultValue = "0")]
        public int Low { get; set; }

        [Parameter("High Lookback", DefaultValue = "2")]
        public int High { get; set; }

        //[Output("Line")]
        //public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // Draw the text on the last bar high.
            var highPrice = MarketSeries.High.Last(High);
            var lowPrice = MarketSeries.Low.Last(Low);

            Chart.DrawHorizontalLine("Active Area High", highPrice, ColorH, 2, LineStyle.Solid);

            Chart.DrawHorizontalLine("Active Area Low", lowPrice, ColorL, 2, LineStyle.Solid);


        }
    }
}

 


@alex_mihail
Replies

PanagiotisCharalampous
29 May 2019, 09:38

Hi Alex,

See below an example for using the Daily timeframe

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

namespace cAlgo
{

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ActiveAreas : Indicator
    {
        public Color _textColor;

        [Parameter("High Color", DefaultValue = "DarkOrange")]
        public string ColorH { get; set; }

        [Parameter("Low Color", DefaultValue = "Orange")]
        public string ColorL { get; set; }

        [Parameter("Low Lookback", DefaultValue = "0")]
        public int Low { get; set; }

        [Parameter("High Lookback", DefaultValue = "2")]
        public int High { get; set; }

        //[Output("Line")]
        //public IndicatorDataSeries Result { get; set; }

        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // Draw the text on the last bar high.
            var series = MarketData.GetSeries(TimeFrame.Daily);
            var highPrice = series.High.Last(High);
            var lowPrice = series.Low.Last(Low);

            Chart.DrawHorizontalLine("Active Area High", highPrice, ColorH, 2, LineStyle.Solid);

            Chart.DrawHorizontalLine("Active Area Low", lowPrice, ColorL, 2, LineStyle.Solid);


        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

alex_mihail
29 May 2019, 11:45

Thanks Panagiotis!

EDIT: Is there a way to specify this to grab the highest point WITHIN 5 bars back rather than the high FROM 5 bars back exactly?


@alex_mihail

igorjrmedeiros
18 Jul 2019, 17:24

RE:

alex_mihail said:

Thanks Panagiotis!

EDIT: Is there a way to specify this to grab the highest point WITHIN 5 bars back rather than the high FROM 5 bars back exactly?

Hi alex_mihail,

 

Look this, I hope help you.

 

double max = Functions.Maximum(MarketSeries.High, period);

// where: period is the bars back
//            

 


@igorjrmedeiros