0% found this document useful (0 votes)
23 views5 pages

AI Smart Trading Indicator Script

Uploaded by

pencarihal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views5 pages

AI Smart Trading Indicator Script

Uploaded by

pencarihal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

//@version=5

indicator("🤖 AI Smart Trading Indicator", shorttitle="AI-STI", overlay=true,


max_bars_back=500)

// === INPUT PARAMETERS ===


ai_sensitivity = [Link](14, "AI Sensitivity", minval=5, maxval=50, group="AI Settings")
ml_lookback = [Link](50, "ML Lookback Period", minval=20, maxval=200, group="AI
Settings")
volatility_filter = [Link](true, "Enable Volatility Filter", group="Filters")
volume_confirmation = [Link](true, "Volume Confirmation", group="Filters")
show_signals = [Link](true, "Show Buy/Sell Signals", group="Display")
show_zones = [Link](true, "Show Support/Resistance Zones", group="Display")
alert_enabled = [Link](true, "Enable Alerts", group="Alerts")

// === AI MACHINE LEARNING FUNCTIONS ===


// Adaptive moving average with AI weighting
ai_adaptive_ma(src, length) =>
alpha = 2.0 / (length + 1.0)
var float ai_ma = na
volatility_weight = [Link](14) / [Link]([Link](14), 50)
momentum_weight = [Link](src, 14) / 50.0
adaptive_alpha = alpha * (volatility_weight + momentum_weight) / 2.0
ai_ma := na(ai_ma) ? src : ai_ma + adaptive_alpha * (src - ai_ma)
ai_ma

// Multi-timeframe trend detection


get_trend_strength() =>
// RSI-based trend
rsi = [Link](close, 14)
rsi_trend = rsi > 50 ? 1 : rsi < 50 ? -1 : 0

// MACD trend
[macd_line, signal_line, _] = [Link](close, 12, 26, 9)
macd_trend = macd_line > signal_line ? 1 : -1

// Price vs MA trend
ma_trend = close > [Link](close, 20) ? 1 : -1

// Combine trends
total_trend = (rsi_trend + macd_trend + ma_trend) / 3.0
total_trend

// Volume-Price analysis
volume_price_analysis() =>
vol_ma = [Link](volume, 20)
price_change = [Link](close)
vol_ratio = volume / vol_ma
// Volume confirmation logic
strong_vol = vol_ratio > 1.5
bullish_vol = strong_vol and price_change > 0
bearish_vol = strong_vol and price_change < 0

[bullish_vol, bearish_vol, vol_ratio]

// AI Pattern Recognition
pattern_recognition() =>
// Detect potential reversal patterns
hammer = (low < open and low < close) and (high - [Link](open, close)) <
([Link](open, close) - low) * 0.3
shooting_star = (high > open and high > close) and ([Link](open, close) - low) < (high -
[Link](open, close)) * 0.3
doji = [Link](open - close) < (high - low) * 0.1

// Engulfing patterns
bullish_engulfing = close[1] < open[1] and close > open and close > open[1] and open <
close[1]
bearish_engulfing = close[1] > open[1] and close < open and close < open[1] and open >
close[1]

[hammer, shooting_star, doji, bullish_engulfing, bearish_engulfing]

// === MAIN AI CALCULATIONS ===


ai_ma = ai_adaptive_ma(close, ai_sensitivity)
trend_strength = get_trend_strength()
[bull_vol, bear_vol, vol_ratio] = volume_price_analysis()
[hammer, shooting_star, doji, bull_engulf, bear_engulf] = pattern_recognition()

// Advanced momentum oscillator


momentum_rsi = [Link](close, 14)
momentum_stoch = [Link](close, high, low, 14)
combined_momentum = (momentum_rsi + momentum_stoch) / 2

// Volatility-adjusted signals
atr = [Link](20)
volatility_percentile = (atr - [Link](atr, 100)) / ([Link](atr, 100) - [Link](atr, 100)) *
100

// === AI SIGNAL GENERATION ===


// Buy conditions
ai_buy_condition = trend_strength > 0.3 and
close > ai_ma and
combined_momentum < 30 and
(not volume_confirmation or bull_vol) and
(not volatility_filter or volatility_percentile < 80) and
(bull_engulf or hammer)

// Sell conditions
ai_sell_condition = trend_strength < -0.3 and
close < ai_ma and
combined_momentum > 70 and
(not volume_confirmation or bear_vol) and
(not volatility_filter or volatility_percentile < 80) and
(bear_engulf or shooting_star)

// Signal filtering to reduce noise


var float last_buy_bar = na
var float last_sell_bar = na

buy_signal = ai_buy_condition and (na(last_buy_bar) or bar_index - last_buy_bar > 10)


sell_signal = ai_sell_condition and (na(last_sell_bar) or bar_index - last_sell_bar > 10)

if buy_signal
last_buy_bar := bar_index
if sell_signal
last_sell_bar := bar_index

// === SUPPORT/RESISTANCE ZONES ===


// Dynamic S/R calculation
var float support_level = na
var float resistance_level = na

if trend_strength > 0.5


support_level := [Link](low, 20)
resistance_level := [Link](high, 20)
else if trend_strength < -0.5
support_level := [Link](low, 20)
resistance_level := [Link](high, 20)

// === VISUAL ELEMENTS ===


// Plot AI moving average
plot(ai_ma, "AI Adaptive MA", color=trend_strength > 0 ? [Link] : [Link],
linewidth=2)

// Plot support/resistance zones


plot(show_zones and not na(support_level) ? support_level : na, "Support",
color=[Link]([Link], 70), linewidth=1, style=plot.style_linebr)
plot(show_zones and not na(resistance_level) ? resistance_level : na, "Resistance",
color=[Link]([Link], 70), linewidth=1, style=plot.style_linebr)

// Color candles based on AI sentiment


barcolor(trend_strength > 0.3 ? [Link]([Link], 60) :
trend_strength < -0.3 ? [Link]([Link], 60) :
[Link]([Link], 80))

// Plot buy/sell signals


plotshape(show_signals and buy_signal, "Buy Signal", [Link], [Link],
color=[Link]([Link], 0), textcolor=[Link], text="AI BUY", size=[Link])
plotshape(show_signals and sell_signal, "Sell Signal", [Link], [Link],
color=[Link]([Link], 0), textcolor=[Link], text="AI SELL", size=[Link])

// === DASHBOARD ===


var table info_table = [Link](position.top_right, 3, 6, bgcolor=[Link]([Link], 80),
border_width=1)

if [Link]
// AI Status
ai_status = trend_strength > 0.3 ? "🟢 BULLISH" : trend_strength < -0.3 ? "🔴 BEARISH" : "🟡
NEUTRAL"
[Link](info_table, 0, 0, "AI Status", text_color=[Link], text_size=[Link])
[Link](info_table, 1, 0, ai_status, text_color=[Link], text_size=[Link])

// Trend Strength
[Link](info_table, 0, 1, "Trend Power", text_color=[Link], text_size=[Link])
[Link](info_table, 1, 1, [Link]([Link](trend_strength * 100)) + "%",
text_color=[Link], text_size=[Link])

// Momentum
[Link](info_table, 0, 2, "Momentum", text_color=[Link], text_size=[Link])
momentum_status = combined_momentum > 70 ? "Overbought" : combined_momentum
< 30 ? "Oversold" : "Neutral"
[Link](info_table, 1, 2, momentum_status, text_color=[Link], text_size=[Link])

// Volume
[Link](info_table, 0, 3, "Volume", text_color=[Link], text_size=[Link])
vol_status = vol_ratio > 1.5 ? "High" : vol_ratio > 1.0 ? "Normal" : "Low"
[Link](info_table, 1, 3, vol_status, text_color=[Link], text_size=[Link])

// Volatility
[Link](info_table, 0, 4, "Volatility", text_color=[Link], text_size=[Link])
vol_status_txt = volatility_percentile > 80 ? "Very High" : volatility_percentile > 60 ? "High"
: "Normal"
[Link](info_table, 1, 4, vol_status_txt, text_color=[Link], text_size=[Link])

// === ALERTS ===


if alert_enabled and buy_signal
alert("🤖 AI BUY SIGNAL: " + [Link] + " @ " + [Link](close, "#.##") +
"\nTrend: " + [Link]([Link](trend_strength * 100)) + "%" +
"\nMomentum: " + [Link]([Link](combined_momentum)) +
"\nVolume: " + [Link]([Link](vol_ratio, 2)), alert.freq_once_per_bar)

if alert_enabled and sell_signal


alert("🤖 AI SELL SIGNAL: " + [Link] + " @ " + [Link](close, "#.##") +
"\nTrend: " + [Link]([Link](trend_strength * 100)) + "%" +
"\nMomentum: " + [Link]([Link](combined_momentum)) +
"\nVolume: " + [Link]([Link](vol_ratio, 2)), alert.freq_once_per_bar)

You might also like