Arrow position on lower study

G

GGC

New member
I would like to get some help on position arrows in a lower study. I was able to insert arrows in the Aroon Oscillator when the oscillator crosses the overbought level (up or down) or the oversold level (up or down). Unfortunately the arrows show up in the upper part of the study window (see code below). Can anyone help me position the arrows near the oscillator line or the overbought/oversold levels?

Thanks in advance!
Code:
declare lower;

input length = 25;

Assert(length > 0, "'length' must be positive: " + length);

def aroonUp = reference AroonIndicator(length = length).Up;
def aroonDown = reference AroonIndicator(length = length).Down;

plot UpDownDiff = aroonUp - aroonDown;
plot OverBought = 50;
plot MiddleLine = 0;
plot OverSold = -50;

UpDownDiff.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(8));
MiddleLine.SetDefaultColor(GetColor(8));
OverSold.SetDefaultColor(GetColor(8));

plot crossing = crosses(UpDownDiff,OverBought) and UpDownDiff >= OverBought;
crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot ccrossing = crosses(UpDownDiff,OverBought) and UpDownDiff <= OverBought;
ccrossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot cccrossing = crosses(UpDownDiff,OverSold) and UpDownDiff >= OverSold;
cccrossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot ccccrossing = crosses(UpDownDiff,OverSold) and UpDownDiff <= OverSold;
ccccrossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
 
P

Pensar

Active member
VIP
@GGC - I believe this code positions the arrows in the appropriate spots - if not, let me know. :)

Code:
#Aroon Oscillator with Crossing Signals
#Aroon Oscillator code by TD Ameritrade IP Company, Inc. (c) 2007-2020
#Added arrows when the AO crosses Oversold and Overbought levels

declare lower;

input length = 25;

Assert(length > 0, "'length' must be positive: " + length);

def aroonUp = reference AroonIndicator(length = length).Up;
def aroonDown = reference AroonIndicator(length = length).Down;

plot UpDownDiff = aroonUp - aroonDown;
plot OverBought = 50;
plot MiddleLine = 0;
plot OverSold = -50;

UpDownDiff.SetDefaultColor(GetColor(1));
OverBought.SetDefaultColor(GetColor(8));
MiddleLine.SetDefaultColor(GetColor(8));
OverSold.SetDefaultColor(GetColor(8));

#arrow signals
plot ArrowUpLow = if UpDownDiff[1] < OverSold and Updowndiff >= OverSold  
               then OverSold else double.nan;
     ArrowUpLow.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     ArrowUpLow.SetDefaultColor(color.green);
     ArrowUpLow.SetLineWeight(3);

plot ArrowUpHigh = if UpDownDiff[1] < OverBought and Updowndiff >= OverBought  
               then OverBought else double.nan;
     ArrowUpHigh.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     ArrowUpHigh.SetDefaultColor(color.green);
     ArrowUpHigh.SetLineWeight(3);

plot ArrowDnHigh = if UpDownDiff[1] > OverBought and Updowndiff <= OverBought
               then OverBought else double.nan;
     ArrowDnHigh.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     ArrowDnHigh.SetDefaultColor(color.red);
     ArrowDnHigh.SetLineWeight(3);

plot ArrowDnLow = if UpDownDiff[1] > OverSold and Updowndiff <= OverSold
               then OverSold else double.nan;
     ArrowDnLow.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     ArrowDnLow.SetDefaultColor(color.red);
     ArrowDnLow.SetLineWeight(3);

#End of code
 
G

GGC

New member
Code:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#

declare lower;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;

def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;

def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
smi.setDefaultColor(getColor(1));

plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));

plot overbought = over_bought;
overbought.setDefaultColor(getcolor(5));

plot oversold = over_sold;
oversold.setDefaultColor(getcolor(5));

plot crossing = crosses(SMI,AVGSMI) and SMI >= AVGSMI;
crossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot ccrossing = crosses(AVGSMI,SMI) and SMI <= AVGSMI;
ccrossing.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Any chance you could help me do the same thing on the study above? It is Stochastic momentum index and I would like to have a down arrow is SMI crosses below AVGSMI (with the crossing happening above the overbought line), and an up arrow if SMI crosses above AVGSMI (with the crossing happening below the oversold line). Thanks :)
 
P

Pensar

Active member
VIP
Sure, here you go. Please verify that the crossing signals are plotting where you want.

Code:
# Stochastic Momentum Index
# Base code by TD Ameritrade IP Company, Inc. (c) 2008-2020
# Added arrows and alerts when SMI/AvgSMI cross above/below the oversold/overbought lines

declare lower;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;

def min_low = lowest(low, percentKLength);
def max_high = highest(high, percentKLength);
def rel_diff = close - (max_high + min_low)/2;
def diff = max_high - min_low;

def avgrel = expaverage(expaverage(rel_diff, percentDLength), percentDLength);
def avgdiff = expaverage(expaverage(diff, percentDLength), percentDLength);

plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
smi.setDefaultColor(getColor(1));

plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));

plot overbought = over_bought;
overbought.setDefaultColor(getcolor(5));

plot oversold = over_sold;
oversold.setDefaultColor(getcolor(5));

def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;

plot arrowUp = if signalUp then AvgSMI else double.nan;
     arrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     arrowUp.SetDefaultColor(color.green);

plot arrowDn = if signalDn then AvgSMI else double.nan;
     arrowDn.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     arrowDn.SetDefaultColor(color.red);

Alert(alerts and signalUp, " Arrow Up! ", alert.bar, sound.ring);
Alert(alerts and signalDn, " Arrow Down! ", alert.bar, sound.ring);

#end code

Edit: Modified code to add alerts for the arrow signals.
 
Last edited:

Similar threads

Top