Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Logic while in positions
- if strategy.position_size > 0
- trade_entry_price := strategy.opentrades.entry_price(0)
- longStopPrice := trade_entry_price * (1 - longSL)
- longTakePrice := trade_entry_price * (1 + longTP)
- strategy.exit("Exit", from_entry = "LONG", stop = longStopPrice, comment = "Long Stop Loss " + str.tostring(longStopPrice) + " / " + str.tostring(trade_entry_price))
- if trail_longTP == 0.0
- if high > longTakePrice
- trail_longTP := high * (1 - longTO)
- strategy.exit("Exit", "LONG", stop = trail_longTP, comment = "Long Trail TP Hit, on first calc")
- else
- if (high * (1 - longTO)) > trail_longTP
- b_long_to_tp_set := true
- trail_longTP := high * (1 - longTO)
- strategy.exit("Exit", "LONG", stop = trail_longTP, comment = "Long Trail TP Hit, on calc")
- else if high[1] > high or close < trail_longTP
- strategy.exit("Exit", "LONG", stop = trail_longTP, comment = "Long Trail TP Hit, close < TO")
- else if strategy.position_size < 0
- trade_entry_price := strategy.opentrades.entry_price(0)
- shortStopPrice := trade_entry_price * (1 + shortSL)
- shortTakePrice := trade_entry_price * (1 - shortTP)
- strategy.exit("Exit", from_entry = "SHORT", stop = shortStopPrice, comment = "Short Stop Loss " + str.tostring(shortStopPrice) + " / " + str.tostring(trade_entry_price))
- if trail_shortTP == 0.0
- if low < shortTakePrice
- trail_shortTP := low * (1 + shortTO)
- strategy.exit("Exit", from_entry = "SHORT", stop = trail_shortTP, comment = "Short Trail TP Hit, on first calc")
- else
- if low < low[1] and (low * (1 + shortTO)) < trail_shortTP
- trail_shortTP := low * (1 + shortTO)
- b_short_to_tp_set := false
- strategy.exit("Exit", from_entry = "SHORT", stop = trail_shortTP, comment = "Short Trail TP Hit, on calc")
- else if low[1] < low or close > trail_shortTP
- strategy.exit("Exit", from_entry = "SHORT", stop = trail_shortTP, comment = "Short Trail TP Hit, close > TP")
- else if strategy.position_size == 0
- trail_shortTP := 0.0
- trail_longTP := 0.0
- shortStopPrice := 0.0
- longStopPrice := 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement