Checking if Trade is closed on stoploss or takeprofit - page 2

 

There is no way natively in MQL (that I know of) that you can retrieve whatever it is that makes this turn green:

 

 

I don't know about that,

I think when price is close to takeprofit, a green color is added, if the order is closed, the green color remain in place.

 

As far as I know, that color (in Account History) only shows when a trade was closed by TP.

Same for SL (but red).

 

Open Trade

 

Closed Trade 

 

The colour only shows when the trade is closed by the TP as you can see above.

As you can see, price was within 10 pips of the TP and so it was coloured green. I closed it manually, still within 10 pips of TP, but it no longer shows as green in the trade history.

I suspect that the comment in square brackets defines the colour, but I don't know for sure. Probably irrelevant as there is no way to read the colour. 

 

II think the MT4 program is watching this distance :

if ( MathAbs( OrderClosePrice() - OrderStopLoss() ) < Point )


when the order is closed, the information ticket, price and color are copied to the history orders array .. ??

 
GumRai:

 

 

 

The colour only shows when the trade is closed by the TP as you can see above.

As you can see, price was within 10 pips of the TP and so it was coloured green. I closed it manually, still within 10 pips of TP, but it no longer shows as green in the trade history.

I suspect that the comment in square brackets defines the colour, but I don't know for sure. Probably irrelevant as there is no way to read the colour. 

I get the same behaviour (TP on Open Orders highlighted green <10 pips but only stays green in Account History if TP was hit) but I don't get anything written in the comments. So I suspect that may be a red-herring.
 
ffoorr:

II think the MT4 program is watching this distance :


when the order is closed, the information ticket, price and color are copied to the history orders array .. ??


Then it would fail to mark the TP green if there was any slippage greater than 1 point...

 
honest_knave:

Then it would fail to mark the TP green if there was any slippage greater than 1 point...

I checked through orders history to find a trade closed with slippage.

These are closed by SL with 26 , 28 Point slippage. The colour is still red

Note: the slippage actually appears to be recorded in the comment. I had never noticed this before.

SL 

and the slippage was positive 

 

Thanks GumRai.

Which brings us neatly back around to the start:

The terminal does know whether a trade was closed by TP or SL (because it colors the order history accordingly), but we can't access that information using MQL. We can only make a best guess.

 

Yes Honest Knave,

I actually contacted the service deck nearly a year ago about this.

This is what I sent...


...It is not clear to me whether all brokers incorporate the letters sp or tp in the order comment when a trade hits the StopLoss or TakeProfit. Is this at the brokers' discretion or is it automatically done with every broker?

Sometimes, when writing code, it is necessary to check whether a trade was closed by hitting the sp or tp or manually. Because of slippage, it may not always be possible to simply compare the OrderClosePrice() with OrderStopLoss() or OrderTakeProfit().

I think that it would be a really good idea to have an additional function OrderCloseAction() or something like that to return whether the trade was closed by  hitting the sp or tp or manually

Thank You  

Their reply...

 

Hello,

Thank you for your suggestion. Unfortunately, we have no plans to add this additional function.

which is a shame as it could be so useful.

My reply...

Ok, thank you, but are you able to answer the posted question please?

...It is not clear to me whether all brokers incorporate the letters sp or tp in the order comment when a trade hits the StopLoss or TakeProfit. Is this at the brokers' discretion or is it automatically done with every broker? 

and theirs

 

It is automatically done with every broker. And also the broker can change this value itself.

It is worrying that I did not get a definitive answer as the broker can change the value. 

I can only say that in my experience, I have never seen an order closed at SL or TP that does not include SL,TP, sl or tp in the OrderComment.

Reason: