```
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("BAR COUNTING RULER Ver 2");
GfxSetOverlayMode( 1 );
GfxSetCoordsMode( 1 ); // bar/price mode (instead of pixel)
function BarCountingRuler( StudyID, Color )
{
trendline = Study(StudyID, GetChartID() );
bi =BarIndex();
X0= StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), BarIndex() ) );
X1= EndX = LastValue( ValueWhen( trendline, BarIndex()) ); // printf("X0 StartX = %g,\n X1 EndX = %g\n", StartX, EndX );
Y0= StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
Y1= EndY = LastValue( ValueWhen( trendline, trendline ) ); // printf("Y0 StartY = %g,\nY1 EndY = %g\n", StartY, EndY );
Y2=((Y1-Y0)*0.382)+Y0;
Y3=((Y1-Y0)*1.618)+Y0;
Y4=((Y1-Y0)*2.618)+Y0;
y6=y0-((Y1-Y0)*1.618);
y7=y0-((Y1-Y0)*2.618);
GfxSelectPen( Color );
Bars= bi[x1]-bi[x0];
ext= Bars;
GfxMoveTo( X0, y1 ); GfxLineTo( X1+(ext*2), y1 ); // 0%
GfxMoveTo( X0, y0 ); GfxLineTo( X1, y0 ); // 100%
GfxMoveTo( X0, Y2 ); GfxLineTo( X1+(ext), y2 );
GfxMoveTo( X0, Y3 ); GfxLineTo( X1+(ext*2), y3 );
GfxMoveTo( X0, Y4 ); GfxLineTo( X1+(ext*2), y4 );
GfxMoveTo( X0, Y6 ); GfxLineTo( X1+(ext*2), y6 );
GfxMoveTo( X0, Y7 ); GfxLineTo( X1+(ext*2), y7 );
adjustment =-5; x2= x0+Bars*0.618; x3= x0+Bars*1.618; x4= x0+Bars*2; x5= x0+Bars*2.618; x6= x0+Bars*3; //printf("x2 = %g,\t x3 = %g\n", x2, x3 );
// Plot Vetrical lines
visH=HighestVisibleValue(h); VisL= LowestVisibleValue(l);
GfxMoveTo( X0, visH ); GfxLineTo( x0, VisL );
GfxMoveTo( X1, visH ); GfxLineTo( x1, VisL );
GfxMoveTo( X2, visH ); GfxLineTo( x2, VisL );
GfxMoveTo( X3, visH ); GfxLineTo( x3, VisL );
GfxMoveTo( X4, visH ); GfxLineTo( x4, VisL );
GfxMoveTo( X5, visH ); GfxLineTo( x5, VisL );
GfxMoveTo( X6, visH ); GfxLineTo( x6, VisL );
GfxsetBkMode( colorDefault );
GfxSetTextColor( ParamColor("Text Color", colorWhite ));
GfxTextOut( "BAR: "+Bars , X0+adjustment, VISH );
PlotShapes(IIf(x1==bi,shapeDigit1,shapeNone ),colorBlack,0,Y1 ,10 );
PlotShapes(IIf(x6==bi,shapeDigit3,shapeNone ),colorBlue,0,Y1 ,10 );
PlotShapes(IIf(x4==bi,shapeDigit2,shapeNone ),colorRed,0,Y1 ,10 );
}
BarCountingRuler("M1",colorGreen ) ;
BarCountingRuler("M2",colorBlueGrey ) ;
_SECTION_END();
```