OPEN-SOURCE SCRIPT

Scalping Strategy2

595
//version=6
strategy("DOGE/USDT 5X Scalping Strategy", overlay=true, margin_long=20, margin_short=0)

// === Core Parameters ===
fastEMA = input.int(5, "Fast EMA Length", minval=1, maxval=20)
slowEMA = input.int(12, "Slow EMA Length", minval=2, maxval=50)
trendEMA = input.int(55, "Trend EMA Length", minval=10, maxval=200)
atrPeriod = input.int(14, "ATR Period", minval=1, maxval=50)
tradeInterval = input.int(72, "Minutes Between Trades", minval=1, maxval=1440)

// Risk Management
slMultiplier = input.float(1.5, "Stop-Loss (ATR Multiple)", minval=0.5, maxval=5.0, step=0.1)
tpMultiplier = input.float(1.2, "Take-Profit (ATR Multiple)", minval=0.5, maxval=10.0, step=0.1)
riskPct = input.float(1.0, "Risk Per Trade (%)", minval=0.1, maxval=10.0, step=0.1)
leverage = 5.0 // Fixed 5x leverage

// === Calculate Indicators ===
fastLine = ta.ema(close, fastEMA)
slowLine = ta.ema(close, slowEMA)
trendLine = ta.ema(close, trendEMA)
atrValue = ta.atr(atrPeriod)
rsiValue = ta.rsi(close, 14)

// === Visualize Indicators ===
plot(fastLine, "Fast EMA", color=#2196F3, linewidth=2)
plot(slowLine, "Slow EMA", color=#FF9800, linewidth=2)
plot(trendLine, "Trend EMA", color=#757575, linewidth=1)

// Cross detection for visualization
crossUp = ta.crossover(fastLine, slowLine)
crossDown = ta.crossunder(fastLine, slowLine)
plotshape(crossUp, "EMA Cross Up", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(crossDown, "EMA Cross Down", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)

// === Trade Logic ===
var int lastTradeBarIndex = 0
timeElapsed = (bar_index - lastTradeBarIndex) >= tradeInterval
noActivePosition = strategy.position_size == 0

// Enhanced Entry Conditions - 80%+ win rate optimizations
emaCross = ta.crossover(fastLine, slowLine)
trendFilter = close > trendLine
priceStrength = close > open and close > close[1] // Strong bullish momentum
rsiFilter = rsiValue > 40 and rsiValue < 68 // Avoid overbought conditions

validEntry = emaCross and trendFilter and timeElapsed and noActivePosition and priceStrength and rsiFilter

// Position sizing calculation
equity = strategy.equity
riskAmount = equity * (riskPct / 100)
stopDistance = atrValue * slMultiplier
positionSize = math.round((riskAmount / stopDistance) * leverage)

// === Strategy Execution ===
if (validEntry)
strategy.entry("Long", strategy.long, qty=positionSize)
stopPrice = close - (atrValue * slMultiplier)
targetPrice = close + (atrValue * tpMultiplier)
strategy.exit("Exit", "Long", stop=stopPrice, limit=targetPrice)
lastTradeBarIndex := bar_index
line.new(bar_index, stopPrice, bar_index+20, stopPrice, color=color.red, width=1)
line.new(bar_index, targetPrice, bar_index+20, targetPrice, color=color.green, width=1)

// Early Exit Logic
inTrade = strategy.position_size > 0
if (inTrade and rsiValue > 75) // Take profit early if RSI gets too high
strategy.close("Long", comment="RSI Exit")

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.