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

[amibroker] Re: Writing a fib cluster indicator - strange issue


  • Date: Sat, 19 Dec 2009 22:12:33 -0000
  • From: "kevinoversby" <kevinoversby@xxxxxxxxx>
  • Subject: [amibroker] Re: Writing a fib cluster indicator - strange issue

PureBytes Links

Trading Reference Links


OK, its running stably now, execution time well under 0.5 s.  Next steps are to sort the levels and detect clusters for plotting.

If I try to set any of the fibs values to negative values they are returned as {EMPTY} - why is that?

Thanks / Kevin

SetBarsRequired(sbrAll,sbrAll);

n = 0.3 ;//approx. 4 point swing on ES
fibs[1] = .62; fibs[2] = .27; fibs[3] = 0.01; fibs[4] = .38; fibs[5] = .5;
fibs [6] = .62; fibs[7] = 1; fibs[8] = 1.27; fibs[9] = 1.62; //9 symmetric levels

for(i=1;i<=9;i++)
{

p[i] = LastValue(ValueWhen(PeakBars(H,n)==0,H,i));  //last 9 peaks
t[i] = LastValue(ValueWhen(TroughBars(L,n)==0,L,i));//last 9 troughs

   for(j=1;j<=9;j++)
   {
       for(k=1;k<=9;k++)
       {

array[100*i+10*j+k-111] = t[i] + fibs[k] * (p[j] - t[i]); // calc fib levels
}}}

// Plot levels for testing purposes

for(i=1;i<=900;i++) {
Plot(IIf(array[i]>0,array[i],-1e10),"a",colorBlue);
}



--- In amibroker@xxxxxxxxxxxxxxx, "kevinoversby" <kevinoversby@xxx> wrote:
>
> 
> 
> 
> 
> 
> I've now got the levels plotting on ES 15 second data and its actually quite fast as the array function calls are in a small loop.  The strange part is that the array reverts to empty shortly after plotting. Can anyone see why?
> 
> Thanks / Kevin
> 
> 
> n = 0.3 ;   //approx. 4 point swing on ES
> fibs[1] = -.62; fibs[2] = -.27; fibs[3] = 0; fibs[4] = .38; fibs[5] = .5;
> fibs [6] = .62; fibs[7] = 1; fibs[8] = 1.27; fibs[9] = 1.62; //9 symmetric levels
> 
> PeakCondition=PeakBars(H,n)==0;
> TroughCondition=TroughBars(L,n)==0;
> 
> for(i=1;i<=10;i++)
> {
> 
> p[i]=LastValue(ValueWhen(PeakCondition,H,i)); 
> t[i] = LastValue(ValueWhen(TroughCondition,L,i));
> 
>    for(j=1;j<=10;j++)
>    {
>        for(k=1;k<=5;k++)
>        {
> 
> array[i+j+k-2] = t[i] + fibs[k] * (p[j] - t[i]); // calc fib levels
> }}}
> 
> // Plot first 100 unfiltered levels for test purposes
> 
> for(i=1;i<=100;i++) {
> Plot(IIf(array[i]>0,array[i],-1e10),"a",colorBlue);
> }
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "kevinoversby" <kevinoversby@> wrote:
> >
> > Hi Mike,
> > 
> > Thank you very much for taking the time to post these tips.  I will incorporate as much as I can and post the update later.
> > 
> > 
> > Kevin
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@> wrote:
> > >
> > > Hi,
> > > 
> > > A couple of quick points to spare you some wasted time.
> > > 
> > > 1. In general; I think that you would benifet greatly by reading the following:
> > > 
> > > http://www.amibroker.com/guide/h_understandafl.html
> > > 
> > > 2. You *really* do not want to be making array based function calls (e.g. PeakBars, ValueWhen, IIF, TroughBars, etc) within a loop. This will be horribly slow. Look for a way to calculate everything outside of a loop.
> > > 
> > > 3. The termination check of all your for loops are incorrect. Do not use "i = 10". You probably want something like "i <= 10". It needs to be a boolean if you ever want it to terminate. Also "=" is assignment, "==" is equivalence test.
> > > 
> > > http://www.amibroker.com/guide/a_mistakes.html
> > > 
> > > 4. When trying to populate an array inside a loop, you generally should be populating bar by bar: e.g.  array[i] = ...
> > > 
> > > Mike
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "kevinoversby" <kevinoversby@> wrote:
> > > >
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > Parts 1) & 2)
> > > > 
> > > > n = 0.3 //approx. 4 point swing on ES
> > > > fibs = [-.62 -.27 0 .38 .5 .62 1 1.27 1.62]; //symmetric
> > > > 
> > > > for(i=1;i=10;i++)
> > > > {
> > > > PeakCondition=PeakBars(H,n)==0;
> > > > p[i] = ValueWhen(PeakCondition,H,i);
> > > > p[i] = IIf(p[i] >= HHV(p,i),p[i],0); //set to zero if not HH
> > > > 
> > > > TroughCondition=TroughBars(L,n)==0;
> > > > t[i] = ValueWhen(TroughCondition,L,i);
> > > > t[i] = IIf(t[i] <= LLV(t,i),t[i],0); //set to zero if not LL
> > > > 
> > > >    for(j=1;j=10;j++)
> > > >    {
> > > >        for(k=1;k=9;k++)
> > > >        {
> > > > 
> > > > array = t[i] + fibs[k] * (p[j] - t[i]); // calc fib levels
> > > > }}}
> > > > 
> > > > I'm unsure of the last line - how to assign the fib levels to an array for sorting.  Thanks in advance for any help.
> > > > 
> > > > 
> > > > Kevin
> > > > 
> > > > 
> > > > 
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "kevinoversby" <kevinoversby@> wrote:
> > > > >
> > > > > I have not found an AFL implementation of this so decided to develop my own.  I'm doing it here as there are a couple of coding issues I'm unsure of.  Constructive comments and tips most welcome.
> > > > > 
> > > > > Process:
> > > > > 
> > > > > 1) Find i last higher peaks and j last lower troughs
> > > > > 2) For each peak/trough pair, calculate fib levels and add to array
> > > > > 3) Sort array
> > > > > 4) Discard a level if distance to next level > tolerance
> > > > > 5) Plot remaining levels, preferably at left or right edge like volume at price (VAP) to simplify chart.
> > > > > 
> > > > > (A thought just occurred that this would also be a useful exercise with VAP levels - investigate later).
> > > > > 
> > > > > 
> > > > > Kevin
> > > > >
> > > >
> > >
> >
>




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

**** 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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/