Lowest low period and bars back

Created at 09 Mar 2022, 12:01
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!
UN

undseth

Joined 18.05.2021

Lowest low period and bars back
09 Mar 2022, 12:01


Hi,

 

Is it a way to do this in Ctrader? 

In tradingview it looks like this:

low[24] == ta.lowest(low[7], 77)

 

Thanks in advance

Halvard


@undseth
Replies

amusleh
10 Mar 2022, 10:26

Hi,

If you want to get the lowest/minimum value x bars back you can use this method:

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // To get index on a cBot use
            // var index = Bars.Count - 1;

            // low of 20 previous bars
            var low = Minimum(Bars.LowPrices, index - 20, index);

            Print(low);
        }

        /// <summary>
        /// Returns the minimum value between start and end (inclusive) index in a dataseries
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">Start index (Ex: 1)</param>
        /// <param name="endIndex">End index (Ex: 10)</param>
        /// <returns>double</returns>
        private double Minimum(DataSeries dataSeries, int startIndex, int endIndex)
        {
            var min = double.PositiveInfinity;

            for (var i = startIndex; i <= endIndex; i++)
            {
                min = Math.Min(dataSeries[i], min);
            }

            return min;
        }
    }
}

 


@amusleh

undseth
10 Mar 2022, 11:13

RE:

amusleh said:

Hi,

If you want to get the lowest/minimum value x bars back you can use this method:

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // To get index on a cBot use
            // var index = Bars.Count - 1;

            // low of 20 previous bars
            var low = Minimum(Bars.LowPrices, index - 20, index);

            Print(low);
        }

        /// <summary>
        /// Returns the minimum value between start and end (inclusive) index in a dataseries
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">Start index (Ex: 1)</param>
        /// <param name="endIndex">End index (Ex: 10)</param>
        /// <returns>double</returns>
        private double Minimum(DataSeries dataSeries, int startIndex, int endIndex)
        {
            var min = double.PositiveInfinity;

            for (var i = startIndex; i <= endIndex; i++)
            {
                min = Math.Min(dataSeries[i], min);
            }

            return min;
        }
    }
}

 

 

 

Thank you :).

 

Best regards

Halvard


@undseth

undseth
11 Mar 2022, 11:26

RE: RE:

Hi again,

 

I'm not sure this will do what I asked for, but maybe i'm wrong?

I need to get the lowest low in a range lets say 63 bars back.

so something like this:

Lowest.low(range), [bars back]

 

Hope this make sense?

 

Regards

Halvard

 

 

undseth said:

amusleh said:

Hi,

If you want to get the lowest/minimum value x bars back you can use this method:

using System;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        protected override void Initialize()
        {
            // Initialize and create nested indicators
        }

        public override void Calculate(int index)
        {
            // To get index on a cBot use
            // var index = Bars.Count - 1;

            // low of 20 previous bars
            var low = Minimum(Bars.LowPrices, index - 20, index);

            Print(low);
        }

        /// <summary>
        /// Returns the minimum value between start and end (inclusive) index in a dataseries
        /// </summary>
        /// <param name="dataSeries"></param>
        /// <param name="startIndex">Start index (Ex: 1)</param>
        /// <param name="endIndex">End index (Ex: 10)</param>
        /// <returns>double</returns>
        private double Minimum(DataSeries dataSeries, int startIndex, int endIndex)
        {
            var min = double.PositiveInfinity;

            for (var i = startIndex; i <= endIndex; i++)
            {
                min = Math.Min(dataSeries[i], min);
            }

            return min;
        }
    }
}

 

 

 

Thank you :).

 

Best regards

Halvard

 


@undseth

amusleh
14 Mar 2022, 08:46

Hi,

The data series itself has a minimum method, so you can use is like this:

// This gives you the lowest price in last 20 bars lows
var lowestLow = Bars.LowPrices.Minimum(20)

 


@amusleh

undseth
14 Mar 2022, 11:12

RE:

amusleh said:

Hi,

The data series itself has a minimum method, so you can use is like this:

// This gives you the lowest price in last 20 bars lows
var lowestLow = Bars.LowPrices.Minimum(20)

 

 

Hi again,

This will get the lowest low from start index 1, but I need it to get the lowest low from eks start index 10, so it shuld

start at index 10 and get the lowest low in a periode of 20 bars. Hope this make sense??

 

Thanks for all the help!

Halvard


@undseth

amusleh
14 Mar 2022, 18:10

RE: RE:

undseth said:

amusleh said:

Hi,

The data series itself has a minimum method, so you can use is like this:

// This gives you the lowest price in last 20 bars lows
var lowestLow = Bars.LowPrices.Minimum(20)

 

 

Hi again,

This will get the lowest low from start index 1, but I need it to get the lowest low from eks start index 10, so it shuld

start at index 10 and get the lowest low in a periode of 20 bars. Hope this make sense??

 

Thanks for all the help!

Halvard

Then use the method I posted on my first post, you can set the start/end index and it will give you the low, ex:

// This will return the lowest low between bar index 90 and 100
var low = Minimum(Bars.LowPrices, 90, 100);

 


@amusleh

undseth
14 Mar 2022, 18:46

RE: RE: RE:

amusleh said:

undseth said:

amusleh said:

Hi,

The data series itself has a minimum method, so you can use is like this:

// This gives you the lowest price in last 20 bars lows
var lowestLow = Bars.LowPrices.Minimum(20)

 

 

Hi again,

This will get the lowest low from start index 1, but I need it to get the lowest low from eks start index 10, so it shuld

start at index 10 and get the lowest low in a periode of 20 bars. Hope this make sense??

 

Thanks for all the help!

Halvard

Then use the method I posted on my first post, you can set the start/end index and it will give you the low, ex:

// This will return the lowest low between bar index 90 and 100
var low = Minimum(Bars.LowPrices, 90, 100);

 

Thank you so much!

 

Best regards

Halvard


@undseth