Add arrows for DMI indicator

FOTM_8888

Member
VIP
I need help with this indicator, i will like to plot a green arrow for long and red arrow for short, can someone here can help me .. the arrow will be great on the signal candle. here is the script. thank you in advance.

Code:
declare lower;

input length = 10;
input paintBars = yes;
input averageType = AverageType.WILDERS;

def diPlus = DMI(length, averageType)."DI+";
def diMinus = DMI(length, averageType)."DI-";

plot Osc = diPlus - diMinus;
plot Hist = Osc;
plot ZeroLine = 0;

Osc.SetDefaultColor(GetColor(1));
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.DefineColor("Positive", Color.UPTICK);
Hist.DefineColor("Negative", Color.DOWNTICK);
Hist.AssignValueColor(if Hist > 0 then Hist.Color("Positive") else Hist.Color("Negative"));
Hist.HideTitle();
ZeroLine.SetDefaultColor(Color.GRAY);

DefineGlobalColor("Positive", Color.UPTICK);
DefineGlobalColor("Negative", Color.DOWNTICK);
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if Osc > 0
        then GlobalColor("Positive")
        else GlobalColor("Negative"));

Osc.assignValueColor(
         if Osc > 0 then color.dark_green
    else if Osc < 0 then color.dark_red
    else color.black);
 

MerryDay

Administrative
Staff member
Staff
VIP
Is this what you are looking for?

aaa2.png


Code:
#Add these lines to the end of your script:

plot greenarrow = if  Osc crosses above 0 then ZeroLine else Double.NaN;
greenarrow.SetDefaultColor(color.green);
greenarrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
greenarrow.SetLineWeight(2);
greenarrow.HideBubble() ;
greenarrow.HideTitle() ;

plot redarrow = if Osc crosses below 0 then ZeroLine else double.NaN ;
redarrow.SetDefaultColor(Color.red);
redarrow.SetLineWeight(2);
redarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
redarrow.HideBubble() ;
redarrow.HideTitle() ;
 

FOTM_8888

Member
VIP
thank you some much for your reply, that is was I am looking for, but the arrow is plotting in the lower indicator, i will like the arrow to plot in the price charts, meaning in the upper . thank you very much.
 

MerryDay

Administrative
Staff member
Staff
VIP
@FOTM_8888 To post a lower indicator in an upper chart with just the arrows; requires that all plots except the arrows be changed to 'def' and the arrows which currently print on the zeroline of the histogram to be modified to print above/below the candles in the upper chart.

Here is the script w/ the changes:

Code:
input length = 10;
input paintBars = yes;
input averageType = AverageType.WILDERS;

def diPlus = DMI(length, averageType)."DI+";
def diMinus = DMI(length, averageType)."DI-";

def Osc = diPlus - diMinus;
def Hist = Osc;
def ZeroLine = 0;

DefineGlobalColor("Positive", Color.UPTICK);
DefineGlobalColor("Negative", Color.DOWNTICK);
AssignPriceColor(if !paintBars
    then Color.CURRENT
    else if Osc > 0
        then GlobalColor("Positive")
        else GlobalColor("Negative"));

# This plots arrows at 30% of bar range above the bar high/low
def prange = high – low;
def plotHigh = high + prange * 0.3;
def plotLow  = low  - prange * 0.3;

plot greenarrow = if  Osc crosses above 0 then plotLow else Double.NaN;
greenarrow.SetDefaultColor(color.green);
greenarrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
greenarrow.SetLineWeight(2);
greenarrow.HideBubble() ;
greenarrow.HideTitle() ;

plot redarrow = if Osc crosses below 0 then plotHigh else double.NaN ;
redarrow.SetDefaultColor(Color.red);
redarrow.SetLineWeight(2);
redarrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
redarrow.HideBubble() ;
redarrow.HideTitle() ;

aaa2.png
 

Similar threads

Top