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

RE: [amibroker] Re: Writing a fib cluster indicator


  • Date: Mon, 21 Dec 2009 08:48:26 -0600
  • From: "Joris Schuller" <jschuller@xxxxxxxxxxx>
  • Subject: RE: [amibroker] Re: Writing a fib cluster indicator

PureBytes Links

Trading Reference Links



Don’t know how experienced you are; with that in mind, I would first simplify code verification somewhat:

1.  limit the plot to the current meaningful visible section by using MinPlotValue=(1-Adjfactor)*LowestVisibleValue(L) and
MaxPlotValue=(
1+Adjfactor)*HighestVisibleValue(H);

2.  start with and verify a simple case (1 pair of peaks and troughs) and expand from that. Compare results with the results using the Fibonacci toolbar

3.  use params to be able to methodically build up in complexity

4.  turn on/off the included ZigZagHL to verify that the correct peaks/troughs are selected

5.  verify that the (incorrect) Fib levels you selected are what you want

6.  convert the constants in the Fib level loop (10,100,111) to params (currently incorrect Fib values are displayed).

7. changes are prefaced by “added”

 

The proposed changes are shown below. 

 

Title = EncodeColor(4)+ _DEFAULT_NAME()+";  "+EncodeColor(1) + StrFormat("{{NAME}} - {{INTERVAL}}; {{DATE}}; O=%g, H=%g, L=%g, C=%g (%.1f%%)
{{VALUES}}
", O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
SetBarsRequired(sbrAll,sbrAll);
//============== added; Begin First Addition===================
Plot(C,"C",1,64);
ZigZagHL=
ParamToggle("ZigZagHL","Off|On",1);
NoOfLastPeaksTroughs=
Param("NoOfLastPeaksTroughs",9,1,10,1);
NoOfFibonacciLevels=
Param("NoOfFibonacciLevels",9,1,10,1);
Adjfactor=
Param("Adjfactor",0.003,0,0.05,0.001); //added. Forex values; for stocks use change as necessary
MinPlotValue=(
1-Adjfactor)*LowestVisibleValue(L);
MaxPlotValue=(
1+Adjfactor)*HighestVisibleValue(H);
Plot(MinPlotValue,"MinPlotValue",colorGreen,5);
Plot(MaxPlotValue,"MaxPlotValue",4,5);
//===============End First Addition===========
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;//added ??????????  fibs[3] = 0.01??;fibs[1]=fibs [6] = .62???????? fibs[2] = .27;???????
//fibs [6] = .62; fibs[7] = 1; fibs[8] = 1.27; fibs[9] = 1.62; //9 symmetric levels//added????????(instead of:0,0.236,0.382,0.5,0.618,0.786.1,1.272)
fibs[
1] = 0.0; fibs[2] = .238; fibs[3] = .382; fibs[4] = .5;//added ??????????  fibs[3] = 0.01??;fibs[1]=fibs [6] = .62???????? fibs[2] = .27;???????
fibs [
5] = .618; fibs[6] = 0.786;fibs[7] = 1; fibs[8] = 1.272; fibs[9] = 1.618;//for(i=1;i<=9;i++) //Original
for(i=1;i<=NoOfLastPeaksTroughs;i++)//Added
{
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++) //Original
for(j=1;j<=NoOfLastPeaksTroughs;j++) //added
{
//for(k=1;k<=9;k++)
for(k=1;k<=NoOfFibonacciLevels;k++) //added; assumed that this are the Fibonacci levels
{
array[
100*i+10*j+k-111] = t[i] + fibs[k] * (p[j] - t[i]); // calc fib levels //added;  might have to adjust the constants(100,10,111) to reflect the param values
}}}
// Plot levels for testing purposes
for(i=1;i<=900;i++) {
//Plot(IIf(array[i]>0,array[i],-1e10),"a",colorBlue); //Original
Plot(IIf(array[i]>MinPlotValue AND array[i]<MaxPlotValue,array[i],-1e10),"a",colorBlue);//Added
}

//==============ZigZagHL; added for verification purposes=========================
if (ZigZagHL)
{
//added
Plot( C, "Close", 1,64);
zigpct =
Param( "Zag %",0.2,0.01,10,0.01);
ATRmult =
Param("ATRmult",1.8,0.1,3,0.1);
Arrowadj =
Param("Arrowadj; ",12,2,25,1);
HHLLSel =
ParamToggle("Each Pk/Tr|HH/LL","Each Pk/Tr|HH/LL",1);
pk=
PeakBars(H,zigpct)==0;
tr=
TroughBars(L,zigpct)==0;
zHi=
Zig(H,zigpct); zLo=Zig(L,zigpct); HLAvg=(zHi+zLo)/2;
zp=
IIf(pk,zHi,IIf(tr,zLo,IIf(HLAvg>Ref(HLAvg,-1),H,L)));
zag=
Zig(zp,zigpct);
pR=
Ref(zag,-1)<zag AND zag>Ref(zag,1);
pS=
Ref(zag,-1)>zag AND zag<Ref(zag,1);
Plot(C,"C",1,64);
Plot(zag,"",11,1|styleNoLabel);//Zig H-L
PlotShapes(shapeDownArrow*pR,colorGreen,0,H,-Arrowadj);
PlotShapes(shapeUpArrow*pS,colorRed,0,L,-Arrowadj);
if(HHLLSel)
{
HH=((zag>
Ref(zag,- 1) AND zag > Ref(zag,1)) AND (Peak(zag,zigpct,1 )>Peak(zag,zigpct,2 ))); //HH
LL=((zag<
Ref(zag,- 1) AND zag < Ref(zag,1)) AND (Trough(zag,zigpct,1 ) <Trough(zag,zigpct,2 ))); //LL
}
if(!HHLLSel)
{
HH=((zag>
Ref(zag,- 1) AND zag > Ref(zag,1)));
LL=((zag<
Ref(zag,- 1) AND zag < Ref(zag,1)));
}
dist = ATRmult*
ATR (20);//might not want that
for( i = 0; i < BarCount; i++ )
{
// ONLY THIS should be inside the loop
if( HH [i]) PlotText( "HH"+ "\n"+H[ i ], i, H[ i ]+dist[i], colorGreen );
if( LL [i] ) PlotText( ""+L[ i ]+"\nLL", i, L[ i ]-dist[i], colorRed );
}
}

 

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of kevinoversby
Sent: Saturday, December 19, 2009 4:32 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Re: Writing a fib cluster indicator

 

 



http://groups.yahoo.com/group/amibroker/photos/album/1601688415/pic/1019200479/view

See link for plot of unfiltered levels. Levels will be filtered by proximity and could also be weighted, for example, by size of swing producing them.

Constructive comments welcome and appreciated.

--- In amibroker@xxxxxxxxxxxxxxx, "kevinoversby" <kevinoversby@xxx> wrote:
>
>
>
> 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@> 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/





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

__,_._,___