I'm working on backtesting a strategy. I need to simulate stop-limit order, stop-loss, and take-profit. Here's my understanding of these concepts:
Stop-limit order: You ask the broker to buy the security if its price is between the stop and limit price you specified.
Stop-loss: You ask the broker to sell the security if its price falls below the stop-loss price you defined.
Take-profit: You ask the broker to sell the security if its price goes above the take-profit price you defined.
Here are my assumptions for implementing these in a backtest:
On a specific date, if the High price is above the stop price and the Low price is below the limit price, buy the security with an 80% chance (I assume 20% for the cases where the price is in the desired range but for any reason, the order is not filled on that date by the broker).
On the same date that the stock is purchased or later if the High price is above the take-profit price, sell the security at the price of the take-profit limit price.
On the same date that the stock is purchased or later if the Low price is below the stop-loss price, sell the security at the price of the stop-loss price.
Since the order of executing (2) or (3) is important (i.e., checking for a profit on that date or loss on that date), 50% of the times I execute (2) first, and for the rest I execute (3) first.
I'm not sure how realistic are these assumptions for the purpose of the backtest. Note that small changes in this implementation could make a huge difference in the overall return of the strategy. Given this implementation, I find that it is more profitable if you give 10% of the price for stop-loss and 5% of the price for take-profit (which is against my expectation that take-profit should be 2X higher than stop-loss).