I am trying to set states based on whether I have a position and the position 
type. If AFL has a getPositions function I can't find it. I tried to create 
states using the following code but barssince does not return a valid value.

// buy control
BarsSB  = Nz(BarsSince(Buy), 0);
BarsSSl = Nz(BarsSince(Sell), 0);
BarsSSh = Nz(BarsSince(Short), 0);
BarsSC  = Nz(BarsSince(Cover), 0);

state   = 0;
// 0 = no position, 1 = buy last, 2 = short last;
state   = IIf(BarsSB == BarsSSh, 0, IIf(BarsSB < BarsSSh, 1, 2)); 
// if sell after buy we are flat
state   = IIf(state == 1 AND BarsSSl < BarsSB, 0, state);       
// if cover after short we are flat
state   = IIf(state == 2 AND BarsSC < BarsSSh, 0, state);       

If I don't use NZ then BarsSince returns Empty.
When I use NZ then I can see trades using plot shapes. But all the barsSince 
returns 0 so state is always 0. What am I doing wrong?

The really interesting thing is that I can put the barsince lines below the 
logic where I set buy, sell, short and cover, then I get correct values 
returned. Why does the position matter?

I can use static vars to keep the state but when I do that AutoAnalysis will 
not work and the shapes don't show properly. So I am tryng to find a way that 
allows auto analysis to work. I tried to use switch and found it only works 
with numbers and not arrays. 

Thanks,
Barry 

Reply via email to