INVITE-ONLY SCRIPT

MandarKalgutkar-Buy/Sell Arrow Signal

51
//version=5
indicator("MandarKalgutkar-Buy/Sell Arrow Signal", overlay=true)

ma = ta.sma(close, 21)
rsi = ta.rsi(close, 14)

// Tracking variables
var float buyRefHigh = na
var float sellRefLow = na
var int buyCandleIndex = na
var int sellCandleIndex = na

// Detect initial breakout candle
bullishBreak = close > open and close > ma and close[1] < ma[1]
if bullishBreak
buyRefHigh := high
buyCandleIndex := bar_index

bearishBreak = close < open and close < ma and close[1] > ma[1]
if bearishBreak
sellRefLow := low
sellCandleIndex := bar_index

// Next candle only: ensure current bar is exactly next one
isNextBuyBar = (not na(buyCandleIndex)) and bar_index == buyCandleIndex + 1
isNextSellBar = (not na(sellCandleIndex)) and bar_index == sellCandleIndex + 1

// Buy/sell logic
buySignal = isNextBuyBar and high > buyRefHigh and rsi > 55
sellSignal = isNextSellBar and low < sellRefLow and rsi < 45

// Reset if signal used or next candle missed
if buySignal or isNextBuyBar
buyRefHigh := na
buyCandleIndex := na

if sellSignal or isNextSellBar
sellRefLow := na
sellCandleIndex := na

// Plot
plotshape(buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, size=size.small)
plotshape(sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, size=size.small)

plot(ma, "20 MA", color.orange)

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.