Need Help : To Get Shifts of a Fractals Structure

 

Hi coders, I need your help. I need to get a set of codes that to detect the shifts of a fractals structure with the following conditions (kindly look at my picture to have a better understanding) :-




Sf = Shift

Px = Fractals Price Level


- - - - - - - -

Fractals structure 1 :-

FrL1Sf < FrH1Sf && FrH1Sf < FrL2Sf && FrL2Sf < FrH2Sf &&

FrH2Px > FrL2Px && FrL1Px < MathMin(FrH2Px,FrL2Px) && FrH1Px > MathMax(FrH2Px,FrL2Px)


My mission is to get the shifts of FrL1Sf and FrH2Sf.

- - - - - - - -

Fractals structure 2 :-

FrL3Sf < FrH3Sf && FrH3Sf < FrL4Sf && FrL4Sf < FrH4Sf &&

FrH4Px > FrL4Px && FrL3Px < MathMin(FrH4Px,FrL4Px) && FrH3Px > MathMax(FrH4Px,FrL4Px)


My mission is to get the shifts of FrL3Sf and FrH4Sf.

- - - - - - - -


I found a similar calculation of loop by using "while" at https://www.forexfactory.com/thread/post/3850167#post3850167 but the problem that I'm facing is the shifts distances of the fractals are not fixed, it is varying.


Hope the coders can give me a set of loop formulas to detect the shifts of the samples of Fractals structure 1 and Fractals structure 2 above, thank you.