Hello, i want to write my function so that it makes a for loop comparison of different EMAs for order execution. In theory a for loop would go through all the numbers, but mine does nothing. Any ideas?
- Questions from Beginners MQL4 MT4 MetaTrader 4
- Print OrderProfit of last 5 close trade
- ema loop
Your looping is wrong!
void CheckForEMATrade(){ int x,y; int period[]={20,25,30,35,40,45,50,55,60,65,70}; // size=11! for(x=0;x<10;x++) for(y=1;y<=10;y++){ double EMAx=iMA(Symbol(),0,period[x],0,MODE_EMA,PRICE_CLOSE,1), EMAy=iMA(Symbol(),0,period[y],0,MODE_EMA,PRICE_CLOSE,1); if(EMAy>EMAx)printf("buy"); if(EMAy<EMAx)printf("sell"); } }
but maybe y should always be smaller than x?
for(x=1;x<11;x++) for(y=0;y<x;y++){
gooly:
As far as i know array numeration is starting from 0!Your looping is wrong!
but maybe y should always be smaller than x?
BUT! thanks! in fact for loops need variables to be embedded and not being declared outside, that was the problem actually. :)
trisperon:
As far as i know array numeration is starting from 0!
BUT! thanks! in fact for loops need variables to be embedded and not being declared outside, that was the problem actually. :)
As far as i know array numeration is starting from 0!
BUT! thanks! in fact for loops need variables to be embedded and not being declared outside, that was the problem actually. :)
It is not clear from your reply whether you are agreeing or disagreeing with Gooly.
Gooly's suggestion is correct as far as I can see.
Maybe it would be a good idea for you to post your amended code.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register