Simon28304
Simon28304

Reputation: 1

How to handle multiple take profits in pinescript V5 (Tradingview strategy)

I am messing around with a tradingview strategy written in pinescript v5. I want to implement a multiple take profit strategy. The strategy works fine but not 100% as I want.

I have this exit logic for short:

strategy.exit("S-TP-1","short" ,limit=short_tp_1,qty_percent = 10,comment = "TP1")
strategy.exit("S-TP-2","short" ,limit=short_tp_2,qty_percent = 10,comment = "TP2") 
strategy.exit("S-TP-3","short" ,limit=short_tp_3,qty_percent = 10,comment = "TP3") 
strategy.exit("S-TP-4","short" ,limit=short_tp_4,qty_percent = 10,comment = "TP4")
strategy.exit("S-TP-5","short" ,limit=short_tp_5,qty_percent = 10,comment = "TP5")
strategy.exit("SL-Short","short" , stop=short_sl,qty_percent = 100, comment="SL")

The problem:

The stop loss is hit and the strategy does not exit the full position. He only closes 50% of the position. It's because I use limit orders for the TPs with 10%.

Is there a way to cancel the limit orders if the stop loss is hit and sell the whole position?

Here you can see the problem:

Upvotes: 0

Views: 840

Answers (1)

Chris
Chris

Reputation: 1

Remove qty_percent = 100 from the last strategy.exit, then everything from the position "short" is exited.

Upvotes: 0

Related Questions