Aligning PlotText right in the middle of bar (x Position)

Hi Seniors - I have set up fonts that I plot above/below bars based on conditions.

SECTION_BEGIN("Effort Signals");

// Vertical Stacking of Key Efforts 

upperHalf = Close > (High + Low) / 2;
lowerHalf = Close < (High + Low) / 2;
lowClosingBars = Close < Ref(Close, -1);
upClosingBars = Close < Ref(Close, -1);
DnClosingBars = Close < Ref(Close, -1);


highVolEver = V == Highest(V);
    

	
	

for (i = 0; i < BarCount; i++) 
	{


    textY = -50; // adjust this value to change the vertical position of the text
    //textYoffset = textY * textYoffseta;
    textYoffseta = 21;
    textfont = 6;

    //HVE - Up bar
    if (highVolEver[i] && upClosingBars[i] && upperHalf[i]) {
        PlotTextSetFont("HVE", "Arial",textfont, i, L[i], colorBlack, colorBrightGreen, textY);
		 textY -= textYoffseta;
    }    
	
	//HVE - Down bar
    if (highVolEver[i] && DnClosingBars[i] ) {
        PlotTextSetFont("HVE", "Arial", textfont, i, L[i], colorWhite, ColorRGB(255,0,0), textY);
		textY -= textYoffseta;
    }
    
 
    	//XXX
    if (1 == 2 ) {
        PlotTextSetFont("HVQ", "Arial", textfont, i, L[i], ColorRGB(255,0,0), colorDefault, textY);
		
    }
    
    
    }
    
    _SECTION_END();

Output -

As you can see the X position of plotsettext() is skewed towards right side of the bar.

How to Center Align it?

I tried to implement solution our senior @fxshrat suggested, in below link, but it either skewes text towards right or left of a bar and not center.

Appreciate any enhancement in my code please.

PlotText uses left alignment.

If you need custom alignment you need to use low-level graphics, GfxTextOut and GfxSetTextAlign

1 Like

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