PureBytes Links
Trading Reference Links
|
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=12huaejo5/M=362131.6882500.7825259.1493532/D=groups/S=1705632198:TM/Y=YAHOO/EXP=1124811865/A=2889190/R=0/SIG=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
<*> 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/
|