This is my code for counting up and down bars. It works in TradingView but not in AB, it just plots zero for both. Can someone please check it and let me know what mistake I have made. It's probably something simple in the conversion from Pine to AFl but I can't see it. Thanks for any help.

```
_SECTION_BEGIN("BarCount");
UpBarCount = 0;
DnBarCount = 0;
InBarH = -99999;
InBarL = 99999;
for (i = 1; i<BarCount-1; i++)
if ((High[i] <= High[i+1] AND Low[i] >= Low[i+1]) OR (High[i] <= InBarH AND Low[i] >= InBarL))
//inside bar
{
InBarH = Max(High[i],InBarH);
InBarL = Min(Low[i],InBarL);
}
if (InBarH >-99999 OR InBarL < 99999)
if (High[i] > InBarH AND Low[i] < InBarL)//Outside bar
{
UpBarCount += 1;
DnBarCount += 1;
InBarH = High[i];
InBarL = Low[i]; }
else if (High[i] > InBarH AND Low[i] >= InBarL)//Up bar
{
UpBarCount += 1;
DnBarCount = 0;
InBarH = High[i];
InBarL = Low[i];
}
else if (Low[i] < InBarL AND High[i] <= InBarH)//Down bar
{
UpBarCount = 0;
DnBarCount += 1;
InBarH = High[i];
InBarL = Low[i];
}
Plot(UpBarCount, "UpBarCount", colorGreen, styleLine);
Plot(DnBarCount, "DnBarCount", colorRed, styleLine);
_SECTION_END();
```