Storing SL and TP

 

Hello everyone.

I have noticed that the EA I am working on closes trades if an MT4 is restarted. The issue is that the SL and TP values are lost due to the deinitialisation and logic to close trades gets triggerred on 0 TP values. Could anyone recommend how to store SL, TP and other values used for their calculation (support/resistance lines, etc.) I don't want to send SL and TP values to the broker with the OrderSend.

Recalculation of SL and TP is possible, but I am trying to avoid it if I can. Would storing SL and TP in a file do the trick? Is there any better way as I have had some issues with File operations before.

I appreciate your advice.

R

 
resin17:

Hello everyone.

I have noticed that the EA I am working on closes trades if an MT4 is restarted. The issue is that the SL and TP values are lost due to the deinitialisation and logic to close trades gets triggerred on 0 TP values. Could anyone recommend how to store SL, TP and other values used for their calculation (support/resistance lines, etc.) I don't want to send SL and TP values to the broker with the OrderSend.

Recalculation of SL and TP is possible, but I am trying to avoid it if I can. Would storing SL and TP in a file do the trick? Is there any better way as I have had some issues with File operations before.

I appreciate your advice.

R



Place a fake stoploss and takeprofit point that you are managing

those fake points are easie to find when you restart and from that point you get your logic for close on a easie way...

 
deVries:


Place a fake stoploss and takeprofit point that you are managing

those fake points are easie to find when you restart and from that point you get your logic for close on a easie way...


Not sure if I understand it correctly. Are you suggesting to send with the OrderSend some fake values (derivatives of the real SL and TP values) and upon restart of the MT4 read them from the broker's server and calculate back the required SL and TP? It can work, I guess, thank you.

 
resin17:

Not sure if I understand it correctly. Are you suggesting to send with the OrderSend some fake values (derivatives of the real SL and TP values) and upon restart of the MT4 read them from the broker's server and calculate back the required SL and TP? It can work, I guess, thank you.

Or you can just set the real SL & TP values . . . radical idea I know. I don't think your Broker will care either way . . .
 
i also doubt they will hunt them especcially as my EA is not a scalper...however, in my case the TP value changes with number of positions opened (on the same pair) and I need to ensure that it gets adjusted, hence I think it's better to use a wide TP value, so there is no issue with it getting triggered before the real TP is matched...any subsequent TPs can be derived from it..
 
resin17:

Hello everyone.

I have noticed that the EA I am working on closes trades if an MT4 is restarted. The issue is that the SL and TP values are lost due to the deinitialisation and logic to close trades gets triggerred on 0 TP values. Could anyone recommend how to store SL, TP and other values used for their calculation (support/resistance lines, etc.) I don't want to send SL and TP values to the broker with the OrderSend.

Recalculation of SL and TP is possible, but I am trying to avoid it if I can. Would storing SL and TP in a file do the trick? Is there any better way as I have had some issues with File operations before.

I appreciate your advice.

R


when opening the order, add SL and TP data to order comment. If MT4 restarts, your order comment will contain the SL and TP values you need, without re-calculating...
 
resin17:

Not sure if I understand it correctly. Are you suggesting to send with the OrderSend some fake values (derivatives of the real SL and TP values) and upon restart of the MT4 read them from the broker's server and calculate back the required SL and TP? It can work, I guess, thank you.



If you have an ECN account then it has to be done after placing the trade but if you wanted an invisible Stoploss of 100 pips then you set a stoploss for example 250 pips if pricedifference with your fakestoploss which you can manage is 150 pips you close the trade. If there was a restart needed you simply check your trades and the fakepoints again which can't be lost .....if you modify your trades and your broker is using high stoplevels / freezelevels you can manage the trade closer to your stoplevel with a trailingstop

 
c0d3:
when opening the order, add SL and TP data to order comment. If MT4 restarts, your order comment will contain the SL and TP values you need, without re-calculating...
Order Comments are not reliable . . . they can be changed or overwritten by the Broker.
 
deVries:


If you have an ECN account then it has to be done after placing the trade but if you wanted an invisible Stoploss of 100 pips then you set a stoploss for example 250 pips if pricedifference with your fakestoploss which you can manage is 150 pips you close the trade. If there was a restart needed you simply check your trades and the fakepoints again which can't be lost .....if you modify your trades and your broker is using high stoplevels / freezelevels you can manage the trade closer to your stoplevel with a trailingstop


Yes, with an ECN I will need to do an OrderSend + OrderModify which adds a little bit more room for an error (if OrderModify fails). I am using an OrderReliable, but it doesnt guarantee placing/modifying an order. Perhaps, I will stick to non-ECN brokers for now.
 
resin17:

Yes, with an ECN I will need to do an OrderSend + OrderModify which adds a little bit more room for an error (if OrderModify fails). I am using an OrderReliable, but it doesnt guarantee placing/modifying an order. Perhaps, I will stick to non-ECN brokers for now.


trie to code it it isn't that hard if you take the time to code

think what can happen and what do i then have to do....

Reason: