OPEN-SOURCE SCRIPT

Multi-SMA Strategy - Core Signals

Tick-Precise Cross Detection:

Uses bar's high/low for real-time cross detection

Compares current price action with previous bar's position

Works across all timezones and trading sessions

Three-Layer Trend Filter:

Requires 50 > 100 > 200 SMA for uptrends

Requires 50 < 100 < 200 SMA for downtrends

Adds inherent market structure confirmation

Responsive Exit System:

Closes longs when price breaks below 20 SMA

Closes shorts when price breaks above 20 SMA

Uses same tick-precise logic as entries

Universal Time Application:

No fixed time references

Pure price-based calculations

Works on any chart timeframe (1m - monthly)

Signal Logic Summary:

+ Long Entry: Tick cross above 50 SMA + Uptrend hierarchy
- Long Exit: Price closes below 20 SMA
+ Short Entry: Tick cross below 50 SMA + Downtrend hierarchy
- Short Exit: Price closes above 20 SMA



Komut
//version=5
strategy("Multi-SMA Strategy - Core Signals", overlay=true)

// ———— Universal Inputs ———— //
int smaPeriod1 = input(20, "Fast SMA")
int smaPeriod2 = input(50, "Medium SMA")
bool useTickCross = input(true, "Use Tick-Precise Crosses")

// ———— Timezone-Neutral Calculations ———— //
sma20 = ta.sma(close, smaPeriod1)
sma50 = ta.sma(close, smaPeriod2)
sma100 = ta.sma(close, 100)
sma200 = ta.sma(close, 200)

// ———— Tick-Precise Cross Detection ———— //
golden_cross = useTickCross ?
(high >= sma50 and low[1] < sma50[1]) :
ta.crossover(sma20, sma50)

death_cross = useTickCross ?
(low <= sma50 and high[1] > sma50[1]) :
ta.crossunder(sma20, sma50)

// ———— Trend Filter ———— //
uptrend = sma50 > sma100 and sma100 > sma200
downtrend = sma50 < sma100 and sma100 < sma200

// ———— Entry Conditions ———— //
longCondition = golden_cross and uptrend
shortCondition = death_cross and downtrend

// ———— Exit Conditions ———— //
exitLong = ta.crossunder(low, sma20)
exitShort = ta.crossover(high, sma20)

// ———— Strategy Execution ———— //
strategy.entry("Long", strategy.long, when=longCondition)
strategy.entry("Short", strategy.short, when=shortCondition)
strategy.close("Long", when=exitLong)
strategy.close("Short", when=exitShort)

// ———— Clean Visualization ———— //
plot(sma20, "20 SMA", color.new(color.blue, 0))
plot(sma50, "50 SMA", color.new(color.red, 0))
plot(sma100, "100 SMA", color.new(#B000B0, 0), linewidth=2)
plot(sma200, "200 SMA", color.new(color.green, 0), linewidth=2)

// ———— Signal Markers ———— //
plotshape(longCondition, "Long Entry", shape.triangleup, location.belowbar, color.green, 0)
plotshape(shortCondition, "Short Entry", shape.triangledown, location.abovebar, color.red, 0)
plotshape(exitLong, "Long Exit", shape.xcross, location.abovebar, color.blue, 0)
plotshape(exitShort, "Short Exit", shape.xcross, location.belowbar, color.orange, 0)

Disclaimer