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

[amibroker] Re: some looping help needed .......



PureBytes Links

Trading Reference Links

Amazing. I'll need a fresh mind though to fully grasp it. I will 
elaborate on your suggestions and post my progress, if I may.

--- In amibroker@xxxxxxxxxxxxxxx, "Fred" <ftonetti@xxxx> wrote:
> In any case ... writing loops for stuff is leftover programmer 
> ability if you will ... I suffered from the same thing for awhile 
> back when I first started using AB ...
> 
> For example ...
> 
> Your ...
> 
> function CycleConstant(number)
> {
>     for ( i = 0 ; i < BarCount ; i++ )
>     {
>         result[ i ] = Cycle[ number ] ; 
>     }
>     return result; 
> }
> 
> Can be written ...
> 
> Result = Cum(0) + Cycle[number];
> 
> This at least takes the lowest level loop out of play ... 
> 
> When you get around to writing the standard dev part you can write 
> the full calc for indivdual bars w/o loops as well ... so there 
> should only be one loop necessary ...
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@xxxx> wrote:
> > Fred, ALL bars indeed. This is not short-term-TA but long-term-
> > statistics (an attempt at least :-). 3 years of daily bars is 
> > minimum, 10 years would be better.
> > 
> > Your amazement (Is that really what you are wanting ?) though may 
> > have pointed me in the right direction: perhaps I should de-link 
> > these long term standevs from the code. I am thinking about 
> > artificial AddToComposite tickers to store these measurements. No 
> > real "Composites" but multiple per-stock tickers like 
> > 
> > Ticker+"Cycle"+"10to13"
> > Ticker+"Cycle"+"14to17" etc
> > 
> > (certainly incorrect code, I'd have to work this out) 
> > 
> > That would be about 10 ATC tickers per stock (40 different cycles 
> > with 4 storage spaces OHLC for each ticker). One time-consuming 
ATC 
> > run over multiple stocks.  
> > 
> > Remains to be seen though if the code finds accessing data in 
> > truckloads of ATC tickers much more pleasant than doing the 
> > calculations itself..... 
> > 
> > Thanks for thinking along.
> > 
> > -treliff
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Fred" <ftonetti@xxxx> wrote:
> > > Is that really what you are wanting ?
> > > 
> > > Standard deviation of all numbers from the first bar through 
the 
> > > current bar ?  or at the current bar are you wanting standard 
> > > deviation  of the numbers of the most current n bars where n is 
> the 
> > > current cycle ?
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "treliff" <treliff@xxxx> 
wrote:
> > > > Fred, thanks for your comments.
> > > > 
> > > > Correct about standard deviation, the defined StDevCum(array) 
> is 
> > > > really StDev(array, BarIndex() + 1) but this one does not 
work.
> > > > 
> > > > However I'm not sure this is what you are referring to 
because 
> > this 
> > > > is not really a "loop". 
> > > > 
> > > > Could you perhaps be more specific, maybe point me in the 
> > direction 
> > > > of a loop-less re-write? Highly appreciated.
> > > > 
> > > > -treliff
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Fred" <ftonetti@xxxx> 
wrote:
> > > > > Regardless ... It would appear the only loop that's 
required 
> is 
> > > the 
> > > > > one that calc's standard deviation as the built in AFL 
> version 
> > > does 
> > > > > not take an array for length.  The rest of the loops can be 
> > > > replaced 
> > > > > by arrays and in some cases totally done away with.
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@xxxx> 
> wrote:
> > > > > > No, I'm not sure, but this has been discussed before. The 
> > last 
> > > I 
> > > > > recall
> > > > > > Tomasz said not to use this anymore...but we're counting 
on 
> > > > > my "recall"
> > > > > > so that's not reliable ;-)
> > > > > > 
> > > > > > I do know that AB will use as many bars as necessary to 
get 
> > > > > the "right"
> > > > > > answer. It's very smart in that regard. Why don't you 
> record 
> > > some
> > > > > > results, take out the SetBarsRequired and see if the 
> answers 
> > > are 
> > > > > the
> > > > > > same and if the speed is improved?
> > > > > > --
> > > > > > Terry
> > > > > > 
> > > > > > | -----Original Message-----
> > > > > > | From: amibroker@xxxxxxxxxxxxxxx 
> > > > > [mailto:amibroker@xxxxxxxxxxxxxxx] On
> > > > > > | Behalf Of treliff
> > > > > > | Sent: Tuesday, August 23, 2005 09:04
> > > > > > | To: amibroker@xxxxxxxxxxxxxxx
> > > > > > | Subject: [amibroker] Re: some looping help 
needed .......
> > > > > > | 
> > > > > > | Terry, no I don't need 100,000 bars (currently testing 
on 
> > > > several
> > > > > > | years of daily bars) but I do want the calculation 
> (standard
> > > > > > | deviation) over all bars, so back to bar zero from any 
> > > starting 
> > > > > bar.
> > > > > > | 
> > > > > > | While AB Help menu says that SetBarsRequired is only 
> > necessary
> > > > > > | outside pure AFL (having to do with "QuickAFL") I find 
> many 
> > > > pure 
> > > > > AFL
> > > > > > | code examples that contain looping having this
> > > > > > | 
> > > > > > | setbarsrequired( 100000, 100000 ) // require all past 
and 
> > all 
> > > > > future
> > > > > > | bars
> > > > > > | 
> > > > > > | statement at the beginning (like in AFL library or in 
> this 
> > > > > forum).
> > > > > > | 
> > > > > > | Are you sure it can be left out?
> > > > > > | 
> > > > > > | I appreciate your help. Thanks.
> > > > > > | 
> > > > > > | -treliff
> > > > > > | 
> > > > > > | --- In amibroker@xxxxxxxxxxxxxxx, "Terry" 
<MagicTH@xxxx> 
> > > wrote:
> > > > > > | > Do you really need 100,000 bars to get the right 
answer?
> > > > > > | > Seems like not forcing this many bars would speed 
> things 
> > up 
> > > a 
> > > > > lot.
> > > > > > | > --
> > > > > > | > Terry
> > > > > > | > | -----Original Message-----
> > > > > > | > | From: amibroker@xxxxxxxxxxxxxxx
> > > > > > | [mailto:amibroker@xxxxxxxxxxxxxxx] On
> > > > > > | > | Behalf Of treliff
> > > > > > | > | Sent: Monday, August 22, 2005 20:10
> > > > > > | > | To: amibroker@xxxxxxxxxxxxxxx
> > > > > > | > | Subject: [amibroker] some looping help 
needed .......
> > > > > > | > |
> > > > > > | > | Hoping for some help from Expert Coders.
> > > > > > | > |
> > > > > > | > | Code in question is part of a larger code and 
creates 
> an
> > > > > > | incredible
> > > > > > | > | drag, slow chart scrolling etc., understandably so 
in 
> > > view 
> > > > > of the
> > > > > > | > | amount of procedures. Hope this can be 
> > > simplified/improved.
> > > > > > | > | Appreciate anyone's time to take a look and 
possibly 
> > help 
> > > > me 
> > > > > out.
> > > > > > | > |
> > > > > > | > | I have an array called "Cycle" that contains 
integers 
> > > > between
> > > > > > | > | 10 and
> > > > > > | > | 50.
> > > > > > | > |
> > > > > > | > | I have a function called "Oscillator" that, working 
> on 
> > any
> > > > > > | > | Cycle
> > > > > > | > | array, returns some oscillator, meaning it is 
limited 
> > on 
> > > up-
> > > >  
> > > > > and
> > > > > > | > | downside and has Mean approximately zero (like an 
> > > irregular
> > > > > > | Sinus).
> > > > > > | > |
> > > > > > | > | My challenge is that once Cycle has been generated 
> > > (earlier 
> > > > > in my
> > > > > > | > | code) I want to calculate the standard deviation of 
> > > > > Oscillator
> > > > > > | over
> > > > > > | > | all previous bars using strictly the Cycle value of 
> that
> > > > > > | particular
> > > > > > | > | Bar (not the Cycle array which has different 
values).
> > > > > > | > |
> > > > > > | > | For example:
> > > > > > | > | - Bar 300 has cycle value 27
> > > > > > | > | - I create an array with value "27" in all array 
> > elements
> > > > > > | > | - then calculate Oscillator of this "27" array
> > > > > > | > | - calculate the standard deviation of all 
Oscillator 
> > > values 
> > > > > up to
> > > > > > | Bar
> > > > > > | > | 300
> > > > > > | > | - place this particular value in Bar 300 of a new 
> array
> > > > > > | > | - execute this procedure for all Bars separately
> > > > > > | > |
> > > > > > | > | Below is the code I made. TIA for any advice.
> > > > > > | > |
> > > > > > | > | // code start
> > > > > > | > |
> > > > > > | > | /* NOTE: the first few lines below are IRrelevant, 
> only 
> > > to 
> > > > > create
> > > > > > | > | random Cycle values between 10 and 50 and some 
> > Oscillator
> > > > > > | function,
> > > > > > | > | in order for the lower part to work */
> > > > > > | > |
> > > > > > | > | function Randomize(a,b)
> > > > > > | > | { return Random(1)*(b-a)+a ; }
> > > > > > | > |
> > > > > > | > | Cycle = int( Randomize(10,50) ) ;
> > > > > > | > |
> > > > > > | > | function Oscillator(n)
> > > > > > | > | { return Randomize(-50,n) ; }
> > > > > > | > |
> > > > > > | > | /* HERE starts the relevant part */
> > > > > > | > |
> > > > > > | > | SetBarsRequired( 100000, 100000 );
> > > > > > | > |
> > > > > > | > | function StDevCum(array)
> > > > > > | > | { return sqrt( ( (BarIndex()+1) * Cum(array^2) - 
(Cum
> > > > (array))
> > > > > > | ^2 ) /
> > > > > > | > | (BarIndex()+1)^2 ); }
> > > > > > | > |
> > > > > > | > | /* StDevCum calculates standard deviation of array 
> from 
> > > Bar 
> > > > > zero
> > > > > > | up
> > > > > > | > | to current Bar. */
> > > > > > | > |
> > > > > > | > | function Cycleconstant(number)
> > > > > > | > | { for ( i = 0 ; i < BarCount ; i++ )
> > > > > > | > | { result[ i ] = Cycle[ number ] ; }
> > > > > > | > |   return result; }
> > > > > > | > |
> > > > > > | > | /* Cycleconstant fills a complete array with a 
Cycle 
> > > array 
> > > > > element
> > > > > > | > | value (number). */
> > > > > > | > |
> > > > > > | > | for (j = 0 ; j < BarCount ; j++ )
> > > > > > | > | { y = StDevCum( Oscillator( Cycleconstant( j ) ) ) ;
> > > > > > | > |   StDevCumOfOscillator[ j ] = y[ j ] ; }
> > > > > > | > |
> > > > > > | > | /* for each separate Bar this first works 
Oscillator 
> on
> > > > > > | Cycleconstant
> > > > > > | > | array of that Bar, then calculates standard 
deviation 
> > > (from 
> > > > > Bar 0)
> > > > > > | > | and places result in Bar value (array element) of 
new 
> > > array
> > > > > > | > | StDevCumOfOscillator. */
> > > > > > | > |
> > > > > > | > | Plot(0,"",colorBlack);
> > > > > > | > | Plot(Oscillator(Cycle),"Oscillator
(Cycle)",colorBlue);
> > > > > > | > | Plot
> > > (StDevCumOfOscillator,"StDevCumOfOscillator",colorRed);
> > > > > > | > | GraphZOrder = 1;
> > > > > > | > |
> > > > > > | > | // code end
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | > | ------------------------ Yahoo! Groups Sponsor -----
--
> --
> > --
> > > --
> > > > -
> > > > > -----
> > > > > > | -~--
> > > > > > | > | >
> > > > > > | > | <font face=arial size=-1><a
> > > > > > | > |
> > > > > > | 
> > > > > 
> > > > 
> > > 
> > 
> 
href="http://us.ard.yahoo.com/SIG=12h0dd89q/M=362131.6882500.7825259.
> > > > > 1
> > > > > > | > |
> > > > > > | 
> > > > > 
> > > > 
> > > 
> > 
> 
493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1124770234/A=2889190/R=0/
> > > > > S
> > > > > > | > | IG=10r90krvo/*http://www.thebeehive.org
> > > > > > | > | ">Put more honey in your pocket. (money matters 
made 
> > easy)
> > > > > > | Welcome to
> > > > > > | > | the Sweet Life - brought to you by One 
> > Economy</a>.</font>
> > > > > > | > | ----------------------------------------------------
--
> --
> > --
> > > --
> > > > -
> > > > > -----
> > > > > > | --~-
> > > > > > | > | >
> > > > > > | > |
> > > > > > | > | Please note that this group is for discussion 
between 
> > > users 
> > > > > only.
> > > > > > | > |
> > > > > > | > | To get support from AmiBroker please send an e-mail 
> > > > directly 
> > > > > to
> > > > > > | > | SUPPORT {at} amibroker.com
> > > > > > | > |
> > > > > > | > | For other support material please check also:
> > > > > > | > | http://www.amibroker.com/support.html
> > > > > > | > |
> > > > > > | > |
> > > > > > | > | Yahoo! Groups Links
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | > |
> > > > > > | 
> > > > > > | 
> > > > > > | 
> > > > > > | 
> > > > > > | 
> > > > > > | ------------------------ Yahoo! Groups Sponsor ---------
--
> --
> > --
> > > --
> > > > -
> > > > > --~--
> > > > > > | >
> > > > > > | <font face=arial size=-1><a
> > > > > > | 
> > > > > 
> > > > 
> > > 
> > 
> 
href="http://us.ard.yahoo.com/SIG=12hhmiq6u/M=362131.6882500.7825259.
> > > > > 1
> > > > > > | 
> > > > > 
> > > > 
> > > 
> > 
> 
493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1124816731/A=2889190/R=0/
> > > > > S
> > > > > > | IG=10r90krvo/*http://www.thebeehive.org
> > > > > > | ">Put more honey in your pocket. (money matters made 
> easy) 
> > > > > Welcome to
> > > > > > | the Sweet Life - brought to you by One 
Economy</a>.</font>
> > > > > > | --------------------------------------------------------
--
> --
> > --
> > > --
> > > > -
> > > > > ---~-
> > > > > > | >
> > > > > > | 
> > > > > > | Please note that this group is for discussion between 
> users 
> > > > only.
> > > > > > | 
> > > > > > | To get support from AmiBroker please send an e-mail 
> > directly 
> > > to
> > > > > > | SUPPORT {at} amibroker.com
> > > > > > | 
> > > > > > | For other support material please check also:
> > > > > > | http://www.amibroker.com/support.html
> > > > > > | 
> > > > > > | 
> > > > > > | Yahoo! Groups Links
> > > > > > | 
> > > > > > | 
> > > > > > | 
> > > > > > |





------------------------ Yahoo! Groups Sponsor --------------------~--> 
<font face=arial size=-1><a href="http://us.ard.yahoo.com/SIG=12h1dvo6j/M=362343.6886682.7839641.1493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1124866344/A=2894352/R=0/SIG=11fdoufgv/*http://www.globalgiving.com/cb/cidi/tsun.html";>Help tsunami villages rebuild at GlobalGiving. The real work starts now</a>.</font>
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

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

<*> 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/