Hi progster,
That is a very good idea - typeof is good to know for debugging.
Indeed, after the  initialization, the type is number; however, when the first 
indexed access is made, the type is switched to array - if I add the same 
printf after the loop, I see both as arrays. This also explains why the values 
printed by printf are different from bar to bar.

I've added some code to automatically check for consistency , and - the most 
intriguing thing - and awkward for me - happened: now it works! no 
inconsistency is detected. I did see temporary inconsistencies when the check 
was not activated, and after the backtester run. I still think there might be a 
refresh missing somewhere; also, I did see some weird behavior of the 
backtester: if I use my temporary arrays for the entries/exits and only later 
copy them to the Buy/Sell/Short/Cover used by the backtester, the backtester 
seems to get confused - it changes them. 
All in all, I still think this would be worth some further investigation, but 
I'll drop it for now.

Once again, thank you so much for taking the time to look into this question. 
Once made to work, I found that for loop to be useful in reducing whipsaws, and 
in improving system performance when fixed commissions are applied [by the 
broker! :)) ]

For reference, here's the code I used for validation:

//Plot(inBuySwitch, "IBS", styleLine | styleOwnScale);
inBuySwitch = (vinBuy + Ref(VinBuy,-1) == 1);
inconsistentB = inBuySwitch && !(Buy || Sell);
c_incB = Cum(inconsistentB);
inShortSwitch = (vinShort+ Ref(vinShort,-1) == 1);
inconsistentS = inShortSwitch && !(Short || Cover);
c_incS = Cum(inconsistentS);
printf("inBuySwitch= %g c_incB= %g c_incS= %g\n\n", inBuySwitch, c_incB, 
c_incS);

Regards,
Alex


--- In [email protected], "progster01" <progs...@...> wrote:
>
> 
> Hi again.
> 
> I think you may be trying to treat as arrays some items whose typeof() is 
> number.  
> 
> Below is a section of the code with a few extra printf() statements, showing 
> that, for example, nbuy_ is a number, not an array.
> 
> Despite this, later notation such as:
> 
> nbuy_[i] = 1;
> 
> is silently accepted.
> 
> I think that to get the results you want may require very careful attention 
> to types, and possibly a different idiom than you are using.
> 
> There may be little help in that generalization, but I've not personally 
> written/tested AFL ala your example, so I don't have a ready-made "solution" 
> available to offer.  (Others might.)
> 
> -----------
> 
> //filter the raw signals 
> nBuy_ = nSell_ = nShort_ = nCover_ = 0; // make sure all arrays are set empty
> 
> printf( "\ntypeof(nBuy_): " + typeof(nBuy_) ) ;
> printf( "\ntypeof(Buy_): " + typeof(Buy_) ) ;
> 
> 
> printf( "\nAfter initialization: \n" ) ;
> printf( "nBuy_= %g nSell_= %g\n", nBuy_, nSell_ );
> printf( "nShort_ = %g nCover_= %g\n", nShort_, nCover_ );
> 
> 
> inBuy = inShort = 0;
> vinBuy = vinShort = 0;
> eprice = 0; //
> veprice = 0; //
> branch = 0;
> 
> printf( "\ntypeof(inBuy): " + typeof(inBuy) ) ;
> printf( "\ntypeof(branch): " + typeof(branch) ) ;
> 
> 
> 
> --- In [email protected], "redberryys" <redberryys@> wrote:
> >
> > Hi progster,
> > Thank you for your response. I've tried it and it still does the same 
> > thing. I shou[[etc - removed ]

Reply via email to