OPEN-SOURCE SCRIPT
Simple NIFTY Stochastic CE PE System PRAKASAN

//version=6
indicator(
title = "Simple NIFTY Stochastic CE PE System",
shorttitle = "Simple CE PE",
overlay = true
)
//--------------------------------------------------
// INPUTS
//--------------------------------------------------
stochLength = input.int(14, "Stochastic Length")
smoothK = input.int(3, "K Smoothing")
smoothD = input.int(3, "D Smoothing")
oversoldLevel = input.int(20, "Oversold Level")
overboughtLevel = input.int(80, "Overbought Level")
emaLength = input.int(20, "EMA Length")
useVWAP = input.bool(true, "Use VWAP Filter")
showEMA = input.bool(true, "Show EMA")
showVWAP = input.bool(true, "Show VWAP")
//--------------------------------------------------
// INDICATORS
//--------------------------------------------------
emaValue = ta.ema(close, emaLength)
vwapValue = ta.vwap(hlc3)
rawStoch = ta.stoch(close, high, low, stochLength)
stochK = ta.sma(rawStoch, smoothK)
stochD = ta.sma(stochK, smoothD)
//--------------------------------------------------
// TREND FILTER
//--------------------------------------------------
bullishTrend =
close > emaValue and
(not useVWAP or close > vwapValue)
bearishTrend =
close < emaValue and
(not useVWAP or close < vwapValue)
//--------------------------------------------------
// STOCHASTIC SIGNALS
//--------------------------------------------------
// Buy CE when Stochastic crosses upward from oversold
bullishSignal =
ta.crossover(stochK, stochD) and
stochK < 35 and
bullishTrend
// Buy PE when Stochastic crosses downward from overbought
bearishSignal =
ta.crossunder(stochK, stochD) and
stochK > 65 and
bearishTrend
//--------------------------------------------------
// TRADE STATE
//--------------------------------------------------
// 0 = waiting for CE
// 1 = CE active
// 2 = waiting for PE
// -1 = PE active
var int tradeState = 0
bool buyCE = false
bool exitCE = false
bool buyPE = false
bool exitPE = false
buyCE := false
exitCE := false
buyPE := false
exitPE := false
//--------------------------------------------------
// SIGNAL SEQUENCE
//--------------------------------------------------
// Step 1: Buy CE
if tradeState == 0 and bullishSignal
buyCE := true
tradeState := 1
// Step 2: Exit CE
if tradeState == 1 and bearishSignal
exitCE := true
tradeState := 2
// Step 3: Generate fresh Buy PE signal
else if tradeState == 2 and bearishSignal
buyPE := true
tradeState := -1
// Step 4: Exit PE
if tradeState == -1 and bullishSignal
exitPE := true
tradeState := 0
//--------------------------------------------------
// CHART SIGNALS
//--------------------------------------------------
plotshape(
buyCE,
title = "BUY CE",
text = "BUY CE",
style = shape.labelup,
location = location.belowbar,
color = color.green,
textcolor = color.white,
size = size.small
)
plotshape(
exitCE,
title = "EXIT CE",
text = "EXIT CE",
style = shape.labeldown,
location = location.abovebar,
color = color.orange,
textcolor = color.white,
size = size.small
)
plotshape(
buyPE,
title = "BUY PE",
text = "BUY PE",
style = shape.labeldown,
location = location.abovebar,
color = color.red,
textcolor = color.white,
size = size.small
)
plotshape(
exitPE,
title = "EXIT PE",
text = "EXIT PE",
style = shape.labelup,
location = location.belowbar,
color = color.blue,
textcolor = color.white,
size = size.small
)
//--------------------------------------------------
// INDICATOR LINES
//--------------------------------------------------
plot(
showEMA ? emaValue : na,
title = "EMA",
color = color.orange,
linewidth = 2
)
plot(
showVWAP ? vwapValue : na,
title = "VWAP",
color = color.purple,
linewidth = 2
)
//--------------------------------------------------
// ALERTS
//--------------------------------------------------
alertcondition(
buyCE,
title = "BUY CE Alert",
message = "BUY CE signal generated."
)
alertcondition(
exitCE,
title = "EXIT CE Alert",
message = "EXIT CE signal generated."
)
alertcondition(
buyPE,
title = "BUY PE Alert",
message = "BUY PE signal generated."
)
alertcondition(
exitPE,
title = "EXIT PE Alert",
message = "EXIT PE signal generated."
)
indicator(
title = "Simple NIFTY Stochastic CE PE System",
shorttitle = "Simple CE PE",
overlay = true
)
//--------------------------------------------------
// INPUTS
//--------------------------------------------------
stochLength = input.int(14, "Stochastic Length")
smoothK = input.int(3, "K Smoothing")
smoothD = input.int(3, "D Smoothing")
oversoldLevel = input.int(20, "Oversold Level")
overboughtLevel = input.int(80, "Overbought Level")
emaLength = input.int(20, "EMA Length")
useVWAP = input.bool(true, "Use VWAP Filter")
showEMA = input.bool(true, "Show EMA")
showVWAP = input.bool(true, "Show VWAP")
//--------------------------------------------------
// INDICATORS
//--------------------------------------------------
emaValue = ta.ema(close, emaLength)
vwapValue = ta.vwap(hlc3)
rawStoch = ta.stoch(close, high, low, stochLength)
stochK = ta.sma(rawStoch, smoothK)
stochD = ta.sma(stochK, smoothD)
//--------------------------------------------------
// TREND FILTER
//--------------------------------------------------
bullishTrend =
close > emaValue and
(not useVWAP or close > vwapValue)
bearishTrend =
close < emaValue and
(not useVWAP or close < vwapValue)
//--------------------------------------------------
// STOCHASTIC SIGNALS
//--------------------------------------------------
// Buy CE when Stochastic crosses upward from oversold
bullishSignal =
ta.crossover(stochK, stochD) and
stochK < 35 and
bullishTrend
// Buy PE when Stochastic crosses downward from overbought
bearishSignal =
ta.crossunder(stochK, stochD) and
stochK > 65 and
bearishTrend
//--------------------------------------------------
// TRADE STATE
//--------------------------------------------------
// 0 = waiting for CE
// 1 = CE active
// 2 = waiting for PE
// -1 = PE active
var int tradeState = 0
bool buyCE = false
bool exitCE = false
bool buyPE = false
bool exitPE = false
buyCE := false
exitCE := false
buyPE := false
exitPE := false
//--------------------------------------------------
// SIGNAL SEQUENCE
//--------------------------------------------------
// Step 1: Buy CE
if tradeState == 0 and bullishSignal
buyCE := true
tradeState := 1
// Step 2: Exit CE
if tradeState == 1 and bearishSignal
exitCE := true
tradeState := 2
// Step 3: Generate fresh Buy PE signal
else if tradeState == 2 and bearishSignal
buyPE := true
tradeState := -1
// Step 4: Exit PE
if tradeState == -1 and bullishSignal
exitPE := true
tradeState := 0
//--------------------------------------------------
// CHART SIGNALS
//--------------------------------------------------
plotshape(
buyCE,
title = "BUY CE",
text = "BUY CE",
style = shape.labelup,
location = location.belowbar,
color = color.green,
textcolor = color.white,
size = size.small
)
plotshape(
exitCE,
title = "EXIT CE",
text = "EXIT CE",
style = shape.labeldown,
location = location.abovebar,
color = color.orange,
textcolor = color.white,
size = size.small
)
plotshape(
buyPE,
title = "BUY PE",
text = "BUY PE",
style = shape.labeldown,
location = location.abovebar,
color = color.red,
textcolor = color.white,
size = size.small
)
plotshape(
exitPE,
title = "EXIT PE",
text = "EXIT PE",
style = shape.labelup,
location = location.belowbar,
color = color.blue,
textcolor = color.white,
size = size.small
)
//--------------------------------------------------
// INDICATOR LINES
//--------------------------------------------------
plot(
showEMA ? emaValue : na,
title = "EMA",
color = color.orange,
linewidth = 2
)
plot(
showVWAP ? vwapValue : na,
title = "VWAP",
color = color.purple,
linewidth = 2
)
//--------------------------------------------------
// ALERTS
//--------------------------------------------------
alertcondition(
buyCE,
title = "BUY CE Alert",
message = "BUY CE signal generated."
)
alertcondition(
exitCE,
title = "EXIT CE Alert",
message = "EXIT CE signal generated."
)
alertcondition(
buyPE,
title = "BUY PE Alert",
message = "BUY PE signal generated."
)
alertcondition(
exitPE,
title = "EXIT PE Alert",
message = "EXIT PE signal generated."
)
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.