amibroker

HomeKnowledge Base

Automatic support and resistance lines based on last HHV and LLV value

In this example we will present a method to plot automatic support and resistance lines based on recently hit highs/lows. In order to draw horizontal lines showing levels of recent HHV/LLV values and start drawing at the point of the chart, which defines given price level – we first need to identify the bar, where the line should start. This can be done with use of HHVBars / LLVBars functions.

These functions allow to find out the number of bars that have passed since our support or resistance level was established, so we could prevent from drawing the lines before these points.

This example shows how to draw support and resistance lines based on HHV/LLV levels:

// define reusable function
function SupResLevelsbarscolorUpColorDn )
{
   
bi BarIndex();
   
lvbi LastValuebi );

   
// return HHV value only for bars starting from the bar where HHV level was established
   
hv IIfbi >= lvbi LastValueHHVBarsHighbars ) ), LastValueHHVHighbars ) ), Null );

   
// the same approach for LLV
   
lv IIfbi >= lvbi LastValueLLVBarsLowbars ) ), LastValueLLVLowbars ) ), Null );

   
// plot levels
   
Plothv"hv"colorUpstyleDashed );
   
Plotlv"lv"ColorDnstyleDashed );
}

// price plot
PlotClose"Close"colorDefaultstyleBar );

// call function with various parameters
SupResLevels10colorGreencolorRed );
SupResLevels50colorGreencolorRed )

The chart below shows the output produced by the formula:

Automatic resistance/support levels

Comments are closed.