How to check if the last 30 candles are closed above moving average?
-
Hi, I would like to put condition to check whether the last 30 candles are closed above 100 Moving average. So far could not realize a practical way. Does someone know how to do that?
The current condition block only compares the current value of the moving average with older candles, but this does not translate to the fact that the those past candles have been above the MA in their own time. -
@zhahz
loop the last 30 candles and break the loop if a condition isnt met -
@bk7 I made the below loop based on an advice from one of the forum members. However, it does not work when I run the program. No orders will placed if I activate this loop. Please see below link (disregard the first 3 block on top, just put something in there to show you what is the general trend of my EA).
https://fxdreema.com/shared/eCeLfRnE -
i feel like thats totally illogical and this would probably work....
For longs
- if no position (be sure to specify in that block as well as all symbols and all groups)
- ma5 on c1 is above ma 20 on c1. current time frame
- candle 1 cross above ma 100 (very important, there is now a cross width to can edit in between the 2 ampersands now, that will let you select 30). current timeframe.
- final condition for c1 to do something. current time frame.
Do not share any of the blocks with the sell side and recreate for that with opposing conditions if thats what works.
-
-
@tipsywisdom thanks for the support.
I tried this but not working. The cross width is only for comparing the chosen candle ID with candle X in the past (cross width X). So in case there is a candle ID smaller than X which has touched the MA we won't find it and will output false results. -
@bk7 thanks for the reply.
I tried to realize this but couldn't understand some parts. up-counter and dn-counter I have no idea why they are there. Plus how the loop connects to buy or sell.Would you please also mention what is wrong with my logic? thanks.
-
- i didnt check your logic in detail, i just saw that this hardly will work and made for you a solution that works
- up counter is the number of bars that close above the ma and dn counter vice versa (this way you just have to loop once for the upper and lower close)
- in your Problem you didnt mention anyhting about buy or sell, however making such things isnt tricky at all and the forum has plenty of posts regarding this issue. If there are any advanced tasks surrounding buy and sell, you can post your problem here and someone will give you a hint
-
-
Thanks a lot guys, this forum is very supportive. Really appreciate that.
I didn't had the time to check your solutions, was busy developing a new idea which actually worked out and is very simple. The only drawback is that it won't work on the first X candle. Other than that pretty strait forward and easy, please check it, could be very useful for many different indicators:
-
Just click nd drag the condition block
-
@jstap Its a great way to get number of bars - thanks for the idea. However I wanted to ask if you ever experienced stack overflow error with several of these loops running per tick?
-
I have not, chat gbp might know an answer