how to make EA enter once and exit once?

 

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 close 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.

 
nedro018:

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 close 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.


Forum search page usually help a lot,  https://www.mql4.com/search#!keyword=one per bar&module=mql4_module_forum  . You may also want to try different keyword, like once per bar, once a time, or whatever - you get the idea.

 
phi.nuts:


Forum search page usually help a lot,  https://www.mql4.com/search#!keyword=one per bar&module=mql4_module_forum  . You may also want to try different keyword, like once per bar, once a time, or whatever - you get the idea.

 

thanks.  actually i worded it wrong.  i want a 1-time entry.  period.  not per bar.  one entry, one exit.  didnt find this in searches.  thx again.   

 

You should not get a signal in the same direction again on the next bar unless you coded something wrong.

To prevent the EA from opening more than one order, you can loop through the open orders. If there is one, don't allow the EA to trade.

 
You should not get a signal in the same direction again on the next bar unless you coded something wrong. Post your code - there are no mind readers here.
 
WHRoeder:
You should not get a signal in the same direction again on the next bar unless you coded something wrong. Post your code - there are no mind readers here.


thanks both of you.  sorry, i forgot to include code, here it is below.  i think i need the "looping thru open orders" added somehwere but dont know how to do this part:


<SNIP> 

 
nedro018:


thanks both of you.  sorry, i forgot to include code, here it is below.  i think i need the "looping thru open orders" added somehwere but dont know how to do this part:


<SNIP>

Please edit your post . . . 


Please use this to post code . . . it makes it easier to read.  Or if it's too big attach it as a file . . .

 

Maybe you also want to read this and this.

 
kronin:

Maybe you also want to read this and this.



ok i get the messages 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 the basics and give examples?  thx all.
 
nedro018:


ok i get the messages 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 the basics and give examples?  thx all.
Book
Reason: