Price Not Crossed MA in X Candles
-
I have a project idea, but I need the logic "price has not touched/crossed an MA in the last X candles (could be 5 or whatever. Not particularly relevant at the moment).
If I use the cross above block, and change the cross width to 5, then take the false output from that, is that really all it takes?
So, for longs, Candle Low of CandleID 1 (starting on previous candle), cross above, width 5, take the false output.
I'm kinda having a hard time with the "cross width" idea mainly. It means that it's crossed above at any point in the last X candles, right?
Basically, if price is above, and the low touches and penetrates the MA, even if the open and close are above, I would like it to invalidate.
I'm sorry this question probably seems so simple, but the cross width functionality, though I think I clearly understand it, I'm not feeling confident in that understanding for whatever reason.
Thanks, peeps!

-
I've been further experimenting with it (just ran a little EA with a node that has, for buys/above MA, Candle Low, Cross Below, Cross Width: 5, then my MA settings. I took the false output from that. Idea being that it only trades when price has NOT crossed below the MA within the last 5 candles).
I'm starting to feel like I need to create a custom loop that searches for the last candle that cross above/below, take the candle ID from that candle, and check that it is greater than 5? (Because if it's candleID 7, it's been more than 5 candles?)
Is this the most proper/correct/only way to accomplish this task? I simply need some logic that allows trades when price hasn't interacted with the MA in X candles (touch or cross).
-
Bonus points if the method we conclude with has an optimizable input (so I can check if 3 candles is superior to 8 candles, for example).
-
I'm leaving this here in case someone else runs across it and needs help with something similar.
I decided to create a custom loop. Roar discussed them with me very in depth over the last few days on this thread if you wish to further your knowledge:
https://fxdreema.com/forum/topic/10894/scan-historical-data-for-conditions-values?page=1
Basically, my solution I decided on was similar:
Set up a variable "loopid" and set up a variable "candlelookbackID" and a constant "CandleLookback
After my other trade conditions (this is where I'd want to check if the price had violated the MA), I set up condition "loopid <= CandleLookback"
If true, it adds 1 to loopid and adds one to candlelookbackID (both are defaulted to 0).
Next block, condition, for longs, Candle Low > MA. In the candleID slot, I put in candlelookbackID for both of these.
If true, then the output goes back to the "loopid <= CandleLookback". This adds 1 more onto each of my variables and keeps running, one candle back until it hits a candle where the low is below the MA (breaks the loop) or until the loopid is greater than my CandleLookback.
Therefore, if loopid, when that first block is false (loopid <= CandleLookback), then it places my trade.
There's an additional block down there, after the buy/sell that resets loopid and candlelookbackID to 0 for the next time.
I hope this can be of help to someone else!
Thanks again for all your help, Roar (if you see this)
-
@cdwilder1 Impressive works from both of you. Congrats!
-
could it also have been done using market properties range?
I'll think of it and post a version sort of how you explained above and see if its similar.
or possible the Price X Indicator block?