How to Write Pine Script for Adx Above 25?

How to Write Pine Script for Adx Above 25?

I have ema crossover strategy but i want my order to execute only when adx is above 25. I tried doing it in trading view using pinecript but it fails. So, i need pine script which execute only when adx is above 25.

1 Answer

You need to define a boolean variable on your condition like we do here with cond, which you can then use to plot conditionally or in your script's logic:

//@version=4
study(title="Directional Movement Index", shorttitle="DMI", format=format.price, precision=4)
len = input(17, minval=1, title="DI Length")
lensig = input(14, title="ADX Smoothing", minval=1, maxval=50)
[_, _, adx] = dmi(len, lensig)
plot(adx, color=color.red, title="ADX")
hline(25)

cond = adx > 25
bgcolor(cond ? color.silver : na)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.