EA HELL - When it just doesn't work!

 

OK - I should know better than to get involved with programming what with the extremely limited knowledge I have of MQL but rather than constantly nag others to please do this or that to an EA I thought I'd give it a whirl myself. It's taken me over a month of weekends to get to grips with it and what I have to show for it I've attached to the post. The trouble with it is that it's not doing what I thought I'd told it to do and I'm now stuck banging my head against the wall.

The EA is a very basic MA cross over (big yawn, I know) that is supposed reverse position after a cross over and only when the bar has completed and has closed. Instead of this I'm seeing orders being made in random places! So what the heck am I doing wrong here?

Files:
 

I just gave it a quick test and it looked ok on the EURUSD 1H time frame. Can you post a screenshot of what you are seeing.

I have attached my chart from 6th July - 10th July on 1H EURUSD, just as a little example of what I see.

Files:
screenshot.jpg  91 kb
 

The close of the bar which triggered the long trade was 1.39802. I have a slippage variable currently set = 1. According to the journal, the order was priced at 1.39852. The following short order then appears to have been placed at 1.39734 yet the close of the bar was 1.39717. both long and short orders don't seem to be priced correctly as I would have thought that the long order would have been met at ask+slippage and the short order at bid-slippage.

Files:
 

updated program code by removing extraneous variables

I've updated the MQL code in post #1 and added commentary. Primarily the idea of this EA is to practice MQL coding skills in order to move on from hacking the code of others. Throughout the code I've used separate functions that control the orders so that it's a simple matter of calling the routine when a order needs to be executed. The program code uses variable names which aptly reflect their use. When the code is fixed and working properly, I hope that it will provide a basic EA template for everyone to use, enjoy and hopefully understand.

Reason: