How do i set my flag variables when a stop loss is encountered using my EA?

 

Hi Friends,

I am a novice in mql4 programming. In my EA there are times when the trade gets closed due to it hitting the stop loss.

Now, if the trade is closing normally, i.e. using my EA, then i am actually setting a flag to indicate whether the EA should go for another trade or not. Since i am using Moving Average method, i will go for trading only after the next crossing.

Now, if the current trade hits a stop loss, is there any way the EA can know? or is there any function to know whether a previous trade was closed due to hitting the stop loss? How do i check the trade history?

Thanks in advance.

Rajesh

 
rajesh_puu:

Hi Friends,

I am a novice in mql4 programming. In my EA there are times when the trade gets closed due to it hitting the stop loss.

Now, if the trade is closing normally, i.e. using my EA, then i am actually setting a flag to indicate whether the EA should go for another trade or not. Since i am using Moving Average method, i will go for trading only after the next crossing.

Now, if the current trade hits a stop loss, is there any way the EA can know? or is there any function to know whether a previous trade was closed due to hitting the stop loss? How do i check the trade history?

Thanks in advance.

Rajesh

Hi Rajesh

If an order is closed for any reason, the close time is non-zero. Use OrderCloseTime() to find out what the order close time is. If the order is closed OrderCloseTime() will return the time it was closed, otherwise it returns 0.

Cheers

Jellybean

 
Jellybean wrote >>

Hi Rajesh

If an order is closed for any reason, the close time is non-zero. Use OrderCloseTime() to find out what the order close time is. If the order is closed OrderCloseTime() will return the time it was closed, otherwise it returns 0.

Cheers

Jellybean

Hi Jelly bean,

I am using OrderCloseTime() in my EA to log in the closing time. That is possible only for those trades which the EA is closing programatically. Some of the trades are closed automatically when hitting the STOP LOSS value. How do i know whether my previous trade was closed due to hitting the STOP LOSS? Are you trying to say that if a particular trade is closed due to hitting the STOP LOSS, then the closing time will not be there for that particular trade?

Please do clarify. Thanks for the help.

Regards,

Rajesh

 
rajesh_puu wrote >>

Hi Jelly bean,

I am using OrderCloseTime() in my EA to log in the closing time. That is possible only for those trades which the EA is closing programatically. Some of the trades are closed automatically when hitting the STOP LOSS value. How do i know whether my previous trade was closed due to hitting the STOP LOSS? Are you trying to say that if a particular trade is closed due to hitting the STOP LOSS, then the closing time will not be there for that particular trade?

Please do clarify. Thanks for the help.

Regards,

Rajesh

I have found this links which is quite helpful, but i think from the other discussions, there is no concrete function to determine whether the previous trade is due to stop loss or not.

'How to determine the last trade closed by stoploss or not?'

'How to caculate how many orders are closed by StopLoss or TakeProfit?'

Regards,

Rajesh

Reason: