How to stop EA from Trading

 

I have a problem

I have a simple EA which trades when two moving average indicators cross - simple enough. I want to use this on the hour candle and the problem I have is that if the trade condition is true, the trade will occur - which is fine.

If the trade stops out - this is also fine either at break even or stop loss.

BUT

If the trade stops out AND the conditions are still true for a trade, the EA will trade again.

I know there is code which permits the EA to only trade once on the formation of a new candle, but that does not work for me.

I need code which allows the EA to trade only once, while trading condition is true - and then not again if stop out happens for whatever reason.

Can anyone help me with this problem ?

I have looked through code and can not see a solution.....

 

if(OrderTotal==0 && Moving_Average_Cross){ Trade_Condition=true; }

if( Trade_Condition==true ){OrderSend(); Trade_Condition=false; }

Lets start with that since we cannot see your codes.

 

If you want it to trade only once and never again. Then:

static bool is_Traded_Once;

if( is_Traded_Once==false && Moving_Average_Cross){ Trade_Condition=true; }

if( Trade_Condition==true ){OrderSend(); is_Traded_Once==true; Trade_Condition=false;}

 
I will post code, but didnt think it necessary as it is very simple cross over.
 
ubzen:

If you want it to trade only once and never again. Then:

static bool is_Traded_Once;

if( is_Traded_Once==false && Moving_Average_Cross){ Trade_Condition=true; }

if( Trade_Condition==true ){OrderSend(); is_Traded_Once==true; }


is it not the case that the code is re-run every "tick" ?

so would this code not return static bool is_Traded_Once to 0 at the new tick ?

 
No - Static or Global Variables Keep their values between Ticks.
 
ubzen:
No - Static or Global Variables Keep their values between Ticks.


really ? and creating a static variable is as easy as that ? just to name it ?

thank you

 

If you want it to trade only once and never again on StopLoss or Break Even.

static bool is_StopLoss_BreakEven;

if( Order_Select_History==true) {

If(Order_Profit <= 0) { is_StopLoss_BreakEven=true; }

}


if( is_StopLoss_BreakEven==false && OrderTotal==0 && Moving_Average_Cross){ Trade_Condition=true; }

if( Trade_Condition==true ){OrderSend(); Trade_Condition=false;}

 
ubzen:

If you want it to trade only once and never again on StopLoss or Break Even.

static bool is_StopLoss_BreakEven;

if( Order_Select_History==true) {

If(Order_Profit <= 0) { is_StopLoss_BreakEven=true; }

}


if( is_StopLoss_BreakEven==false && OrderTotal==0 && Moving_Average_Cross){ Trade_Condition=true; }

if( Trade_Condition==true ){OrderSend(); Trade_Condition=false;}


thankyou I am very gratefull for your kind help
 
You're welcome.
Reason: