Stopping multiple trades on one bar

 

I'm fairly new at the MQL5 language and I've got a problem I can't find a solution to.

I've got a couple of promising strategies but when things are a bit volatile I can enter a position that gets closed out rapidly and then re-enters again on the same bar. This sometimes happens two or three times during a bar. Regularly the first trade is profitable but the subsequent ones are almost invariably loosing ones.

What I need is a bit of code that will stop the platform from opening a position on a bar that has already had a position opened and closed on it but then leaves it free to trade on subsequent bars.

I imagine it should be relatively simple to do but I haven't had enough experience to work it out

If anyone could point me to some code that would do the trick or give me some suggestions as to how to achieve it I'd be most grateful.

Cheers
Geoff

 
Geoff:

I'm fairly new at the MQL5 language and I've got a problem I can't find a solution to.

I've got a couple of promising strategies but when things are a bit volatile I can enter a position that gets closed out rapidly and then re-enters again on the same bar. This sometimes happens two or three times during a bar. Regularly the first trade is profitable but the subsequent ones are almost invariably loosing ones.

What I need is a bit of code that will stop the platform from opening a position on a bar that has already had a position opened and closed on it but then leaves it free to trade on subsequent bars.

I imagine it should be relatively simple to do but I haven't had enough experience to work it out

If anyone could point me to some code that would do the trick or give me some suggestions as to how to achieve it I'd be most grateful.

Cheers
Geoff

You can get it here https://www.mql5.com/en/forum/1995#comment_18270
How to use the OrdersTotal() correctly?
How to use the OrdersTotal() correctly?
  • www.mql5.com
In my demo account, I always get "0" when I use the function to get the total orders of the account.
 

use flag i think ..

set this at global variable 

bool Flag=false;

 

inside function (example)

void openOrders()

 {

    if(!Flag)

     {

      Flag=true;

      //your code here to send orders 

     } 

 }

 then set the reset flag conditions inside any of event, can be onTick or start or chartEvent or else (example only)

if(TimeToStr(Time[0])>TimeReset){Flag=false;}

 


 

Hi

Thanks for the replies. While neither were exactly what I needed they both pointed me in the direction I needed to go to solve the problem and it's now working fine.

Cheers
Geoff