Support and resistance line

want to draw right extended line from last 5 pivot high and low.


pvt_h = Ref(H,-1)<H AND Ref(H,1)<h;

hx = ValueWhen(pvt_h,H);
hb = ValueWhen(pvt_h,BarIndex());


y0 = y1 = LastValue( hx);

x0 =LastValue( hb);
x1 = LastValue( hb) + 1;

line = LineArray( x0, y0, x1, y1,1);
Plot( Line, "Trend line", colorBlue );

with above code i am able to draw the line from latest pivot. but how to draw from previous one? thanks .

/// @link https://forum.amibroker.com/t/support-and-resistance-line/8692
pvt_h = Ref(H,-1)<H AND Ref(H,1)<h;

for ( i = 1; i <= 5; i++ ) {
	hx = ValueWhen(pvt_h,H, i);
	hb = ValueWhen(pvt_h,BarIndex(), i);

	y0 = y1 = LastValue( hx);

	x0 = LastValue( hb);
	x1 = LastValue( hb) + 1;

	line = LineArray( x0, y0, x1, y1,1);
	Plot( Line, "Trend line"+i, colorBlue );
}

Plot( C, "Price", colorDefault, styleCandle );
5 Likes

thanks a lot sir, it works perfect.

For non arrays it is better to use Gfx instead of Plot and linearray.

/// @link https://forum.amibroker.com/t/support-and-resistance-line/8692/3
pvt_h = Ref(H,-1)<H AND Ref(H,1)<h;
bi = BarIndex();

GfxSetCoordsMode(1);
//
GfxSelectPen( colorBlue, 1, 0 );
//
GfxSetBkMode( 1 );
GfxSetTextAlign( 0 | 24 );
GfxSetTextColor( colorBlue );
GfxSelectFont( "Arial", 9, 500, 0, 0, 0 );
for ( i = 1; i <= 5; i++ ) {
	hx = ValueWhen(pvt_h,H, i);
	hb = ValueWhen(pvt_h,bi, i);

	y0 = y1 = LastValue(hx);

	x0 = LastValue(hb);
	x1 = BarCount+2;
	
	GfxMoveTo( x0, y0 );
	GfxLineTo( x1, y1 );
	
	GfxTextOut( "" + y1, x1, y1 );
}

Plot( C, "Price", colorDefault, styleCandle );
4 Likes

thanks sir for the help . very new to the programing arena. Still struggling with the for loop.. thanks again for guiding me to the right direction.