//@version=5 strategy(title="Simple Pullback Strategy", overlay=true, initial_capital=50000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.cash_per_contract, commission_value=0.005) // Get user input i_ma1 = input.int(title="MA 1 Length", defval=200, step=10, group="Strategy Parameters", tooltip="Long-term MA") i_ma2 = input.int(title="MA 2 Length", defval=10, step=10, group="Strategy Parameters", tooltip="Short-term MA") i_stopPercent = input.float(title="Stop Loss Persent", defval=0.10, step=0.1, group="Strategy Parameters", tooltip="Failsafe Stop Loss Persent Decline") i_lowerClose = input.bool(title="Exit on Lower Close", defval=false, group="Strategy Parameters", tooltip="Wait for a lower-close before exiting") i_startTime = input.time(title="Start Filter", defval=timestamp("01 Jan 1995 13:30 +0000"), group="Time Filter") i_endTime = input.time(title="End Filter", defval=timestamp("01 Jan 2099 13:30 +0000"), group="Time Filter") //Get indicator values ma1 = ta.sma(close, i_ma1) ma2 = ta.sma(close, i_ma2) // Check filter(s) f_dateFilter = time >= i_startTime and time <= i_endTime // check buy/sell conditions var float buyPrice = 0 buyCondition = close > ma1 and close < ma2 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 // Draw pretty colors plot(buyPrice, color=color.lime, style=plot.style_linebr) plot(stopPrice, color=color.green, style=plot.style_linebr, offset=-1) plot(ma1, color=color.blue) plot(ma2, color=color.red) plot(close)