Plot at pixel level

Hi,

First the chart :

image

now the code --

_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();


//WORK IN PROGRESS
_SECTION_BEGIN("WAVES");
nbar=Param("N Pivot Bars",2,2,21,1);

pk=H>Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar)>=L;

x = BarIndex();														
fvb = FirstVisibleValue( x );
lvb = LastVisibleValue( x );
plotarrows = ParamToggle("PLOT ARROWS","NO|YES",0);
plotvalue = ParamToggle( "VALUE", "NO|YES", 0);


R =lvb-fvb;
Hhb = HighestVisibleValue( H ) ;
Llb= LowestVisibleValue( L ); 

HhL = Hhb+20;
 LlL =Llb-20; 
 
if(plotarrows)
{
PlotShapes(shapedownarrow*pk,colorRed,0,HhL);
PlotShapes(shapeuparrow*tr,colorgreen,0,LlL-20);
}


//Value of pivots and range of fall OR rise
Rise = ValueWhen(pk,H,1) - ValueWhen(tr,L,1) ;
Fall = ValueWhen(tr,L,1) - ValueWhen(pk,H,1)  ;

 for( i = 0; i < lvb; i++ ) 
if( Plotvalue )
{ 

if( pk[i] ) PlotText( ""  +  H[ i ],   i-2,   HhL+75,   colorDarkGreen);   
if( tr[i] ) PlotText( ""  +  L[ i ],  i-2,  LlL-100,    colorDarkRed );  


if( pk[i] ) PlotText( ""  +  Rise[ i ],   i-2,   HhL+55,   colorGreen);   
if( tr[i] ) PlotText( ""  +  Fall[ i ],  i-2,  LlL-80,    colorRed );  

} 


_SECTION_END();

What I would kike to achieve is mentioned on the chart , a small explanation here--
Trying to mark 2 bar fractal pivots with arrows, plot the value of the pivot and the run - rise or fall in that swing on the chart.

The calculations for the above are done and the plot is based on Hhb = HighestVisibleValue( H ) ;
Llb= LowestVisibleValue( L ); lines - 22 to 27 of the code.

I would like to do the plots at set "pixel levels".

No attempt to do this is shown as I do not know how to do it.

Much appreciate any help

@JEETU if you still prefer to use PlotText() (instead of the more flexible Gfx - low-level graphics functions) here you'll find an example courtesy of @fxshrat that shows how to to change the font and its size.

Re the formatting of the numbers, you have some options: see this @Tomasz answer or here where there are additional examples of usage of some of the functions that you can use to get the desired number of decimal in your results.

It is not clear to me what do you mean by "pixel level." Please elaborate.

@beppe
Thanks, from your lead got the plot at "pixel level" , lines 24 to 31 of the code.

Still unable to get output of rise & fall to 2 decimal places. As marked on the chart , for fall have used round(), but can not understand how to get the desired 2 decimal places.
Kindly help.

scren shot --
image

code -

_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();

SetChartOptions(0,chartShowArrows|chartShowDates | chartHideQuoteMarker);
GraphLabelDecimals = 2;

//WORK IN PROGRESS
_SECTION_BEGIN("WAVES");
nbar=Param("N Pivot Bars",2,2,21,1);

pk=H>Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar)>=L;

x = BarIndex();														
fvb = FirstVisibleValue( x );
lvb = LastVisibleValue( x );
plotarrows = ParamToggle("PLOT ARROWS","NO|YES",0);
plotvalue = ParamToggle( "VALUE", "NO|YES", 0);


Miny = Status("axisminy");
Maxy = Status("axismaxy");

lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");

pxwidth = Status("pxwidth");
pxheight = Status("pxheight");

 
if(plotarrows)
{
PlotShapes(shapedownarrow*pk,colorRed,0,Maxy -120);
PlotShapes(shapeuparrow*tr,colorgreen,0,Miny +110);
}


//Value of pivots and range of fall OR rise
Rise = ValueWhen(pk,H,1) - ValueWhen(tr,L,1) ;
Fall = round(ValueWhen(tr,L,1) - ValueWhen(pk,H,1))  ;

 for( i = 0; i < lvb; i++ ) 
if( Plotvalue )
{ 

if( pk[i] ) PlotTextSetFont( ""  +  H[ i ], "Arial bold",11,  i-1,  Maxy -95,   colorDarkGreen);   
if( tr[i] ) PlotTextSetFont( ""  +  L[ i ], "Arial bold",11, i-1,  Miny +70,    colorDarkRed );  


if( pk[i] )PlotTextSetFont( ""  +  Rise[ i ],"Arial bold",11,   i-1,  Maxy -75,   colorGreen);   
if( tr[i] ) PlotTextSetFont( ""  +  Fall[ i ],  "Arial bold",11,i-1,  Miny +50,    colorRed );  

} 

_SECTION_END();

Instead of:

"" + H[ i ]

in your code, use proper formatting:

NumToStr( H[ i ], 1.2 );

or

StrFormat("%.2f", H[ i ] );

http://www.amibroker.com/f?numtostr
http://www.amibroker.com/f?strformat

@beppe , @Tomasz

Thanks a lot, still do not understand how it works !! but trial and error, then it clicked.
only showing the change to the code--

t
if( pk[i] )PlotTextSetFont( ""  +  NumToStr( Rise [ i ], 1.2 ),"Arial bold",11,   i-1,  Maxy -75,   colorGreen);   
if( tr[i] ) PlotTextSetFont( ""  +   NumToStr( Fall [ i ], 1.2 ),  "Arial bold",11,i-1,  Miny +50,    colorRed );  

Now I have another issue, till now was working on an hourly chart, when I switched to a daily chart the out put, arrows and numbers are overlapping.

Will try over the week end or come back next week asking for help.

Thanks again

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