highest and lowest values for a number of bars starting from previous bar

Created at 22 Nov 2018, 02:48
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!
mparama's avatar

mparama

Joined 11.10.2016

highest and lowest values for a number of bars starting from previous bar
22 Nov 2018, 02:48


Dear Panagiotis,

please I need your help,

I'm trying to find the "highest and lowest values for a number of bars starting from previous bar" in a cBot

 double highest = MarketSeries.High.Maximum(12);
 double lowest = MarketSeries.Low.Minimum(12);

they gives me the value for 12 bars starting from the LastValue

Actually I need the value for 12 bars starting from high/low(1) or high/Low(2)

In drawing it on chart its Ok

 "ChartObjects.DrawLine("livello_0", MarketSeries.OpenTime.Last(12), livello_0, MarketSeries.OpenTime.Last(2), livello_0, Colors.DeepPink, 4, LineStyle.Solid);"

but I need the value starting from previous bar for my "logic" in opening and closing orders

Probably in Indicators i can obatin it using (index-1 or index-2)

but I need it on a cBot

There is a way to do it ?

I really appreciate your always kind help.

Regards

Mparama


@mparama
Replies

PanagiotisCharalampous
22 Nov 2018, 10:31

Hi Luigi,

You will need to use some loops. See below.

            var highest = MarketSeries.High.Last(1);
            for (int i = 2; i <= 12; i++)
            {
                if (MarketSeries.High.Last(i) > highest)
                    highest = MarketSeries.High.Last(i);
            }

            var lowest = MarketSeries.Low.Last(1);
            for (int i = 2; i <= 12; i++)
            {
                if (MarketSeries.Low.Last(i) < lowest)
                    lowest = MarketSeries.Low.Last(i);
            }

Let me know if this helps,

Best Regards,

Panagiotis


@PanagiotisCharalampous

mparama
22 Nov 2018, 11:34

RE:

Panagiotis Charalampous said:

Hi Luigi,

You will need to use some loops. See below.

            var highest = MarketSeries.High.Last(1);
            for (int i = 2; i <= 12; i++)
            {
                if (MarketSeries.High.Last(i) > highest)
                    highest = MarketSeries.High.Last(i);
            }

            var lowest = MarketSeries.Low.Last(1);
            for (int i = 2; i <= 12; i++)
            {
                if (MarketSeries.Low.Last(i) < lowest)
                    lowest = MarketSeries.Low.Last(i);
            }

Let me know if this helps,

Best Regards,

Panagiotis

Thank you very much !!!!

have a nice day

Luigi


@mparama