Here is my conversion of the Supertrend with the EMA tradingview indicator
but there is an error in line 17 th
Thank you in advance.
https://www.tradingview.com/script/xEtpZd0t/
but there is an error in line 17 th
Thank you in advance.
https://www.tradingview.com/script/xEtpZd0t/
Code:
# Supertrend with EMA
input EmaPer = 4;
input TrPer = 7;
input factor = 1.7;
def ema = ExpAverage(close, EmaPer);
def atrValue = ATR(TrPer);
def up = ema - (factor * atrValue);
def down = ema + (factor * atrValue);
def TUp = if ema[1] > TUp[1] then Max(up, TUp[1]) else up;
def TDown = if ema[1] < TDown[1] then Min(down, TDown[1]) else down;
def Trend = if ema > TDown[1] then 1 else if ema < TUp[1] then -1 else if IsNaN(Trend[1]) then 1 else Trend[1];
def Trailingsl = if Trend == 1 then TUp else TDown;
AssignValueColor(if Trend == 1 then Color.GREEN else Color.RED);
plot Supertrend = Trailingsl;
Supertrend.AssignValueColor(if Trend == 1 then Color.GREEN else Color.RED);
Supertrend.SetLineWeight(2);
plot UpArrow = if Trend == 1 and Trend[1] == -1 then low else Double.NaN;
UpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpArrow.SetDefaultColor(Color.BLUE);
UpArrow.SetLineWeight(3);
plot DownArrow = if Trend == -1 and Trend[1] == 1 then high else Double.NaN;
DownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownArrow.SetDefaultColor(Color.BLACK);
DownArrow.SetLineWeight(3);
Last edited by a moderator: