OPEN-SOURCE SCRIPT
✅ FIXED Strategy + Predictive Range

//version=5
strategy("✅ FIXED Strategy + Predictive Range", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === INPUTS ===
emaFastLen = input.int(5, "Fast EMA")
emaSlowLen = input.int(10, "Slow EMA")
useVolume = input.bool(true, "Use Volume Filter?")
volPeriod = input.int(20, "Volume SMA")
useMACD = input.bool(true, "Use MACD Confirmation?")
macdFast = input.int(12, "MACD Fast")
macdSlow = input.int(26, "MACD Slow")
macdSignal = input.int(9, "MACD Signal")
useUTBot = input.bool(true, "Use UT Bot?")
atrPeriod = input.int(10, "ATR Period")
atrFactor = input.float(1.0, "ATR Factor")
useRange = input.bool(true, "Use First 15-min Range Breakout?")
slPoints = input.int(10, "Stop Loss (Points)")
tpPoints = input.int(20, "Take Profit (Points)")
// === EMA Calculation ===
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
plot(emaFast, color=color.orange)
plot(emaSlow, color=color.blue)
emaBull = ta.crossover(emaFast, emaSlow)
emaBear = ta.crossunder(emaFast, emaSlow)
// === Volume Filter ===
volOk = not useVolume or (volume > ta.sma(volume, volPeriod))
// === MACD ===
[macdLine, macdSig, _] = ta.macd(close, macdFast, macdSlow, macdSignal)
macdOkLong = not useMACD or macdLine > macdSig
macdOkShort = not useMACD or macdLine < macdSig
// === UT Bot (ATR Based) ===
atr = ta.atr(atrPeriod)
upper = high + atrFactor * atr
lower = low - atrFactor * atr
utBuy = ta.crossover(close, upper)
utSell = ta.crossunder(close, lower)
utOkLong = not useUTBot or utBuy
utOkShort = not useUTBot or utSell
// === Predictive Range Logic ===
var float morningHigh = na
var float morningLow = na
isNewDay = ta.change(time("D"))
var bool rangeCaptured = false
if isNewDay
morningHigh := na
morningLow := na
rangeCaptured := false
inFirst15 = (hour == 9 and minute < 30)
if inFirst15 and not rangeCaptured
morningHigh := na(morningHigh) ? high : math.max(morningHigh, high)
morningLow := na(morningLow) ? low : math.min(morningLow, low)
rangeCaptured := true
plot(useRange and not na(morningHigh) ? morningHigh : na, "Range High", color=color.green)
plot(useRange and not na(morningLow) ? morningLow : na, "Range Low", color=color.red)
rangeOkLong = not useRange or close > morningHigh
rangeOkShort = not useRange or close < morningLow
// === Final Conditions ===
longCond = emaBull and volOk and macdOkLong and utOkLong and rangeOkLong
shortCond = emaBear and volOk and macdOkShort and utOkShort and rangeOkShort
// === Entry/Exit ===
if longCond
strategy.entry("BUY", strategy.long)
if shortCond
strategy.entry("SELL", strategy.short)
strategy.exit("TP/SL Long", from_entry="BUY", stop=close - slPoints, limit=close + tpPoints)
strategy.exit("TP/SL Short", from_entry="SELL", stop=close + slPoints, limit=close - tpPoints)
// === Plot Arrows ===
plotshape(longCond, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortCond, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === Alerts ===
alertcondition(longCond, title="BUY Alert", message="BUY Signal Triggered")
alertcondition(shortCond, title="SELL Alert", message="SELL Signal Triggered")
strategy("✅ FIXED Strategy + Predictive Range", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === INPUTS ===
emaFastLen = input.int(5, "Fast EMA")
emaSlowLen = input.int(10, "Slow EMA")
useVolume = input.bool(true, "Use Volume Filter?")
volPeriod = input.int(20, "Volume SMA")
useMACD = input.bool(true, "Use MACD Confirmation?")
macdFast = input.int(12, "MACD Fast")
macdSlow = input.int(26, "MACD Slow")
macdSignal = input.int(9, "MACD Signal")
useUTBot = input.bool(true, "Use UT Bot?")
atrPeriod = input.int(10, "ATR Period")
atrFactor = input.float(1.0, "ATR Factor")
useRange = input.bool(true, "Use First 15-min Range Breakout?")
slPoints = input.int(10, "Stop Loss (Points)")
tpPoints = input.int(20, "Take Profit (Points)")
// === EMA Calculation ===
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
plot(emaFast, color=color.orange)
plot(emaSlow, color=color.blue)
emaBull = ta.crossover(emaFast, emaSlow)
emaBear = ta.crossunder(emaFast, emaSlow)
// === Volume Filter ===
volOk = not useVolume or (volume > ta.sma(volume, volPeriod))
// === MACD ===
[macdLine, macdSig, _] = ta.macd(close, macdFast, macdSlow, macdSignal)
macdOkLong = not useMACD or macdLine > macdSig
macdOkShort = not useMACD or macdLine < macdSig
// === UT Bot (ATR Based) ===
atr = ta.atr(atrPeriod)
upper = high + atrFactor * atr
lower = low - atrFactor * atr
utBuy = ta.crossover(close, upper)
utSell = ta.crossunder(close, lower)
utOkLong = not useUTBot or utBuy
utOkShort = not useUTBot or utSell
// === Predictive Range Logic ===
var float morningHigh = na
var float morningLow = na
isNewDay = ta.change(time("D"))
var bool rangeCaptured = false
if isNewDay
morningHigh := na
morningLow := na
rangeCaptured := false
inFirst15 = (hour == 9 and minute < 30)
if inFirst15 and not rangeCaptured
morningHigh := na(morningHigh) ? high : math.max(morningHigh, high)
morningLow := na(morningLow) ? low : math.min(morningLow, low)
rangeCaptured := true
plot(useRange and not na(morningHigh) ? morningHigh : na, "Range High", color=color.green)
plot(useRange and not na(morningLow) ? morningLow : na, "Range Low", color=color.red)
rangeOkLong = not useRange or close > morningHigh
rangeOkShort = not useRange or close < morningLow
// === Final Conditions ===
longCond = emaBull and volOk and macdOkLong and utOkLong and rangeOkLong
shortCond = emaBear and volOk and macdOkShort and utOkShort and rangeOkShort
// === Entry/Exit ===
if longCond
strategy.entry("BUY", strategy.long)
if shortCond
strategy.entry("SELL", strategy.short)
strategy.exit("TP/SL Long", from_entry="BUY", stop=close - slPoints, limit=close + tpPoints)
strategy.exit("TP/SL Short", from_entry="SELL", stop=close + slPoints, limit=close - tpPoints)
// === Plot Arrows ===
plotshape(longCond, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortCond, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === Alerts ===
alertcondition(longCond, title="BUY Alert", message="BUY Signal Triggered")
alertcondition(shortCond, title="SELL Alert", message="SELL Signal Triggered")
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。