0
votes

I have a cosmetic question regarding PineScript. I'm trying to figure out why I can't draw a continuous line of an indicator. I did this in the past with Stochs, and it worked without gaps, but I can't figure out why it won't work here. Here's a minimal example.

study(title="Directional Movement Index", shorttitle="DMI", format=format.price, precision=4)
lensig = input(title="ADX Smoothing", defval=14, minval=1, maxval=50)
len = input(title="DI Length", defval=14, minval=1)
[diplus, diminus, adx] = dmi(len, lensig)

adxStronger = adx[1] <= adx
adxWeaker = adx[1] >= adx
plot(adxStronger ? adx : na, color=#2196f3, title="ADX Stronger", style=plot.style_linebr, linewidth=2)
plot(adxWeaker ? adx : na, color=#2196f3, title="ADX Weaker", style=plot.style_linebr, linewidth=1)

This code produces breaks in the ADX line. I think because the values from one bar to the next do not end exactly where they start off again, and therefore produce this gap, but I've seen other indicators do this, and I'm wondering how they did it. Do I have to give up on the idea, and just plot the ADX normally once, and then paint over the ADX values that I want different?

Also, is there a way to "group" the two ADX settings in the appearance menu somehow, so they are show in a group, rather than separate? I couldn't find in the documentation about this, or on Kodify.

Thank you.

enter image description here

1

1 Answers

1
votes

Plot all the time, but make the color conditional:

//@version=4
study(title="Directional Movement Index", shorttitle="DMI", format=format.price, precision=4)
lensig = input(title="ADX Smoothing", defval=14, minval=1, maxval=50)
len = input(title="DI Length", defval=14, minval=1)
[diplus, diminus, adx] = dmi(len, lensig)

adxStronger = adx[1] <= adx
adxWeaker = adx[1] >= adx
plot(adx, color=adxStronger ? #2196f3 : na, title="ADX Stronger", linewidth=2)
plot(adx, color=adxWeaker   ? #2196f3 : na, title="ADX Weaker",   linewidth=1)

enter image description here