fnoor1 / trading

0 stars 0 forks source link

script #1

Open fnoor1 opened 1 year ago

fnoor1 commented 1 year ago

//@version=4 study("Swing Trading Strategy with Confirmation", shorttitle="STS", overlay=true)

// Input parameters rsiPeriod = input(14, title="RSI Period", type=input.integer) emaShort = input(9, title="EMA Short Period", type=input.integer) emaLong = input(21, title="EMA Long Period", type=input.integer) atrLength = input(14, title="ATR Length", type=input.integer) atrMultiplier = input(1.5, title="ATR Multiplier", type=input.float)

// Calculate RSI rsi = rsi(close, rsiPeriod)

// Calculate EMA ema_short = ema(close, emaShort) ema_long = ema(close, emaLong)

// Calculate ATR atr = atr(atrLength)

// Define engulfing pattern bullish_engulfing = close[1] > open[1] and open > close[1] and close > open[1] and close > open bearish_engulfing = close[1] < open[1] and open < close[1] and close < open[1] and close < open

// Entry conditions bullish = bullish_engulfing and close > ema_short and close > ema_long and rsi < 60 bearish = bearish_engulfing and close < ema_short and close < ema_long and rsi > 40

// Plot signals plotshape(bullish, title="Bullish Entry", location=location.belowbar, color=color.green, style=shape.triangleup, text="Call") plotshape(bearish, title="Bearish Entry", location=location.abovebar, color=color.red, style=shape.triangledown, text="Put")

// Plot EMA plot(ema_short, title="EMA Short", color=color.blue, linewidth=1, transp=70) plot(ema_long, title="EMA Long", color=color.red, linewidth=1, transp=70)

// Calculate and plot stop loss levels long_stop_loss = bullish ? close - atr atrMultiplier : na short_stop_loss = bearish ? close + atr atrMultiplier : na plot(long_stop_loss, title="Long Stop Loss", color=color.red, linewidth=1, style=plot.style_linebr) plot(short_stop_loss, title="Short Stop Loss", color=color.green, linewidth=1, style=plot.style_linebr)