Looks ok. The error might be somewhere else. Note that Aggregation*60 doesn't work for H1 and greater in MQL5, use PeriodSeconds.

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
Hi I have what I thought was a simple routine but it has some issues.
1) it is will not restrict entry into a trade based on the logic that holds the price close to the 50 moving average:
if (((iClose(Symbol(),Aggregation1,1)+iOpen(Symbol(),Aggregation1,1))/2>=iMA_(Symbol(), Aggregation1, 50, 0, MODE_LWMA, PRICE_CLOSE, 1)-0.25)&&(iClose(Symbol(),Aggregation1,1)+iOpen(Symbol(),Aggregation1,1))/2<=iMA_(Symbol(), Aggregation1, 50, 0, MODE_LWMA, PRICE_CLOSE, 1)+0.25)
2.) It will not exit a trade based on the logic to exit when 5 MA crosses 50 MA
if ((iMA_(Symbol(), Aggregation1, 5, 0, MODE_LWMA, PRICE_CLOSE, 1)<iMA_(Symbol(), Aggregation1, 50, 0, MODE_LWMA, PRICE_CLOSE, 1)) && (iMA_(Symbol(), Aggregation1, 5, 0, MODE_LWMA, PRICE_CLOSE, 2)>=iMA_(Symbol(), Aggregation1, 50, 0, MODE_LWMA, PRICE_CLOSE, 2)) )
)
The more complete code is included. Any idea what I am doing wrong?