Simple Pull Back Strategy Pinescript Code
Simple Pull Back Strategy Pinescript Code
// Check filter(s)
f_dateFilter = time >= i_startTime and time <= i_endTime
//uptrend
int upema1=0
int upema2=0
int upema3=0
for i = 1 to 5
if ma1 > ma1[i]
upema1 += 1
if ma2 > ma2[i]
upema2 += 1
if ma3 > ma3[i]
upema3 += 1
// Check buy/sell conditions
var float buyPrice = 0
buyCondition =close > ma1 and close < ma2 and upema1>= 5 and ma2 > ma1//and strategy.position_size == 0
and f_dateFilter
sellCondition = close >ma2 and strategy.position_size > 0 and (not i_lowerClose or close < low[1])
stopDistance = strategy.position_size > 0 ? ((buyPrice - close) / close) : na
stopPrice = strategy.position_size > 0 ? buyPrice - (buyPrice * i_stopPercent) : na
stopCondition = strategy.position_size > 0 and stopDistance > i_stopPercent
// Enter positions
if buyCondition
strategy.entry(id="Long", direction=strategy.long)
if buyCondition[1]
buyPrice := open
// Exit positions
if sellCondition or stopCondition
strategy.close(id="Long", comment="Exit" + (stopCondition ? "SL=true" : ""))
buyPrice := na