Finding Maximum and Minimum for previuos set of bars

Created at 28 Oct 2023, 06:35
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!
SA

sarvann24

Joined 25.10.2023

Finding Maximum and Minimum for previuos set of bars
28 Oct 2023, 06:35


HI, i am new to this ctrader and i don't know how to write the codes, so could you help me to find the highest high of last set of bars and not including the current bar, the code below includes current bar i believe. i want to check whether the current bar close price has crossed previous maximum for set of bars or minimum for set of bars 

      Bars.ClosePrices.Last(1) >   Bars.HighPrices.Maximum(3) 
      Bars.ClosePrices.Last(1) <   Bars.LowPrices.Minimum(3) 


@sarvann24
Replies

ialhamdazeez
29 Oct 2023, 10:20 ( Updated at: 30 Oct 2023, 06:23 )

Bars is an array beginning from the oldest price to current price. So you should first reverse it to begin from the current price, then skip the current price using skip function, then take the bars that you want to check for highest price using take function. Use the following code:

var bars = Bars.Reverse().Skip(1).Take(5).Where(b => b.High == Bars.Reverse().Skip(1).Take(5).Max(a => a.High));

// print the result 
foreach (var b in bars)
            {
                Print("time: " + b.OpenTime.ToString() + ", price: " + b.Close.ToString());
            }

@ialhamdazeez

r.stipriaan
29 Oct 2023, 19:40

Hi Sarvann,

You can make a array of the last bars and use the .min() and .max() function.

Or draw lines whenever a high is higher or low when lower.

 

 

 

 


@r.stipriaan

sarvann24
30 Oct 2023, 03:07

RE: Findiing Maximum and Minimum for previuos set of bars

r.stipriaan said: 

Hi Sarvann,

You can make a array of the last bars and use the .min() and .max() function.

Or draw lines whenever a high is higher or low when lower.

 

 

 

 

Hi Stipriaan,

Thanks , but I don't know coding, how to create an array

 


@sarvann24

PanagiotisChar
30 Oct 2023, 06:42

Hi there, 

You can try something like this

Bars.HighPrices.Take(Bars.HighPrices.Count-2).Skip(Bars.HighPrices.Count-5).Max()


@PanagiotisChar

sarvann24
30 Oct 2023, 06:45

RE: Findiing Maximum and Minimum for previuos set of bars

PanagiotisChar said: 

Hi there, 

You can try something like this

Bars.HighPrices.Take(Bars.HighPrices.Count-2).Skip(Bars.HighPrices.Count-5).Max()

Thanks :)


@sarvann24

sarvann24
30 Oct 2023, 06:45

RE: Findiing Maximum and Minimum for previuos set of bars

ialhamdazeez said: 

Bars is an array beginning from the oldest price to current price. So you should first reverse it to begin from the current price, then skip the current price using skip function, then take the bars that you want to check for highest price using take function. Use the following code:

var bars = Bars.Reverse().Skip(1).Take(5).Where(b => b.High == Bars.Reverse().Skip(1).Take(5).Max(a => a.High));// print the result foreach (var b in bars)            {                Print("time: " + b.OpenTime.ToString() + ", price: " + b.Close.ToString());            }

Thanks :)


@sarvann24