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")
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.