I'm trying to program 3 take profit targets in a pine strategy.
In the below code, when the condition to go long is triggered, an entry is opened with a quantity of 100. This works fine. The values for valueTakeProfit1, 2 and 3 are also correct. But once I put them into a strategy.exit(), they are or not triggered or the profits are taking at wrong levels. The values for variables ATR1/2/3percent are not percentages, it's just the amount taken from the 100 which are opened via the strategy.entry().
if(longCondition or re_entryCondition)
alertLine := 1
strategy.entry(id="Long Entry", long=true, when=alertLine==1, qty=100)
valueTakeProfit1 := close+ATR1*ma_function(tr(true), lengthATR)
valueTakeProfit2 := close+ATR2*ma_function(tr(true), lengthATR)
valueTakeProfit3 := close+ATR3*ma_function(tr(true), lengthATR)
strategy.exit("Take Profit 1 Long", from_entry="Long Entry", limit=valueTakeProfit1, qty=ATR1percent)
strategy.exit("Take Profit 2 Long", from_entry="Long Entry", limit=valueTakeProfit2, qty=ATR2percent)
strategy.exit("Take Profit 3 Long", from_entry="Long Entry", limit=valueTakeProfit3, qty=ATR3percent)
//End long positions
if(longCloseCondition)
strategy.close(id="Long Entry")
Can someone help me out how I should define multiple take profit levels?