Reputation: 23
I have TP and SL based on ATR value at entry moment. I have pyramiding option turned on, but then, all open at specific time trades (that are in the same direction: long or short) close at the same moment, all together. How to make every trade independent and how to make every trade being closed on a set at entry TP or SL.
Ps. TP = 2ATR, SL = 1ATR
Ps 2. Pine script version5
Similar problem here: Pyramiding trades with independent take profit (Pinescript)
My code for Long trades:
ATR = ta.atr(14)
if EntryLongCondiction1 and EntryLongCondiction2
strategy.entry("Long", strategy.long)
lastLongEntryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)
var float LongProfit = na
var float LongStop = na
if (strategy.position_size[1] != strategy.position_size)
LongProfit := lastLongEntryPrice + (ATR * 2)
LongStop := lastLongEntryPrice - (ATR * 1)
strategy.exit("Long", stop=LongStop, limit=LongProfit)
Upvotes: 0
Views: 778
Reputation: 9
Because all the entry and exit conditions are the same name in "Long"
, the entry might not be in the same place, but exit will. ATR will hit and trigger the exit condition with all names with "Long"
order. If you got a different condition or fixed tp/sl ratio, try naming it like Long 1
, Long2
, etc.
Upvotes: 1