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.
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
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
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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