Check a condition for a period since last trade was closed
-
Here I have something for the advanced folks.
Let's assume I have a moving average. If price is above the MA I assume the price is trending up. If it is below the MA, I assume the price trending down. So far so good.
I want to check the condition now, if since the last trade was closed (eg. long trade) the price ever was closing below my MA. Any idea?
Probably I need some looping and maybe custom code. But any help I appreciate.

-
Hi @trader-philipps!
Here's how I would approach this. It might still have some bug, I'm too lazy to properly test anything.
Blocks:- Load the last closed trade
- Save its ticket number
- Use custom code to get the trade closing candle ID
- Do something closed_ID times. When this process starts the first time:
- set our final condition to FALSE,
- set iteration ID to closed_ID
When the process makes an iteration, decrease iter_ID by 1.
- Now we can just check the condition with MA indicator, using iter_ID in the Candle ID fields.
If this condition is a success, modify variable belowcondition to TRUE

Hope this helps.
https://fxdreema.com/shared/JOQCkRG3e
If you import the .mq4, you get the correct variables as well.
0_1567877553885_check past.mq4 -
@roar Thanks. That is a good start. Is there a way to get the order type as well? As it influence the condition to check.
-
@trader-philipps I would put a "Check type (last closed)" before the condition, and copy the condition and then just flip the comparator for the case of sell order:
