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...
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)