Hello guys, I am working on a custom indicator based on moving averages and I need a little help getting rid of unwanted signals. Basically what I need is a way for the indicator to print only the first arrow(signal) when a trend is changing direction. Thank you so much for any help in advanced.
Ruby:
#Upper Line
input numDevUp = 0.10;
input numDevDn = -0.10;
input priceup = close;
input lengthup = 3;
input AverageType = AverageType.EXPONENTIAL;
def uptmp1 = if priceup > priceup[1] then priceup - priceup[1] else 0;
def uptmp2 = if priceup[1] > priceup then priceup[1] - priceup else 0;
def upd2 = sum(uptmp1, lengthup);
def upd4 = sum(uptmp2, lengthup);
def upcond = upd2 + upd4 == 0;
def upad3 = if upcond then 0 else (upd2 - upd4) / (upd2 + upd4) * 100;
def upcoeff = 2 / (lengthup + 1) * AbsValue(upad3) / 100;
def upasd = compoundValue("visible data" = upcoeff * priceup + (if IsNaN(upasd[1]) then 0 else upasd[1]) * (1 - upcoeff), "historical data" = priceup
);
plot VMAUP = MovingAverage (AverageType, upasd + numDevUp, LengthUP);
VMAUP.setDefaultColor(GetColor(5));
#Lower Line
input pricedn = close;
input lengthdn = 3;
def dntmp1 = if pricedn > pricedn[1] then pricedn - pricedn[1] else 0;
def dntmp2 = if pricedn[1] > pricedn then pricedn[1] - pricedn else 0;
def dnd2 = sum(dntmp1, lengthdn);
def dnd4 = sum(dntmp2, lengthdn);
def dncond = dnd2 + dnd4 == 0;
def dnad3 = if dncond then 0 else (dnd2 - dnd4) / (dnd2 + dnd4) * 100;
def dncoeff = 2 / (lengthdn + 1) * AbsValue(dnad3) / 100;
def dnasd = compoundValue("visible data" = dncoeff * pricedn + (if IsNaN(dnasd[1]) then 0 else dnasd[1]) * (1 - dncoeff), "historical data" = pricedn
);
plot VMADN = MovingAverage (AverageType, dnasd + NumDevDn, LengthDN);
VMADN.setDefaultColor(GetColor(6));
#Center Signal Trigger
input priceT = close;
input lengthT = 1;
def Ttmp1 = if priceT > priceT[1] then priceT - priceT[1] else 0;
def Ttmp2 = if priceT[1] > priceT then priceT[1] - priceT else 0;
def Td2 = sum(Ttmp1, lengthT);
def Td4 = sum(Ttmp2, lengthT);
def Tcond = Td2 + Td4 == 0;
def Tad3 = if Tcond then 0 else (Td2 - Td4) / (Td2 + Td4) * 100;
def Tcoeff = 2 / (lengthT + 1) * AbsValue(Tad3) / 100;
def Tasd = compoundValue("visible data" = Tcoeff * priceT + (if IsNaN(Tasd[1]) then 0 else Tasd[1]) * (1 - Tcoeff), "historical data" = priceT
);
plot VMAT = Tasd;
VMAT.setDefaultColor(GetColor(3));
# Signal
input showBreakoutSignals = no;
plot UpSignal = VMAT crosses above VMAUP;
plot DownSignal = VMAT crosses below VMADN;
UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
# Alerts
input Alert = yes;
Alert(UpSignal and alert, "Buy", Alert.Bar, Sound.Ding);
Alert (DownSignal and alert, "Sell", Alert.Bar, Sound.Ding);
Last edited by a moderator: