# Divergence Breakout

Hi, I am trying out an Breakout exploration with current Price breakout from a earlier price point corresponding to earlier RSI Peak/Through.
I think Iam faltering on the last two lines of the code.
can some seniors help me on this.
regards,

``````array = RSI(14);
array1 = C;
amount = Param("Amount",1, 1, 10, 10 );

zz = Zig( array, amount );
is_peak = (Ref(zz,-1) < zz) AND (zz > Ref(zz,1) );  // True if the bar is a peak
is_trough = (Ref(zz,-1) > zz) AND (zz < Ref(zz,1) );  // True if the bar is a trough
pk=Peak( array, amount );
tr=Trough( array, amount );
verifyPeak = array<pk-(pk*amount/100);  // This bar is low enough to form a peak several bars ago
verifyTrough = array>tr+(tr*amount/100);  // This bar is low enough to form a peak several bars ago

onlywhen =  pk  == array ;
rsipk =  SparseCompress(onlywhen, verifypeak);
prpk = SparseCompress(onlywhen,C);

onlywhen = tr ==array;
rsith = SparseCompress(onlywhen,verifytrough);
prth = SparseCompress(onlywhen,C);

//Divergence
BullD = prth < Ref(prth, -1) AND rsith > Ref(rsith, -1);

BearD = prpk > Ref(prpk, -1) AND rsipk < Ref(rsipk, -1);

BullDX = BullD AND Cross(C,Ref(prth,-1));
BearDX = BearD AND Cross(C, Ref(prpk, -1));

Filter = 1;
``````

`

Just learnt that, I need to use Valuewhen to achive this.

Could some seniors push me in the right direction.
Also, I need to reference the 2nd last peak of the divergence.
Hence, the code is altered:

``````BullDX = BullD AND Cross(C,Ref(prth,-2));
BearDX = BearD AND Cross(C, Ref(prpk, -2));
``````

Thanks.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.