3ema Strategy
3ema Strategy
0 at
https://mozilla.org/MPL/2.0/
// © mattmediawg
//@version=5
strategy("3EMA Scalper Strategy", overlay=true)
// Calculate RANGE
rangeSMA = ta.sma(close, rangeMultiplier)
// 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)
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")