Support Resistance Array - finding the "next SR" after it breaks

Hello everyone.
as in title.. i believe this problem would very simple for you guys... but yet i still cant find the solution.
hopefully someone can help me about this topic.
Believe me, this take a lot of courage for me to post this kind of topic (beginner level problem),.. i already did the search, read the references, and hours of trial & error in formula editor... and still didn't succeed. Oh well, i think my knowledge in AFL is still very far.
.

I'm trying to find resistance level array, with specific condition.
for simplicity, let say the resistance logics is like this:

  1. define the significant bar (cond_1)

  2. find the High, from the bar of cond_1 (cond_2)

  3. Cond_3:
    a. if Ref(C,-1) is below the High of cond_2, then still use the previous cond_2
    b. if Ref(C,-1) is above the High of cond_2, then find the next lowest High that meet Cond_2 (but not necessarily from the most recent bar)

  4. plot the array of Cond_3

.
Conditions:

cond_1 = C<Ref(C,-1) AND H<Ref(H,-1) AND L<Ref(L,-3) AND C < ((H+L)/2);
cond_2 = ValueWhen(cond_1, H, 1);
cond_3 = IIf((Ref(C,-1) < cond_2), ValueWhen(cond_1 , cond_2, 1), ValueWhen(cond_1 , cond_2, 2 /* this is the problem,.. is there any way to find the "next cond_2" without loop?*/) ) ;

Plot(cond_3, "Resistance 1", colordarkred, styleline);

PlotOHLC(O,H,L,C,"",IIf(cond_1, colorDarkRed, colorDarkGreen),styleCandle);

so yeah.. the problem is, i'm struggling to find the next-lowest-high (3.b) to be plotted in array, and i can't use time/period-based argument like in HHV, HighestSince, etc. Because next-lowest-high of cond_2, could happen at anytime (could be as far as 20 bar in high timeframe or maybe only 3 bar in low timeframe).

i really believe the solution should be already very near (if without loop).
or am i wrong? and i really do need a loop for this?
hopefully someone can help me on this.
Much appreciated.
rgds.

1 Like

I think the solution is in Amibroker Knowledge base.

www.amibroker.com/kb/2016/01/16/automatic-support-and-resistance-lines-based-on-last-hhv-and-llv-value/

I have added to the code the parameters to search for different levels of resistance and support according to my needs, as I show here.

//http://www.amibroker.com/kb/2016/01/16/automatic-support-and-resistance-lines-based-on-last-hhv-and-llv-value/

// define reusable function
function SupResLevels( bars, colorUp, ColorDn )
{
   bi = BarIndex();
   lvbi = LastValue( bi );

   // return HHV value only for bars starting from the bar where HHV level was established
   hv = IIf( bi >= lvbi - LastValue( HHVBars( High, bars ) ), LastValue( HHV( High, bars ) ), Null );

   // the same approach for LLV
   lv = IIf( bi >= lvbi - LastValue( LLVBars( Low, bars ) ), LastValue( LLV( Low, bars ) ), Null );

   // plot levels
   stylenivel=ParamStyle("Style nivel 1", styleDashed+styleThick);
   Plot( hv, "hv", colorUp, stylenivel );
   Plot( lv, "lv", ColorDn, stylenivel );
}
// call function with various parameters
PlotSP = ParamToggle("Plotting Suports-Resistences", "NO|Yes", 1);
if(PlotSP==1)
{
Level1 = Param("Level 1 period ", 10, 10, 1000, 10);
Level2 = Param("Level 2 period ", 50, 50, 1000, 10);
SupResLevels( Level1 , colorGreen, colorRed );
SupResLevels( Level2 , colorGreen, colorRed );
}
1 Like

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