Try starting with something like this:
{------------------------------------}
bl:=If(H-Mov(C,22,E)<0,0,H-Mov(C,22,E));
br:=If(L-Mov(C,22,E)>0,0,L-Mov(C,22,E));
{------------------------------------}
a1:=(bl>0)*
(Ref(bl,-1)>0)*
(Ref(bl,-2)>0)*
(Ref(bl,-3)>0)*
(Ref(bl,-4)>0)*
(Ref(bl,-5)>0)*
(Ref(bl,-6)>0)*
(Ref(bl,-7)>0)*
(Ref(bl,-8)>0)*
(Ref(bl,-9)>0);
a2:=If((a1=0) AND (Ref(a1,-1)=1),1,0);
{----------------------------}
b1:=(ValueWhen(1,a2=1,C)+
ValueWhen(2,a2=1,C)+
ValueWhen(3,a2=1,C))/3;
b1