do{if(mrates[0].open>ma[0]&&mrates[0].close>ma[0]; Canddlewait++;} while(Canddlewait<NumofCanddles)
- You are looking at the same candle each loop.
- You need to loop over your 'X amount of canddles" and count above and below. You are looping NumofCanddles
not X.
Thank you very much for your answer!!
Sadly, I copied the code but it didnt work it only returns canddlewait as 5 which is the same number as NumofCanddles. How do I iterate through the whole range?
Every time I run it, it returns the value of NumofCanddles but it doesnt go up in units. It goes from 0 to whatever other value is there. no 1,2,3,4 from 0 to 15.
Thank you very much for your answer!!
Sadly, I copied the code but it didnt work it only returns canddlewait as 5 which is the same number as NumofCanddles. How do I iterate through the whole range?
Every time I run it, it returns the value of NumofCanddles but it doesnt go up in units. It goes from 0 to whatever other value is there. no 1,2,3,4 from 0 to 15.
datetime tim; int numbars = 5; if (ma0 < ma1 && ma1 > ma2) tim = iTime(NULL,0,0); else if (ma0 > ma1 && ma1 < ma2) tim = iTime(NULL,0,0); bool trade = false; if iTime(NULL,0,0) - tim >= 60*Period() * numbars) { //5 bars after the last reversal trade = true; }
- you should add a new bar detection
- whenever a new bar occurs, loop over the recent X-1 candles to get the counts above/below MA, and remember the result in 2 static variables (say
countAbove, countBelow)
- for every
tick, if the current close is above/below your threshold and the static variable's value equals X-1, you're ready to open a
position
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Im trying to make my EA wait for an X amount of canddles above or below a moving average (but not in the middle) to trade a signal. Currently I have a problem in the loop iteration when I'm trying to get a loop to count the canddles that fully opened/closed above/below it. Could you give me a hand?
Thank you very much!
Here goes the code: