Reputation: 319
my exit strategy is simple:
here is my code,
strategy.entry("Enter Long")
strategy.exit("stop", stop=stopPrice)
strategy.exit("profit 1", entry_name="Enter Long", profit=10, qty_percent=50)
strategy.exit("profit 2", entry_name="Enter Long", profit=20)
I found the exits of "stop" and "profit" can't work together. If I put "stop" exit before "profit 1", the "profit 1" not working. If I put "stop" exit to the end, the "stop" exit not working.
Some one says "stop" and "profit" can be written into one strategy.exit
, like
strategy.exit("profit 1", entry_name="Enter Long", profit=10, qty_percent=50, stop=stopPrice)
Stop exit is working but it just exits 50% position size. I need to exit all position when stop loss.
How to write the correct exit?
Upvotes: 1
Views: 410
Reputation: 319
sorry, I made a mistake. If I put the "stop" exit at the end, the "stop" worked but only exit 50% position rather than total position. I guess the reason is there is "profit 1" exit. So I add "stop" to the "profit" exits too. Finally it becomes,
strategy.entry("Enter Long")
strategy.exit("profit 1", entry_name="Enter Long", profit=10, qty_percent=50, stop=stopPrice) // add stop
strategy.exit("profit 2", entry_name="Enter Long", profit=20, stop=stopPrice) // add stop
strategy.exit("stop", stop=stopPrice)
It works. But there is another problem that it orders twice when stop loss. One is triggered by "profit 1" exit, another is triggered by "stop" exit, each is 50% position, which means I failed two orders, which make the "success rate" or "win rate" of strategy be down.
Upvotes: 0