Smart Grid Scalping(Pullback) Strategy[BullByte]

BullByte · strategy · 60 行 · 点赞 1,259 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
strategy("Smart Grid Scalping (Pullback) Strategy[BullByte]", overlay=true, shorttitle="SGS Scalping")
 
// ===== Input Parameters =====
atrLength    = input(10, title="ATR Length")             // ATR period for volatility measurement
gridFactor   = input(0.2, title="Grid Factor")             // Multiplier to determine grid spacing based on ATR
profitTarget = input(0.002, title="Profit Target (0.1% = 0.001)")
noTradeZone  = input(0.005, title="No Trade Zone (%)")     // Defines a price range where trades are avoided
 
// ===== ATR Calculation =====
atrValue = ta.atr(atrLength)
 
// ===== Grid Level Calculation =====
gridLevels = array.new_float(15)  // Create an array to hold 15 grid levels
for i = 0 to 14
    array.set(gridLevels, i, close + (i + 1) * atrValue * gridFactor)
 
// ===== Plot Grid Levels =====
for i = 0 to 14
    line.new(bar_index[1], array.get(gridLevels, i), bar_index, array.get(gridLevels, i), color=color.new(color.green, 0), width=1)
 
// ===== Trading Logic =====
// Additional RSI filter for extra confirmation
rsiValue = ta.rsi(close, 14)
 
// Conditions for entry:
// - Long: Price is below the first grid level, volatility is above the no trade zone, and RSI indicates oversold (<30).
// - Short: Price is above the last grid level, volatility is above the no trade zone, and RSI indicates overbought (>70).
longCondition  = close < array.get(gridLevels, 0) and (high - low) / low > noTradeZone and rsiValue < 30
shortCondition = close > array.get(gridLevels, 14) and (high - low) / high > noTradeZone and rsiValue > 70
 
if (longCondition)
    strategy.entry("Long", strategy.long)
 
if (shortCondition)
    strategy.entry("Short", strategy.short)
 
// ===== Take Profit with Trailing Stop Logic =====
if (strategy.position_size > 0)
    strategy.exit("Take Profit", "Long", 
                  limit=close * (1 + profitTarget), 
                  trail_price=close * (1 + profitTarget * 0.5), 
                  trail_offset=atrValue)
 
if (strategy.position_size < 0)
    strategy.exit("Take Profit", "Short", 
                  limit=close * (1 - profitTarget), 
                  trail_price=close * (1 - profitTarget * 0.5), 
                  trail_offset=atrValue)
 
// ===== Plot Trade Entry Labels =====
// Plot labels only on the bar where the position is initiated
longEntry  = strategy.position_size > 0 and (strategy.position_size[1] <= 0)
shortEntry = strategy.position_size < 0 and (strategy.position_size[1] >= 0)
 
plotshape(longEntry, location=location.belowbar, 
     color=color.new(color.green, 0), style=shape.labelup, text="LONG", textcolor=color.white, size=size.normal)
 
plotshape(shortEntry, location=location.abovebar, 
     color=color.new(color.red, 0), style=shape.labeldown, text="SHORT", textcolor=color.white, size=size.normal)

← 返回列表