How to refresh / repaint screen after left click the mouse to select different bar

Dear All
I have make a trend line between HHV and pev HHV, and it works, but when I click the mouse to select bar diffrent from the inititial bar (the second bar from the right in programming), the trend line don't redraw according to the selected bar, but if we check from the text that I use for checking the HHV,HHVbars, all change to the new bar position, so how to refresh and repaint the new trendline to draw/paint with the new HHV and HHV bars changed ?
the code :

// this  trendline period not include the most right bar
// the HHVBars1 and HHVBars2 count using zero base, it means count from 0, then 1, then 2 and so on
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} {{OHLCX}} Vol %.0f {{VALUES}}", V ));
HHVPrd1 = Param("Period for HHV1",5,1,100,1);
HHVPrd2 = Param("Period for HHV2",5,1,100,1);
HHV1= Ref(HHV(H,HHVPrd1),-1); 
HHVBars1 = Ref(HHVBars(H,HHVPrd1),-1);
CountStart= (HHVBars1+1)* (-1); 
HHV2 = Ref(HHV(H,HHVPrd2),-1);
HHV2 = Ref(HHV2,CountStart);
HHVBars2 = Ref(HHVBars(H,HHVPrd2),-1);
HHVBars2 = Ref(HHVBars2,CountStart);
totalbar1=HHVBars1+1;
totalbar2=totalbar1+HHVBars2+1;
text1 = "   HHV1: "+ WriteVal(HHV1,1.2)+",  HHV2: "+ WriteVal(HHV2,1.2)+",  HHVBars1 :"+WriteVal(HHVBars1,1.0)+
",  HHVBars2 : "+WriteVal(HHVBars2,1.0)+",  HHV_period1 :"+WriteVal(HHVPrd1,1.0)+",  HHV_period2 :"+WriteVal(HHVPrd2,1.0);
Plot( Close, "Close", colorDefault, styleBar ); 
GfxSetOverlayMode(1);
GfxSelectFont("Tahoma", Status("pxheight")/32);
GfxSetTextAlign( 6 );// center alignment
GfxSetTextColor( ColorRGB( 200, 200, 200 ) );
GfxSetBkMode(1); // transparent
GfxTextOut(text1, Status("pxwidth")/2, Status("pxheight")/12 );
x1 =  LastValue(barindex()-HHVBars1-1); // BAR KE
y1 =  LastValue(HHV1);       			// NILAI HARGA
x0 = LastValue(BarIndex()-totalbar2);	// BAR KE
y0 =  LastValue(HHV2);    					// NILAI KE
Plot( LineArray( x0,y0,x1,y1 ), "Trend line", colorYELLOW, styleThick );

trend%20line%20-%20bob
Thanks for helping me to increase my skill programming in Amibroker

Rgds Bob Tanujaya

Hi @yenpok,

If I understand your requirement correctly, you want the trendline to be redrawn whenever you select a different bar?

And the trendline draws from the High of the selected bar, to the previous HHV?

Can you pls confirm.

Yes Sir. that's what I want.

rgds bob tanujaya

You seem to have locked the X1,Y1, X0,Y0 co-ords to the last bar using LastValue(). Try SelectedValue() instead for the bars.
You may have to adjust the logic for other parts of the code.

2 Likes

Dear Sir
I have changed to SelectedValued(), and fix my problem, thanks for your Help, I will get clear diffrence between lastvalued (that lock the last bar) and selectedvalue (that will run according the valued that I selected), and now I know more detail how to use right command then.

thanks and many thanks.

rgds bob tanujaya