NumberBars = BarsSince( Buy ); <--- How can I change "BarsSince( Buy )" to be a given period of "yesterday 091500 to 162959"

UpBar = Close > Open;

BarsConditionTrue = Sum( UpBar, NumberBars );

Actually I want to make a check if 80% bars of yesterday are upbar

if yes, then will do long only today

Many Thanks!

fxshrat
2
**Please** use code tags!

It is just using Sum/BarsSince at start of new day.

```
/// Percentage of yesterday's upbars
/// @link https://forum.amibroker.com/t/how-to-find-the-percentage-of-up-bar-15mins-of-yesterday/27775/2
daysback = 2;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));
dn = DateNum();
newday = dn != Ref( dn, -1);
UpBar = Close > Open;
array = UpBar;
sum_up = SumSince(newday, array)+ValueWhen(newday,array);
yesterday_sum = ValueWhen(newday, Ref(sum_up, -1));
yesterday_bars = ValueWhen(newday, Ref(BarsSince(newday)+1, -1));
percentage = yesterday_sum/yesterday_bars*100;
Buy = percentage > 80;
```

3 Likes

It's very useful!!!

Many Thanks!!

fxshrat
4
Rather use this one as it is faster (because of reducing costly ValueWhen calls and BarsSince being used anyway).

```
/// Percentage of yesterday's upbars
/// @link https://forum.amibroker.com/t/how-to-find-the-percentage-of-up-bar-15mins-of-yesterday/27775/4
daysback = 2;
SetBarsRequired(daysback*inDaily/Max(1,Interval()));
dn = DateNum();
newday = dn != Ref( dn, -1);
UpBar = Close > Open;
array = UpBar;
bars = BarsSince(newday)+1;
sum_up = Sum(array, bars);
yesterday_sum = ValueWhen(newday, Ref(sum_up,-1));
yesterday_bars = ValueWhen(newday, Ref(bars,-1));
percentage = yesterday_sum/yesterday_bars*100;
Buy = percentage > 80;
```

3 Likes

THanks THanks, THanks !!!!!!

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