Required AFL Codes for displaying "Today's Bar Numbers" on Each of Candles on Charts..

pkgmtnl

Well-Known Member
#1
Dear Coders,
AFL Codes are requested for displaying the "Trading Day's Bar/ Candle" Number at top or bottom of each candle on Charts. Can any coder help to develop or share?

Thankyou.
 

sanju005ind

Investor, Option Writer
#4
this will be helpful, good luck :)

Code:
newday = DateNum()!=Ref(DateNum(),-1);
count = 0;
for ( i = 0 ; i < BarCount ; i++)
{
if(newday[i])
count=1;

PlotText(NumToStr(count,1.0),i,L[i],1,-1,-12);
count++;

}
Have you disabled PM.. I was trying to send a message.
 
#8
I've added quite some parameters so that you can adjust it to your taste.

Please note the the angle at which you want to plot the text is multiplied by 0.1. Thus for 90 degrees you will have to use 900 in the properties box.
Kindly keep that in mind while adjusting that value in the properties dialog box.

Hope this helps.

Code:
plot_interval = param("Plot bar num interval", 5, 1, 500, 1);

bar_num_font = paramstr("Font for bar number", "Corbel");
bar_num_font_size = param("Font size for bar number", 8, 1, 10, 1);
bar_num_color = paramcolor("Color for bar number", colorgrey40);
bar_num_align = param("Alignment for bar number", 30, 0, 100, 1);
bar_num_angle = param("Angle for bar number", 0, 0, 3600, 1);
bar_num_offset = param("Bar number offset", 1, 0, 200, 1);
bar_num_pos = paramtoggle("Bar number plot position", "Below Low|Above High", 0);

if (interval() < indaily) {
    newday = datenum() != ref(datenum(), -1);
    
    count = 0;
    
    gfxsetbkmode(1);
    gfxsetcoordsmode(1);
    gfxsettextalign(bar_num_align);
    gfxsettextcolor(bar_num_color);
    gfxselectfont(bar_num_font, bar_num_font_size, 400, false, false, bar_num_angle);

    first_visible_bar = status("firstvisiblebar");
    last_visible_bar = status("lastvisiblebar");
    
    for (i = first_visible_bar; (i < last_visible_bar) and (i < barcount); i++) {
        if (newday[i]) {
            count = 1;
        }
        
        if (count % plot_interval == 0) {
            x = i;
            if (bar_num_pos) {
                y = h[i] + bar_num_offset;
            } else {
                y = l[i] - bar_num_offset;
            }
            gfxtextout(strformat("%.0f", count), x, y);
        }
        
        count++;
    }
}
 
Last edited:
#9
I have updated the formula in the previous post and if you are using it then please update your copy with the latest one. The logic is still the same but have updated some defaults.
 

pkgmtnl

Well-Known Member
#10
I've added quite some parameters so that you can adjust it to your taste.

Please note the the angle at which you want to plot the text is multiplied by 0.1. Thus for 90 degrees you will have to use 900 in the properties box.
Kindly keep that in mind while adjusting that value in the properties dialog box.

Hope this helps.

Code:
plot_interval = param("Plot bar num interval", 5, 1, 500, 1);

bar_num_font = paramstr("Font for bar number", "Corbel");
bar_num_font_size = param("Font size for bar number", 8, 1, 10, 1);
bar_num_color = paramcolor("Color for bar number", colorgrey40);
bar_num_align = param("Alignment for bar number", 30, 0, 100, 1);
bar_num_angle = param("Angle for bar number", 0, 0, 3600, 1);
bar_num_offset = param("Bar number offset", 1, 0, 200, 1);
bar_num_pos = paramtoggle("Bar number plot position", "Below Low|Above High", 0);

if (interval() < indaily) {
    newday = datenum() != ref(datenum(), -1);
  
    count = 0;
  
    gfxsetbkmode(1);
    gfxsetcoordsmode(1);
    gfxsettextalign(bar_num_align);
    gfxsettextcolor(bar_num_color);
    gfxselectfont(bar_num_font, bar_num_font_size, 400, false, false, bar_num_angle);

    first_visible_bar = status("firstvisiblebar");
    last_visible_bar = status("lastvisiblebar");
  
    for (i = first_visible_bar; (i < last_visible_bar) and (i < barcount); i++) {
        if (newday[i]) {
            count = 1;
        }
      
        if (count % plot_interval == 0) {
            x = i;
            if (bar_num_pos) {
                y = h[i] + bar_num_offset;
            } else {
                y = l[i] - bar_num_offset;
            }
            gfxtextout(strformat("%.0f", count), x, y);
        }
      
        count++;
    }
}

Thankyou so much, similarly can you help with codes to write HIGH and LOW values of each candle at top and bottom respectively...

Rgds
 
Last edited:

Similar threads