Script using Divergence Index Tool

Hi Optuma

I’m looking to write a script which identifies when price crosses above the lower band of the Divergence Index (default 40/10) in last 5 days and is equal to or above its 50 day moving average.

I’ve attempted the following but scripting is stating I have errors. Could you please point me in the right direction.

V1 = DVI() ; V2 = MA(V1, BARS=50) ; V3 = V1 >= V2; V4 = HIGH crossesabove DVI(Default=Lowerline) and TIMESINCESIGNAL() < 5; V3 and V4

Hi,

Are you able to post a screenshot of the setup you want to identify?

By default, when applied, the Divergence Index displays in its window, not on top of the chart as they have very different values (oscillating between 10 and -10 for example).

Ex1

Because of this, it’s not really possible to script for a charts High price crossing above a Divergence Index’s plot(s).

Hi Matthew
I apologise, I have misinterpreted the indicator. I recognise it appears in its own window and not overlaid on the chart. Your chart appears like mine. I simply want to identify when the orange line on your indicator crosses above the lower of the two green bands please.

Hi Matthew
Many thanks for looking into this for me but I think I have resolved the issue with the following script:-

V1 = dvi().UpperLine ; V2 = dvi().LowerLine ; DVI() crossesabove V2

From your original question, if you just place () behind the “HIGH” function, the code is valid:

V1 = DVI() ;
V2 = MA(V1, BARS=50) ;
V3 = V1 >= V2;//For clarity of the Boolean logic, I would rephrase this as V3 = (V1 >= V2)
V4 = HIGH() crossesabove DVI(Default=Lowerline) and TIMESINCESIGNAL() < 5;
V3 and V4

Hi Terry
Thank you for looking at this for me. I’ll check out your solution now.