Find recent High/Low with specific conditions
-
Hi @roar & @miro1360 ,
I'm hoping one of you guys can help me with this one as you seem to be the resident Variable experts, which I'm sure will be needed to solve this one.I'm wanting to find the recent high, but only when both preceding candles have highs that are <= their following candle.
I then need to get the value of that high to set SL at.
I thought I could do it with many many pairs of conditions that work back through the candles then put out that candle number to a variable, but I'm sure there must be a more elegant way to get the job done...
cheers!

-
Hello!
Maybe some loop works, like this:

It first looks for candle ID 1, and then compares it to ID 2 and then ID 2 to ID 3. If conditions are not met, ID 1 becomes ID 2 and the loop continues from there until it finds what it is looking for.
Be careful though, loop like this doesn't have any "expiration", so if it doesnt find what it looks for - your metatrader crashes. Thats why I put block # 6 there, to limit the loop.
-
Hi @roar ,
Thanks so much for this, incredibly useful!
I'm sure I'll use this for many projects...
I had an idea of the blocks required but couldn't get it sorted in my head how to connect them.
I never would have thought about the limiter either, nice how it's path is also a double redundancy.Though does the value in Block 7 need to be '+1'?
...or does that need to be done by the Adjust field?
Do the Condition blocks 2 & 3 looking at the candles also need to be '+1' so they head backwards through the candles?I'll need to increment the start points of everything anyway because my trade indicator appears at ID1.
cheers!

-
@drayzen oops, youre absolutely right, the IDs go in the wrong way in my example. I should sleep more

https://fxdreema.com/shared/XYqEDtP9c
Here's the fixed blocks, but I'm sure you already got the idea. -
Even better, we make an EA that can read the future! xD
Yeah, I'm just working my way through testing, did a build and had some strange results initially with virtual stops (some trades not getting stops set).
Doing another ground up build testing along the way with hard stops first...Do you know if the exact syntax with spaces in calculations matters?
e.g. Do these all work?
Variable+1
Variable +1
Variable + 1cheers
-
I'm fairly sure you can put as many spaces as you want, if its a math operation
-
I did my own goof, went off visual and linked 7 -> 6 instead of 6 -> 7...
Much better now! xD -
Oh, yeah, that connection is not very clear in my picture