Help with MA cross over Price IN EA
What is the index of "previous bar" ?
-
Because zero is not one of the ENUM_TRADE_REQUEST_ACTIONS ; exactly what the message says.
-
Because you are calling OrderSend and not checking its return code; exactly what the message says.
Check your return codes, and report your errors (including market prices and your variables). Don't look at GLE/LE unless you have an error. Don't just silence the compiler (MT5/MT4+strict), it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 programming forum (2012)
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles (2014)

I am attempting to create a simple EA that uses only the Close Price of the Previous bar compared to an MA of 'x' periods.
Parameters:
If the Close Price of the Previous bar is Higher than MA, then Buy. Close the trade when the Close Price of the Previous bar is below the MA.
If the Close Price of the Previous bar is Lower than the MA, then Sell. Close the trade when the Close Price of the Previous bar is above the MA.
So far, the Opening and Closing of the Trades is happening at the wrong times. I cannot tell why. I suspect it has something to do with my MA creation.
Any help is appreciated.
Thank you
The following is my code: