OPEN-SOURCE SCRIPT

Scalping Strategy

//version=5
strategy("Scalping Strategy", overlay=true)

// EMA settings
emaShort = ta.ema(close, 9)
emaLong = ta.ema(close, 21)

// RSI settings
rsi = ta.rsi(close, 14)
rsiOversold = 30
rsiOverbought = 70

// Entry conditions
longCondition = ta.crossover(emaShort, emaLong) and rsi < rsiOversold
shortCondition = ta.crossunder(emaShort, emaLong) and rsi > rsiOverbought

// Exit conditions
exitLongCondition = ta.crossunder(emaShort, emaLong) or rsi > rsiOverbought
exitShortCondition = ta.crossover(emaShort, emaLong) or rsi < rsiOversold

// Risk management: stop loss and take profit
stopLossPercent = 0.003 // 0.3% of the entry price
takeProfitPercent = 0.006 // 0.6% of the entry price

// Long trade setup
if (longCondition)
strategy.entry("Buy", strategy.long)
strategy.exit("Exit Buy", "Buy", stop=close * (1 - stopLossPercent), limit=close * (1 + takeProfitPercent))

// Short trade setup
if (shortCondition)
strategy.entry("Sell", strategy.short)
strategy.exit("Exit Sell", "Sell", stop=close * (1 + stopLossPercent), limit=close * (1 - takeProfitPercent))

// Plot EMAs on the chart for visual reference
plot(emaShort, title="9 EMA", color=color.green, linewidth=2)
plot(emaLong, title="21 EMA", color=color.red, linewidth=2)
Moving AveragesPine utilitiesTrend Analysis

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer