Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Positive Bars Percentage – Intraday Sentiment Indicator

53 sec read

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

Masterclass on AmiBroker AFL coding

AMIBROKER

Masterclass on AmiBroker AFL coding

Write trading systems, explorations and backtests in AFL, and use ChatGPT to code faster.

  • AFL from basics to trading systems
  • Backtesting and optimisation done right
  • 7 courses in one masterclass
Learn AFL coding →by Marketcalls

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();
Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

7 Replies to “Positive Bars Percentage – Intraday Sentiment Indicator”

    1. You mean overall sentiment of the stock?

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

      NewDay = Day() != Ref(Day(), -1); with NewMonth = Month() != Ref(Month(), -1);
      if(NewDay[i]==True) with if(NewMonth[i]==True)

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

      NewDay = Day() != Ref(Day(), -1); with NewYear = Year() != Ref(Year(), -1);
      if(NewDay[i]==True) with if(NewYear[i]==True)

  1. Thanks 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…

  2. hello this afl doesn’t work, amibroker told me that there are some errors could you tell me why?

  3. Dear Sir,
    I am trying to count red and green candle in last 5 days but it showing both 5 (red=5 and green=5). Please help to find error-

    g = 0;
    r = 0;
    for( i = 0; i Ref(O, – i);
    Greenc = Ref(C, – i) < Ref(O, – i);

    IIf(Redc == 0, r = r + 1, r = r);
    IIf(Greenc == 1, g = g + 1, g = g);
    }

    if(Status("action")==actionCommentary)
    {
    printf(WriteVal(r ) + "n");
    printf(WriteVal(g ) + "n");
    }

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More