OPEN-SOURCE SCRIPT

Smart Pattern Predictor

158
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org/MPL/2.0/
// © payattentionjay

//version=6
strategy("Smart Whale Pattern Predictor", overlay=true)

// === PARAMETERS ===
lengthEMA = input(50, title="EMA Length")
lengthVWAP = input(20, title="VWAP Length")
rsiLength = input(14, title="RSI Length")
macdShort = input(12, title="MACD Short EMA")
macdLong = input(26, title="MACD Long EMA")
macdSignal = input(9, title="MACD Signal Length")
whaleVolumeMultiplier = input(2.5, title="Whale Volume Multiplier")

// === INDICATORS ===
// Trend Confirmation
emaTrend = ta.ema(close, lengthEMA)
vwapTrend = ta.vwap(close)

// Momentum & Overbought/Oversold Levels
rsiValue = ta.rsi(close, rsiLength)
macdLine = ta.ema(close, macdShort) - ta.ema(close, macdLong)
macdSignalLine = ta.ema(macdLine, macdSignal)
macdHistogram = macdLine - macdSignalLine

// Whale Activity Detection (Unusual Volume Spikes)
avgVolume = ta.sma(volume, 20)
whaleTrade = volume > (avgVolume * whaleVolumeMultiplier)

// === CHART PATTERN DETECTION ===
// Head & Shoulders Detection
leftShoulder = ta.highest(high, 20)[20]
head = ta.highest(high, 10)[10]
rightShoulder = ta.highest(high, 20)

headAndShoulders = leftShoulder < head and rightShoulder < head and leftShoulder > rightShoulder

// Double Top & Double Bottom Detection
doubleTop = ta.highest(high, 20) == ta.highest(high, 40)[20] and close < ta.highest(high, 20)
doubleBottom = ta.lowest(low, 20) == ta.lowest(low, 40)[20] and close > ta.lowest(low, 20)

// Triangle Patterns (Ascending & Descending)
ascendingTriangle = ta.highest(high, 20) > ta.highest(high, 40)[20] and ta.lowest(low, 20) > ta.lowest(low, 40)[20]
descendingTriangle = ta.highest(high, 20) < ta.highest(high, 40)[20] and ta.lowest(low, 20) < ta.lowest(low, 40)[20]

// Future Price Prediction Based on Pattern Breakout
futureUpMove = headAndShoulders == false and (doubleBottom or ascendingTriangle)
futureDownMove = headAndShoulders or doubleTop or descendingTriangle

// === ENTRY & EXIT CONDITIONS ===
// Buy Conditions
longCondition = ta.crossover(close, emaTrend) and rsiValue < 50 and macdLine > macdSignalLine and whaleTrade and futureUpMove
if (longCondition)
strategy.entry("Long", strategy.long)

// Sell Conditions
shortCondition = ta.crossunder(close, emaTrend) and rsiValue > 50 and macdLine < macdSignalLine and whaleTrade and futureDownMove
if (shortCondition)
strategy.entry("Short", strategy.short)

// === PLOT CHART PATTERNS ===
plotshape(headAndShoulders, location=location.abovebar, color=color.red, style=shape.triangleup, title="Head & Shoulders Detected")
plotshape(doubleTop, location=location.abovebar, color=color.orange, style=shape.triangleup, title="Double Top Detected")
plotshape(doubleBottom, location=location.belowbar, color=color.green, style=shape.triangledown, title="Double Bottom Detected")
plotshape(ascendingTriangle, location=location.abovebar, color=color.blue, style=shape.triangleup, title="Ascending Triangle Detected")
plotshape(descendingTriangle, location=location.belowbar, color=color.purple, style=shape.triangledown, title="Descending Triangle Detected")

// === PLOT TREND INDICATORS ===
plot(emaTrend, color=color.blue, title="EMA 50")
plot(vwapTrend, color=color.orange, title="VWAP")

// === ALERT SYSTEM ===
alertcondition(longCondition, title="Buy Alert", message="BUY SIGNAL: Strong entry detected with pattern breakout!")
alertcondition(shortCondition, title="Sell Alert", message="SELL SIGNAL: Downtrend detected with pattern breakdown!")

// === END OF SCRIPT ===

คำจำกัดสิทธิ์ความรับผิดชอบ

ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน