Dear MC Team
I have been trying to solve this issue in a strategy, but i seem to look in the wrong places.
The use case is as follows:
I open a trade via a market order and use a stop loss. I need to know if the trade was closed "normally" - via the strategy itself, or if the stop has been hit.
The things I tried so far:
Use GenerateStopLoss()
Use a normal stop order
Look at the list of closed trades to find out if the last one has been exited via a stop order (very cumbersome and seems way too complicated to be correct way).
So far I have had zero success, can please somebody help me and show how to get this information.
PS: I know about ITradeManager, but I need this functionality in backtest too
How to know if a stop order has been hit
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How to know if a stop order has been hit
Hello waldfee,
You can get the ExitOrder Name to distinguish between your stop order and GenerateStopLoss order.
Please refer to Strategy Performance article for more information.
You can get the ExitOrder Name to distinguish between your stop order and GenerateStopLoss order.
Please refer to Strategy Performance article for more information.
Re: How to know if a stop order has been hit
Thank you for your reply.
Unfortunately I still am not able to implement what I want to. Could you please provide an example strategy of the following simple logic:
1. The strategy wants to go long on every bar, but we want only one open position.
At the opening of the position a stop loss is sent with a stop price of entry price minus some points.
2. If a trade is open, do not go long again
3. If the stop loss is hit, a flag is set and the next time a long signal is generated, this flag is checked and no trade is initiated.
The expected result of a backtest of this strategy:
1 trade, which is a long trade, exited via a short stop order (stop loss)
This example would help me very much, I would be really delighted if you could provide it.
Unfortunately I still am not able to implement what I want to. Could you please provide an example strategy of the following simple logic:
1. The strategy wants to go long on every bar, but we want only one open position.
At the opening of the position a stop loss is sent with a stop price of entry price minus some points.
2. If a trade is open, do not go long again
3. If the stop loss is hit, a flag is set and the next time a long signal is generated, this flag is checked and no trade is initiated.
The expected result of a backtest of this strategy:
1 trade, which is a long trade, exited via a short stop order (stop loss)
This example would help me very much, I would be really delighted if you could provide it.
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: How to know if a stop order has been hit
Please provide the script you have created and describe what exactly does not work as you expect.