OPEN-SOURCE SCRIPT

Scalping Strategy - Liquidity, Volatility & Candlestick2

//version=5
strategy("Scalping Strategy - Liquidity, Volatility & Candlestick Patterns", overlay=true)

// --- Inputs ---
lengthATR = input.int(14, title="ATR Period")
multiplierATR = input.float(1.5, title="ATR Multiplier for Volatility")
lengthEMA = input.int(20, title="EMA Period")
lengthVolume = input.int(20, title="Volume Moving Average Period")
momentumThreshold = input.float(2.0, title="Momentum Threshold (News Catalysts)")

// --- Indicators ---
atr = ta.atr(lengthATR) // ATR for volatility
ema = ta.ema(close, lengthEMA) // EMA for trend
volMA = ta.sma(volume, lengthVolume) // Volume moving average

// --- Candlestick Pattern Detection (Manually Defined) ---
// Bullish Engulfing: Current close > current open and previous close < previous open and current close > previous open
bullishEngulfing = close > open and close[1] < open[1] and close > open[1] and open < close[1]

// Bearish Engulfing: Current close < current open and previous close > previous open and current close < previous open
bearishEngulfing = close < open and close[1] > open[1] and close < open[1] and open > close[1]

// Doji Pattern: Current close is within a small range of the open (doji condition)
doji = math.abs(close - open) < (high - low) * 0.1

// --- Trend Identification ---
uptrend = close > ema // Price above EMA = uptrend
downtrend = close < ema // Price below EMA = downtrend

// --- Volatility & Liquidity Analysis ---
highVolatility = atr * multiplierATR // Volatility condition
highVolume = volume > volMA * 1.5 // High volume for liquidity

// --- Triangle Pattern & Trendline Breakout (Simplified) ---
// Calculate recent highest and lowest closes for breakout detection
highestHigh = ta.highest(high, 3) // Highest high of the last 3 bars
lowestLow = ta.lowest(low, 3) // Lowest low of the last 3 bars

// Detect breakouts
triangleBreakoutUp = close > highestHigh // Breakout above the highest high
triangleBreakoutDown = close < lowestLow // Breakdown below the lowest low

// --- Momentum Catalysts (Simulated) ---
momentumBullish = highVolume and bullishEngulfing
momentumBearish = highVolume and bearishEngulfing

// --- Buy (Long Position) Conditions ---
longCondition = (uptrend and bullishEngulfing and highVolume and close > ema)
longMomentumCondition = (momentumBullish and highVolume and close > ema)

// --- Sell (Short Position) Conditions ---
shortCondition = (downtrend and bearishEngulfing and highVolume and close < ema)
shortMomentumCondition = (momentumBearish and highVolume and close < ema)

// --- Exit Conditions (Close Long and Short Positions) ---
sellLongCondition = (downtrend and bearishEngulfing and close < ema) // Exit long position
buyShortCondition = (uptrend and bullishEngulfing and close > ema) // Exit short position

// --- Plot Buy and Sell Signals ---
plotshape(series=longCondition, title="Long Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Short Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// --- Strategy Execution (Enter and Exit Trades) ---

// Enter Long Position
if longCondition
strategy.entry("Long", strategy.long)

// Enter Short Position
if shortCondition
strategy.entry("Short", strategy.short)

// Close positions at market price when exit conditions are met
if sellLongCondition
strategy.close("Long")

if buyShortCondition
strategy.close("Short")

// --- Plot Indicators for Reference ---
plot(ema, title="EMA", color=color.orange, linewidth=2)
plot(atr, title="ATR", color=color.blue, linewidth=2)
plot(volMA, title="Volume MA", color=color.purple, linewidth=2)
arshBill Williams IndicatorsCandlestick analysisChart patterns

开源脚本

本着真正的TradingView精神,此脚本的作者已将其开源,以便交易者可以理解和验证它。向作者致敬!您可以免费使用它,但在出版物中重复使用此代码受网站规则约束。 您可以收藏它以在图表上使用。

想在图表上使用此脚本?

免责声明