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

Re: [amibroker] Re: How to code a Adaptive StDev()



PureBytes Links

Trading Reference Links

Title: Re: [amibroker] Re: How to code a Adaptive StDev()


Bruce, I am humbled ;-)


This is an excellent tutorial. I had tried nz() earlier but obviously i placed it in the wrong place. This works just great now.


Wow, this was a tough go for me... couldn't have solved this without your, and other user's, help. Thank you.


best regards,

herman





Sunday, June 14, 2009, 7:28:49 PM, you wrote:


>



Herman -


The discontinuities are straightforward to fix.  They are caused by very small numbers in the "dev" result.  Simply apply Nz() to it.  I've left the debug approach in the code below.


Now, I'm just trying to help, but I don't know if you are going to see the effect that I'm referring to until you place the following statement at the END OF THE CODE -


SetBarsRequired( 500, 0 );


I'm taking some liberties with Tomasz's way of explaining this, but another way to think of this is that it is limiting ALL internal calculations in the AFL to 500 bars before the first visible bar PLUS just visible bars.  The reason that this is so important is that it streamlines all calculations by limiting their bar scope.


I've left it in the code below and suggest that you run the following experiment -


  1. Bring the code below up in an editor.
  2. Insert it into a chart and note the timings.
  3. NOTICE THAT THE BARCOUNT ON THE SECOND LINE IS ALL BARS.  This isbecause the first execution of an AFL after an edit or insert mustassume all bars for QuickAFL to calculate its requirements.
  4. NOTE THE LAST LINE OF THE CODE - SetBarsRequired(500, 0).  Whatthat is doing is to override AFL and tell it to process only 500 barsbefore the first visible bar and no future bars.
  5. Now, click anywhere on the chart and note how the barcount on thesecond title line changes.  QuickAFL is now processing a subset ofbars.  It should be bars visible + 500.
  6. MOST IMPORTANTLY, look at the timings in the first line and how they change.

In probably 99 out of 100 cases, an all array implementation withQuickAFL utilized will outperform a looping implementation, usually byfar.


-- BruceR



Periods         = Param("Periods", 15, 4, 50, 1 );

Width         = Param("Width", 2, 0, 10, 0.05 );


function BB2()

{

    global periods, width, dev;

    global temp;


    MAC = MA( C, periods );

    Dev = Width * sqrt( MA( C*C, periods ) - MAC*MAC );

    temp = dev;

    dev = Nz(dev);

    BBTop = MAC + Dev;

    BBBot = MAC - Dev;

    Plot(BBTop, "", colorRed);

    Plot(BBBot, "", colorRed);

}


LOOP            = 10;


GetPerformanceCounter( True );

for ( i = 0; i < LOOP; i++ )

    bb2dev         = BB2();

BB2avg            = GetPerformanceCounter( ) / LOOP;


Plot( C, "", colorDefault );

Plot( MA( C, periods ), "", colorGreen );


Title            = StrFormat( "BB2 avg elapsed = %6.3f", bb2avg );


barsvis        = LastValue( Cum( Status( "barvisible" ) ) );

Title            = Title + StrFormat( "\nBarcount = %5.0f, bars visible = %5.0f", BarCount, barsvis );


Title            = Title + "\nIsNull(temp) = " + IsNull(temp);


SetBarsRequired( 500, 0 );








__._,_.___


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





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___