// This source code is subject to the terms of the Mozilla Public License 2.
0 at
https://mozilla.org/MPL/2.0/
// © mattmediawg
//@version=5
strategy("3EMA Scalper Strategy", overlay=true)
// Input lengths for EMA, RSI, and ADX
length1 = input(8, "Length EMA 1")
length2 = input(35, "Length EMA 2")
length3 = input(212, "Length EMA 3")
rsiLength = input(14, "RSI Length")
rsiThreshold = input(50, "RSI Threshold") // Threshold for RSI to determine trend
clarity
overboughtLevel = input(70, "Overbought Level") // RSI level indicating overbought
condition
oversoldLevel = input(30, "Oversold Level") // RSI level indicating oversold
condition
rangeMultiplier = input(10, "Range Multiplier") // Multiplier for the RANGE
indicator
adxLength = input(14, "ADX Length") // ADX smoothing length
diLength = input(14, "DI Length") // DI length for ADX calculation
// Calculate RANGE
rangeSMA = ta.sma(close, rangeMultiplier)
// Calculate EMAs on RANGE
ema1 = ta.ema(rangeSMA, length1)
ema2 = ta.ema(rangeSMA, length2)
ema3 = ta.ema(rangeSMA, length3)
// Plot EMAs
plot(ema1, color=color.blue, linewidth=2, title="EMA 1")
plot(ema2, color=color.red, linewidth=2, title="EMA 2")
plot(ema3, color=color.green, linewidth=2, title="EMA 3")
// Plot RANGE
plot(rangeSMA, color=color.orange, linewidth=2, title="Range SMA")
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Calculate ADX
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
[plus, minus]
adx(dilen, adxlen) =>
[plus, minus] = dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adxValue = adx(diLength, adxLength)
var bool position_open = false
if strategy.position_size != 0
position_open := true
else if strategy.position_size == 0 and position_open
position_open := false
enterLong = ta.crossover(rangeSMA, ema3) and not position_open and rsi >
rsiThreshold and rsi < overboughtLevel and adxValue > 24
enterShort = ta.crossunder(rangeSMA, ema2) and not position_open and rsi <
rsiThreshold and rsi > oversoldLevel and adxValue > 23
// Variabili di uscita - Long
takeProfitLong = input.float(2.19, "Take Profit Long", step=0.01)
stopLossLong = input.float(0.92, "Stop Loss Long", step=0.01)
// Variabili di uscita - Short
takeProfitShort = input.float(1.28, "Take Profit Short", step=0.01)
stopLossShort = input.float(0.71, "Stop Loss Short", step=0.01)
// Variabili di uscita estreme
extremeStopLossLong = input.float(0.92, "Extreme Stop Loss Long", step=0.01)
extremeStopLossShort = input.float(0.71, "Extreme Stop Loss Short", step=0.01)
var float entryPriceLong = na
var float entryPriceShort = na
if enterLong
entryPriceLong := close
strategy.entry("Long", strategy.long)
if enterShort
entryPriceShort := close
strategy.entry("Short", strategy.short)
if strategy.position_size > 0
takeProfitLongValue = rangeSMA * (1 + takeProfitLong / 100)
stopLossLongValue = rangeSMA * (1 - stopLossLong / 100)
extremeStopLossLongValue = entryPriceLong * (1 - extremeStopLossLong / 100)
if close > takeProfitLongValue
strategy.close("Long", comment="Take Profit Long")
if close < stopLossLongValue
strategy.close("Long", comment="Stop Loss Long")
if close < extremeStopLossLongValue
strategy.close("Long", comment="Extreme Stop Loss Long")
if strategy.position_size < 0
takeProfitShortValue = rangeSMA * (1 - takeProfitShort / 100)
stopLossShortValue = rangeSMA * (1 + stopLossShort / 100)
extremeStopLossShortValue = entryPriceShort * (1 + extremeStopLossShort / 100)
if close < takeProfitShortValue
strategy.close("Short", comment="Take Profit Short")
if close > stopLossShortValue
strategy.close("Short", comment="Stop Loss Short")
if close > extremeStopLossShortValue
strategy.close("Short", comment="Extreme Stop Loss Short")
plot(adxValue, color=color.purple, title="ADX")