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."
)
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.