Download MetaTrader 5
To add comments, please log in or register
Deposit to your account in any convenient way. There are 4 of them here!
Dominic Gilbert
1632
Dominic Gilbert 2015.01.22 09:35 

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 

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.01.22 09:48  
Use timer or make one.
honest_knave
969
honest_knave 2015.01.22 09:57  
Are you also manually closing orders? Or always via TP or SL?
Dominic Gilbert
1632
Dominic Gilbert 2015.01.22 10:06  
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.
honest_knave
969
honest_knave 2015.01.22 10:19  

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.

Dominic Gilbert
1632
Dominic Gilbert 2015.01.22 11:56  
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?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2015.01.22 12:10  
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.
honest_knave
969
honest_knave 2015.01.22 12:23  
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);
Dominic Gilbert
1632
Dominic Gilbert 2015.01.22 22:46  
Oh I like that! Thank you for giving me a snippet example - very helpful!

I'll have a play tomorrow, cheers!
Dominic Gilbert
1632
Dominic Gilbert 2015.01.23 20:38  
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"?

honest_knave
969
honest_knave 2015.01.23 21:28  
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.

/ /12
To add comments, please log in or register