Need help to create upper signals

zotz

New member
VIP
Hello all,

Anyone can help me to create upper signals (up/down arrows, etc) whenever the Avg line (Avg = Average(diff, smoothingLength) crosses the Zero line?
I'm not good with coding.

The code/indicator is below.
Btw, it's just the HeikinAshiDiff indicator in ToS.
Thank you!

Code:
##########
declare lower;

input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

plot HADiff = diff;
plot Avg = Average(diff, smoothingLength);
plot ZeroLine = 0;

HADiff.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
ZeroLine.SetDefaultColor(GetColor(5));
 

mfsteve

Member
VIP
Code:
plot ArrowUp = if Avg crosses above ZeroLine then (Avg - 1) else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowUp.SetLineWeight(2);
ArrowUp.HideBubble();

plot ArrowDn = if Avg crosses below ZeroLine then (Avg + 1) else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.YELLOW);
ArrowDn.SetLineWeight(2);
ArrowDn.HideBubble();

I used (Avg +1) and (Avg - 1) to move the arrows little ways from the lines.

xCocZ8d.jpg
 

BenTen

Administrative
Staff member
Staff
VIP
@zotz Here you go. I used the up and down arrows provided by @mfsteve

Code:
input smoothingLength = 3;

def haclose = (open + high + low + close) / 4;
def haopen = CompoundValue(1, (haopen[1] + haclose[1]) / 2, (open[1] + close[1]) / 2);
def diff = haclose - haopen;

def HADiff = diff;
def Avg = Average(diff, smoothingLength);
def ZeroLine = 0;

plot ArrowUp = if Avg crosses above ZeroLine then low else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowUp.SetLineWeight(2);
ArrowUp.HideBubble();

plot ArrowDn = if Avg crosses below ZeroLine then high else Double.NaN;
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDn.SetDefaultColor(Color.YELLOW);
ArrowDn.SetLineWeight(2);
ArrowDn.HideBubble();
 

Similar threads

Top