Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124

// =========================
// input
// =========================
fastEMA = input.int(50, “EMA fast”, minval=1)
SlowEMA = input.int(200, “EMA Slow”, minval=1)
rsiLen = input.int(14, “RSI length”, minval=1)
rsiBuyLevel = input.int(35, “RSI Buy Level”, minval=1, maxval=100)
rsiSellLevel = input.int(65, “RSI sell level”, minval=1, maxval=100)
ivotLen = input.int(5, “Pivot length”, minval=2)
srLookback = input.int(80, “S/R Lookback Bars”, minval=10)
useVolume = input.bool(true, “Use volume filter”)
volLen = input.int(20, “Volume SMA length”, minval=1)
useSession = input.bool(false, “Use session filter”)
sessionInput = input.session(“0900-1800”, “Trading Session”)
slBufferTicks = input.int(2, “SL buffer (ticks)”, minval=0)
rrTarget = input.float(1.5, “Risk return target”, minval=0.5, step=0.1)
showSignals = input.bool(true, “Show buy/sell labels”)
showSR = input.bool(true, “Show support/resistance”)
// =========================
// Core indicators
// =========================
emaFast = ta.ema(off, fastEMA)
emaSlow = ta.ema(Close, SlowEMA)
rsiVal = ta.rsi(off, rsiLen)
volSma = ta.sma(volume, volLen)
plot(emaFast, title=”EMA 50″, linewidth = 2)
plot(emaSlow, title=”EMA 200″, linewidth = 2)
// =========================
// trend
// =========================
bullTrend = emaFast > emaSlow
Bear trend = emaFast < emaSlow
// =========================
// session filter
// =========================
inSession = not na(time(timeframe.period, sessionInput))
session OK = use session? in session: true
// =========================
// volume filter
// =========================
volume OK = use volume? Volume > volSma : true
// =========================
// automatic support/resistance from pivot
// =========================
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var float final resistance = na
var float finally supports = na
if not na(ph)
Final resistance:= ph
if not na(pl)
Last support := pl
plot(showSR?lastResistance:na,”resistance”,style=plot.style_linebr,linewidth=2)
Figure(showSR?lastSupport:na,”support”,style=plot.style_linebr,linewidth=2)
// =========================
// Price action confirmation
// =========================
bullishCandle = closing price > opening price and closing price > closing price(1)
bearishCandle = closing price < opening price and closing price < closing price(1)
// EMA hits or near support/resistance
touchEMAForBuy = lowest price <= emaFast 且收盘价 >=emaFast
touchEMAForSell = Highest price >= emaFast and closing price <= emaFast
closeSupport = not na(lastSupport) and math.abs(close – lastSupport) <= ta.atr(14) * 0.25
closeResistance = not na(lastResistance) and math.abs(close – lastResistance) <= ta.atr(14) * 0.25
// RSI reversal
rsiBuySignal = rsiVal <= rsiBuyLevel or ta.crossover(rsiVal, rsiBuyLevel)
rsiSellSignal = rsiVal >= rsiSellLevel or ta.crossunder(rsiVal, rsiSellLevel)
// =========================
// Entry conditions
// =========================
long condition=
bull trend and
Session OK and
Volume Determination and
(touch EMAForBuy or nearSupport) and
rsiBuySignal and
bullish candle
short condition=
bear trend and
Session OK and
Volume Determination and
(touching EMAForSell or nearResistance) and
rsiSell signal and
bearish candle
// =========================
// risk management
// =========================
tick size = syminfo.mintick
longSL = math.min(low, nz(lastSupport, low)) – (slBufferTicks * tickSize)
ShortSL = math.max(high, nz(lastResistance, high)) + (slBufferTicks * tickSize)
Long risk = close position – long stop loss
Short risk = Short SL – Close position
longTP = close position + (longRisk * rrTarget)
ShortTP = close position – (shortRisk * rrTarget)
// =========================
// Order
// =========================
If longCondition and strategy.position_size <= 0 且longRisk > 0
strategy.entry(“buy”, strategy.long)
Strategy.exit(“Buy Take Profit/Stop Loss”, from_entry=”Buy”, stop=longSL, limit=longTP)
If shortCondition and strategy.position_size >= 0 and shortRisk > 0
strategy.entry(“sell”, strategy.short)
Strategy.exit(“Sell Take Profit/Stop Loss”, from_entry=”Sell”, stop=shortSL, limit=shortTP)
// =========================
// visual signal
// =========================
plotshape(showSignals and longCondition, title=”Buy Signal”, style=shape.labelup, location=location.belowbar, text=”BUY”, size=size.tiny)
plotshape(showSignals and shortCondition, title=”Sell Signal”, style=shape.labeldown, location=location.abovebar, text=”Sell”, size=size.tiny)
// =========================
// alert
// =========================
Alertcondition(longCondition, title=”Buy Alert”, message=”Buy signal on {{ticker}} @ {{close}}”)
Alertcondition(shortCondition, title=”Sell Alert”, message=”Sell signal on {{ticker}} @ {{close}}”)