Here the Goal is to use Amibroker AFL to find the Percentage Number of bars which have closed higher then the previous bar out of total number of bars for a day in a selected time frame on Intraday basis. **Positive Bars Percentage** is generally a breath indicator used to gauge the Intraday Sentiment of a Particular stock/Index.Value above 80 indicates extreme positive sentiment and a value below 20 indicates extreme negative sentiment.

For example If Current Time is 11:00 am and we are using 5 min chart then the Total no. of bars till 11.00am is 21

Now,

Let the Total Number of Bars closed higher than previous bar = 16

Let the Total Number of Bars closed lower = 5

Therefore the Percentage of higher closing bars to total no. of bars on Intraday Basis = 76% i.e ((16*100)/21). Which indicates a positive sentiment for the day so far till 11.00a.m.

Here is the afl code which does the action.

///////////////////////////////////

//Coded by Rajandran R

//Date : 20th May 2014

//www.marketcalls.in

///////////////////////////////////_SECTION_BEGIN(“Positive Bars Percentage”);

BarsUp=0;

BarsDown=0;

PCount = 0;

NCount = 0;

NewDay = Day() != Ref(Day(), -1);for(i=0;i<BarCount;i++)

{

if(NewDay[i]==True)

{

BarsUp[i]=0;

BarsDown[i]=0;

PCount = 0;

NCount = 0;

}

//positive count

if(C[i]-O[i]>0)

{

PCount++;

BarsUp[i]=PCount;

BarsDown[i]=NCount;

}

//negative count

if(C[i]-O[i]<0)

{

NCount++;

BarsUp[i]=PCount;

BarsDown[i]=NCount;

}}

BarsToday = 1 + BarsSince(NewDay);

PositiveBarsPercentage = BarsUp*100/BarsToday;

//Plot(BarsToday,”Today Bars”,colorRed);

//Plot(BarsUp,”Positive Bars”,colorblue);

//Plot(BarsDown,”Negative Bars”,colorRed);

Plot(PositiveBarsPercentage,”PositiveBars Percentage”,colorGreen);_SECTION_END();

_SECTION_END();

Download the AFL code for Positive Bars Percentage

SUDHIN says

May 21, 2014 at 9:38 pmCan you make the same for eod basis this would be of real help.

sudhin

Rajandran R says

May 22, 2014 at 3:30 amYou mean overall sentiment of the stock?

If you want to measure the overall sentiment for the month then replace the codes

If you want to measure the overall sentiment for the Year then replace the codes

Leslie says

September 9, 2014 at 6:41 pmThanks Rajandran.

But how to refine for particular days. For eg: Between 4th and 9th of September (ie., 6 days here).

How to set manually in code for ‘Explore’ or ‘Scan’??

Can you please help…

lorenzo says

February 10, 2017 at 4:48 pmhello this afl doesn’t work, amibroker told me that there are some errors could you tell me why?

Rajandran says

February 10, 2017 at 10:27 pmMay be it is not compatible with the current version. What error you are getting?