0

i want to create a pine script in trading view for a moving average crossover between a EMA of length 5 and SMMA (Smoothed Moving Average) of length 7

I was able to create for the 5 EMA but couldnt find how to input the smoothed moving average(SMMA). I was only able to input SImple moving Average (SMA) and not SMMA

2 Answers2

0

Smoothed Moving Average (SMMA) is included in the Bullit-in script library enter image description here

This:

//@version=5
indicator(title="Smoothed Moving Average", shorttitle="SMMA", overlay=true, timeframe="", timeframe_gaps=true)
len = input.int(7, minval=1, title="Length")
src = input(close, title="Source")
smma = 0.0
smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len
plot(smma, color=#673AB7)

Here are recommendations on how to adapt a Bullit-in script https://www.tradingview.com/script/J8kODTBn-Adapting-a-built-in-PineCoders/

Gu5tavo71
  • 706
  • 1
  • 4
  • 11
0

this one and give feedback:

//@version=5
indicator("EMA and SMMA Crossover", overlay=true)

// Define EMA and SMMA
ema = ta.ema(close, 5)
smma = ta.sma(close, 7)

// Check for crossover
cross = ta.crossover(ema, smma)

// Plot EMA and SMMA
plot(ema, color=color.blue, linewidth=2, title="EMA")
plot(smma, color=color.red, linewidth=2, title="SMMA")

// Mark crossover events with up arrow
plotshape(cross, style=shape.arrowup, location=location.belowbar, color=color.green, size=size.small)
  • 1
    Your reply doesn't answer Ranjith's question, the script you posted is using the Simple Moving Average(SMA) instead of Smoothed Moving Average(SMMA). – e2e4 Mar 06 '23 at 10:35