How to make EA enter trade ONCE and exit with exit signal...not enter on all new bars

my EA uses off-points on the AO (awesome oscillator) to enter a trade. when the trend goes short (from long), the AO changes to red (from blue) and enters short. it stays in the short trade until AO goes back to blue, then closes the short and buys long.

to make this happen, the EA compares the values of the current AO bar (shift 0) and the one previous (shift 1). it works great but problem is it enters trades on every bar, not just the initial one that began the new trend. it keeps comparing the current bar and previous bar on every hour (or 4 hour, etc) and making new trades. what code needs to be added to NOT enter trade again if a position is already open?. if anyone could guide me on this issue i would appreciate it.

If (OrdersTotal()) == 0) then…

any chance you could paste this orders-looping routine here for me? if i added it to bottom of mine, would it work in mine? thks.

tried to paste my code, it wouldnt take it.

Have you looked at the documentation?

ok i get the message loud and clear. i have been using EA builders and apparently they code poorly. can you recc a good online “dummies” book or website that will get me started with EA basics and give examples? or a direct link in this site’s documentation? thx

The resources are very poor. Everything you need is at MQL4.com, but its hard to find some specific information and the explanations are difficult to understand. Good luck.

Essentailly CodeMeister is correct. There are not any real easy MQL4 for dummies type resources out there. I learned by reading the documentation and by initially copying other very good MQL4 developers, and then eventually by writing my own work and tweaking it with a specific goal in mind.

And finally I learned and continue to learn by writing some MQL4 tutorials. I think there are a lot of good resources on mql4.com, and I might add to that some simple tutorials on writing code that I’ve created to help new coders develop the skills necessary to write their own code and / or edit the code of others to suit their needs.