Easiest way to halt trading on stop loss being hit?

 

So I know when a stop loss was hit: what's the easiest way to halt trading for 1 hour when I know this?

 I.e. OnTick fails on an equality statement every time for 1 hour after I discover a stop loss was hit?

cheers 

 
Use timer or make one.
 
Are you also manually closing orders? Or always via TP or SL?
 
I will sometimes manually close trades, yea. 95% of the time it's via take profit or stop loss. But I enter x4 positions on any one given setup.

I do not know how to make a timer, so any wisdom on this, would be great.
 

One way is to check if OrderClosePrice() is nearer to OrderTakeProfit() or nearer to OrderStopLoss().

However, if you are manually closing orders that will present a problem, unless you move both TP and SL to 0 before closing (you could consider doing this by code, if suitable. For example, using a script or a button).

If you find an order has been closed by SL, then add one hour to OrderCloseTime() and don't open new orders until after this time.

 
Thanks for your reply.

Just thought; I use this OnTick:

if( OpenOrdersThisPair(Symbol()) == 0 && H1_Buy_Touch == "H1 Buy Touch" ...)

...

OrderEntry(0);


H1_Buy_Touch is essentially the last check before the trade is placed (if no trades are open it will place a trade like above - Buy Stop).

If that is not "H1 Buy Touch" then no trades can physically be placed. If OpenOrdersThisPair(Symbol()) == 4 , I want a way to safely stop my EA when it goes from == 4 to == 0 for "x" amount of time. Is this possible?

 
It is possible. Depends on how you code the logic and how it reflects your idea. To be honest, what you want is quite easy to achieve actually.
 
DomGilberto:
Thanks for your reply.

Just thought; I use this OnTick:


H1_Buy_Touch is essentially the last check before the trade is placed (if no trades are open it will place a trade like above - Buy Stop).

If that is not "H1 Buy Touch" then no trades can physically be placed. If OpenOrdersThisPair(Symbol()) == 4 , I want a way to safely stop my EA when it goes from == 4 to == 0 for "x" amount of time. Is this possible?

Create a static datetime variable which you update when required (for example, when you have had an order closed by SL).

Then add a simple check that sufficient time has passed before placing an order.

static datetime NextOrder = 0;

...

if(ClosedBySL) NextOrder = OrderCloseTime()+3600;

...


if(TimeCurrent()>=NextOrder && OpenOrdersThisPair(Symbol()) == 0 && H1_Buy_Touch == "H1 Buy Touch" ...)

...

OrderEntry(0);
 
Oh I like that! Thank you for giving me a snippet example - very helpful!

I'll have a play tomorrow, cheers!
 
If MT4 crashes or I shut it down during:

if(TimeCurrent()>=NextOrder...

...

How does TimeCurrent() work in this part and would I need to store in GlobalVariable for it to remember NextOrder if it were set to "3,600"?

 
DomGilberto:
If MT4 crashes or I shut it down during:

How does TimeCurrent() work in this part and would I need to store in GlobalVariable for it to remember NextOrder if it were set to "3,600"?

TimeCurrent() is the last known server time.

Personally, I wouldn't bother with global variables because you can easily recalculate the value with a loop through your order history.

Reason: