Download MetaTrader 5
To add comments, please log in or register
Having questions? Ask them on the Forum - traders will help you!
Michael
19
Michael 2014.04.15 22:18 

Hello,

I'm working on an expert that will sometimes use sell-stop orders to get out of a position, rather than just having a stop-loss on that position. For example, if a long order for EURUSD has been placed at 1.0000, it may place sell-stop orders at 0.9950, 0.9900 and 0.9850 so that these orders combined will close out the long order completely.

What I find as I am testing this expert is that the sell-stop orders seem to count as "active" orders, rather than simply diminishing the initial order. That is, my expert sees this as me having a long order at 1.0000 and a number of short orders in the opposite direction. It is as if hedging is somehow allowed in test mode even though with my actual broker the behavior would be different.

Is there some way to tell the testing framework to treat orders in the opposite direction as "partial closes", such as would be the case in a live trading scenario? Otherwise I'm not sure how I can test the performance of my expert....

-Michael

qjol
3243
qjol 2014.04.15 22:49  
Does your broker allows hedging ?
Alain Verleyen
Moderator
28652
Alain Verleyen 2014.04.15 23:03  
mberg2007:

Hello,

I'm working on an expert that will sometimes use sell-stop orders to get out of a position, rather than just having a stop-loss on that position. For example, if a long order for EURUSD has been placed at 1.0000, it may place sell-stop orders at 0.9950, 0.9900 and 0.9850 so that these orders combined will close out the long order completely.

What I find as I am testing this expert is that the sell-stop orders seem to count as "active" orders, rather than simply diminishing the initial order. That is, my expert sees this as me having a long order at 1.0000 and a number of short orders in the opposite direction. It is as if hedging is somehow allowed in test mode even though with my actual broker the behavior would be different.

Is there some way to tell the testing framework to treat orders in the opposite direction as "partial closes", such as would be the case in a live trading scenario? Otherwise I'm not sure how I can test the performance of my expert....

-Michael

Use OrderClose() with part of initial volume you want to close and the ticket number of the long order.

With MT4, a sell-stop (or any pending order) open a new trade.

Michael
19
Michael 2014.04.16 20:52  
qjol:
Does your broker allows hedging ?


No.

But when I perform expert testing in MetaTrader, it seems to assume that my broker does in fact allow this.

-Michael

Michael
19
Michael 2014.04.16 21:00  
angevoyageur:

Use OrderClose() with part of initial volume you want to close and the ticket number of the long order.

With MT4, a sell-stop (or any pending order) open a new trade.



I'm doing precisely that: Using OrderClose() with part of the lot size of the long trade.

A sell stop appears to open a new trade only when testing. If you open a long trade in EURUSD for 0.02 lots in live trading, and then place a sell-stop order for 0.01 a few pips below the current price for example, and that trade is triggered, then the OrderLots() for the long trade will no longer return 0.02 but 0.01, because that's how much volume is "left" on the trade. The sell-stop order doesn't appear anywhere in the user interface. However, when testing an expert, it seems the testing framework doesn't behave this way, rather it simply registers an opposing trade as if it is assuming that my broker allows hedging. How can I change this assumption to false? Seems like a strange assumption since the vast majority of brokers don't allow hedging.

Incidently (I should open a new topic for this I guess), how do you OrderSelect(ticket) and then see if that order is active or not? It seems as if partial sells will reduce the OrderLots() return value but only for the FIRST partial sell. The OrderCloseTime() will also begin returning a value greater than zero, even though the order technically is still open, even if only partially. I need some way to see if, for example, a long trade has been *fully* closed by some number of opposing sell-stop orders. I can't think of any way to achieve this.

-Michael

euclid
34
euclid 2014.04.17 18:01  
If your sell stop order becomes an open trade use OrderCloseBy to offset it against your long position. Then your code will work for both cases.
Alain Verleyen
Moderator
28652
Alain Verleyen 2014.04.19 12:22  
mberg2007:


I'm doing precisely that: Using OrderClose() with part of the lot size of the long trade.

A sell stop appears to open a new trade only when testing. If you open a long trade in EURUSD for 0.02 lots in live trading, and then place a sell-stop order for 0.01 a few pips below the current price for example, and that trade is triggered, then the OrderLots() for the long trade will no longer return 0.02 but 0.01, because that's how much volume is "left" on the trade. The sell-stop order doesn't appear anywhere in the user interface. However, when testing an expert, it seems the testing framework doesn't behave this way, rather it simply registers an opposing trade as if it is assuming that my broker allows hedging. How can I change this assumption to false? Seems like a strange assumption since the vast majority of brokers don't allow hedging.

Incidently (I should open a new topic for this I guess), how do you OrderSelect(ticket) and then see if that order is active or not? It seems as if partial sells will reduce the OrderLots() return value but only for the FIRST partial sell. The OrderCloseTime() will also begin returning a value greater than zero, even though the order technically is still open, even if only partially. I need some way to see if, for example, a long trade has been *fully* closed by some number of opposing sell-stop orders. I can't think of any way to achieve this.

-Michael

You have to talk with your broker, they probably process your order in a special way as hedging is not allowed for them.
/
To add comments, please log in or register