[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: probable bug in afl execution



PureBytes Links

Trading Reference Links

Hello,

"Release Notes" document, changes for version 4.46:

Numbers (floats) are now automatically 'upsized' to arrays on first use of l-value array subscript operator without causing error.
Also r-value subscript can be applied to numbers and return the number itself without causing error, but the underlying variable 
remains just a single number.

This allows to easily intialize arrays to any value without need to write loops.

Example 1:
in previous versions you would need to write:

for( i = 0; i < BarCount; i++ ) myarray[ i ] = 0 ; // fill with zeros
myarray[ 5 ] = 6; // write value to 5th element of the array

now you can write simply:

myarray = 3; // initialize, at this moment myarray is just a number
myarray[ 5 ] = 6; // write value to 5th element of the array, the variable is automatically
// upsized to array and all elements are filled with a numeric value
// that was originally placed in myarray variable

/* myarray is holds now the array filled with values of 3 except element 5 that has value of 6 */

mynumber = 5;
test = mynumber[ 7 ]; // previous versions would give an error message here
// now subscript operator for r-value numeric variable
// is allowed and returns just the number
// and variable is not upsized to array unless appears on left side
// of assignment (l-value)
/* mynumber variable here is still a number */
WriteVal( test );

Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message ----- 
From: "progster01" <progster@xxxxxxxxxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday, March 10, 2009 7:26 PM
Subject: [amibroker] Re: probable bug in afl execution


> Alex - thanks much for your follow-up post.
>
>>Indeed, after the initialization, the type is number; however, when >the first indexed access is made, the type is switched to 
>>array
>
> I am so not used to this sort of thing!
> (It's probably documented somewhere - can anyone note where?)
>
>>now it works! no inconsistency is detected.
>
> I'm glad you are able to move on, but if you don't understand the reason(s) for the initial behavior and subsequent change, 
> beware! <g>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "redberryys" <redberryys@xxx> wrote:
>>
>> 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 amibroker@xxxxxxxxxxxxxxx, "progster01" <progster@> 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 amibroker@xxxxxxxxxxxxxxx, "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 ]
>>
>
>
>
>
> ------------------------------------
>
> **** IMPORTANT PLEASE READ ****
> This group is for the discussion between users only.
> This is *NOT* technical support channel.
>
> TO GET TECHNICAL SUPPORT send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
> http://www.amibroker.com/feedback/
> (submissions sent via other channels won't be considered)
>
> For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
> http://www.amibroker.com/devlog/
>
> Yahoo! Groups Links
>
>
>



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/