本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("AI Volume Breakout for scalping", overlay=true)
// Parameters
var float volumeThreshold = 4.0 // Increased to 2.0 for more significant volume changes
var float priceChangeThreshold = 0.015 // Increased to 2% for more significant price changes
var int smaLength = 20 // Length of the Simple Moving Average for trend confirmation
var int cooldownPeriod = 10 // Number of bars to wait before another signal
var int atrPeriod = 14 // ATR period for volatility check
var float volatilityThreshold = 0.01 // If ATR is above this, market is too volatile
// Calculate SMA for trend confirmation
sma = ta.sma(close, smaLength)
atr = ta.atr(atrPeriod)
// Simulate ML prediction based on volume and price change
var float lastPrediction = na
var int barsSinceLastSignal = 0
// Check if we are past the cooldown period
if barsSinceLastSignal >= cooldownPeriod
volumeDelta = volume - volume[1]
priceDelta = close - open
// Trend Confirmation
trendUp = close > sma
trendDown = close < sma
// Volatility check
lowVolatility = atr / close < volatilityThreshold
// Here you would ideally get a prediction from your ML model
// For this example, we'll use a refined heuristic for volume breakout:
if volumeDelta > 0 and volume / volume[1] >= volumeThreshold and lowVolatility
if trendUp and priceDelta > 0 and math.abs(priceDelta / open) >= priceChangeThreshold
lastPrediction := 1 // Bullish
barsSinceLastSignal := 0
else if trendDown and priceDelta < 0 and math.abs(priceDelta / open) >= priceChangeThreshold
lastPrediction := 0 // Bearish
barsSinceLastSignal := 0
else
lastPrediction := na
else
lastPrediction := na
else
lastPrediction := na
// Increment the cooldown counter
barsSinceLastSignal := barsSinceLastSignal + 1
// Labels
if lastPrediction == 1
label.new(bar_index, low - (low * 0.005), text="Bullish Breakout", color=color.green, style=label.style_label_up, size=size.small)
if lastPrediction == 0
label.new(bar_index, high + (high * 0.005), text="Bearish Breakout", color=color.red, style=label.style_label_down, size=size.small)