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

[amibroker] Re: Hurst Channels



PureBytes Links

Trading Reference Links

Thanks for the description ... It wasn't a sarcastic comment per 
se ... It is imho a benefit to be able to hear from authors of code 
what the process is that is going on as opposed to someone 
unfamiliar with the code having to dig it out ...

I agree with your comments in 1 & 2 ... I had initially implemented 
Millard's CMA in the Hurst DE I posted in the library this way ...

Lag = int(Period / 2);
CMA = Ref(MA(MA(Data, Lag), Lag), Lag);

It would seem though after reading Millard more carefully that a 
better implementation is something like 

CMAL1 = Int(Period * 2 / 3);
if (CMAL1 < 5)
    CMAL1 = 5;
If (CMAL1 % 2 == 0)
    CMAL1 = CMAL1 + 1;
CMAL2 = Period - CMAL1;
If (CMAL2 % 2 == 0)
    CMAL2 = CMAL2 + 1;
Lag = (CMAL1 - 1) / 2 + (CMAL2 - 1) / 2;

CMA = Ref(MA(MA(Data, CMAL1), CMAL2), Lag)

The only potential problem I see with this approach is it makes the 
minimum overall CMA Length 8.

For the current AFL I implemented a simple CMA ... no muss / 
fuss ... The reason is that the CMA would be sampled and potentially 
smoothed again ...

I don't know whether or not you have Hurst's PM but he covers ( very 
quickly ) the topic of pulling out the coeff's for multiple cycles 
simultaneously in what is to me any way some rather complex math in 
Appendix 6 ... But then I'm hardly a math Wiz ... If you are 
interested in this kind of thing I would strongly recommend 
Cleeton's book which while out of print is still readily available 
at Amazon and other places for a few bucks used.  He discusses how 
to perform a similar operation for one cycle and for multiple cycles 
simultaneously with one of the early steps being sampling of the 
CMA ... He uses those points directly and as you can tell from my 
description I opted for this approach more or less as well which 
seems to produce some interesting results without requiring Gaussian 
Elimiation to solve multiple simultaneous equations.

--- In amibroker@xxxxxxxxxxxxxxx, Andy Davidson <AndyDavidson@xxx> 
wrote:
>
> Hi Fred,
> 
> It's good to be able to get back on this subject again, especially 
as it 
> looks like there's a few of us who are 'into' cycles.
> 
> Your work-in progress looks very interesting I must say. I 
particularly 
> like the idea in step 5 to reduce the data before finding a 
> fit...brilliant in its simplicity. I also think your equation in 
step 6 
> will help me out...but without getting into that, here's the 
general 
> logic of my approach for comparison (and I take the sarcastic(?) 
comment 
> about explaining in English...I didn't do a good job of notating 
the 
> script properly!)
> 
> 1. Calculate *two* CMAs using triangular-smoothed MAs. CMA1 is n-
periods 
> length and CMA2 is n/2-periods. Both periods are rounded up to the 
> nearest odd number.
> 2. CMA1 allows wavelengths > n-periods to pass and filters out < 
> n-period waves. CMA2 allows through all cycle wavelengths > n/2-
periods 
> and filters out those < n/2. Therefore, subtracting CMA2 from CMA1 
will 
> give us the cycle (or combination of cycles if we're unlucky 
enough, or 
> have our value of n wrong) that lies between n/2 and n.
> 
> Steps 1 and 2 are as per Millard's "Cycle Highlighter" (CH), 
except he 
> states that the best results are obtained with CMA1 being an SMA 
and 
> CMA2 being a Weighted MA. He also says CMA1 periods should be 
*equal* to 
> the wavelength to be isolated. This does work but, through 
> experimenting, I have found that Triangular-MAs are best for both 
as 
> they offer the superior smoothing-to-lag trade off. Furthermore, 
the 
> periodicity of CMA1 should be x1.5 the cycle you want (making CMA2 
> therefore x0.75). The logic still holds up and the results are 
better 
> IMO, with a more sine-like output.
> 
> 3. Based on user-inputs (see below) I then generate an artificial 
sine 
> wave. This is *anchored to the CH at its most recent (i.e. 
confirmed) 
> peak or trough*.
> 4. Correlation coefficients are calculated between (a) the sine 
wave and 
> the CH (or price - depending on user input) over the 'lookback' 
period 
> (see below) and (b) the sine wave and the price in the 'end zone' 
(i.e. 
> the no-data zone for the CH at the right-hand edge).
> 
> Inputs:
> "SINE WAVELENGTH" - this determines if the wavelength of the sine 
is (a) 
> "as per the base cycle (CH)" (i.e. there is no attempt to 'fit' 
the two 
> curves beyond the anchor point) or (b) a "best fit". In the second 
case, 
> the sine wavelength will depend on:
> "BEST FIT # RECENT CYCLES" - this is the number of full, completed 
> cycles of the CH where the correlation is measured. The start 
point of 
> X-cycles back is shown by a blue and red tick on the indicator. If 
> option (b) is chosen above the average wavelength of the CH is 
measured 
> in the zone from the blue tick to the end of its plot. This value 
is 
> assigned to the sine plot. If option (a) above then we just get X-
cycles 
> back of both plots at the same periodicity.
> 
> All the above is as per the first indicator I posted. The 
following 
> loops are done in the auto-fit version:
> 
> 5. A loop from "Wavelength Min" to "Wavelength Max" is performed 
to find 
> the highest total correlation coefficient (a weighted average of 
the 
> 'CH/sine' and the 'sine/end-zone price' values).
> 6. The series of loops is repeated for "#Cycles Min" lookback up 
to 5 
> cycles lookback. I chose 5 as an arbitrary number...it's slow 
enough as 
> is and very rarely do you get a decent correlation going that far 
back. 
> Obviously though when you do, you take notice.
> 
> That's as much as I can tell you right now about the logic. Does 
it 
> work? Well, with the usual caveats blah-blah-blah, I would say 
that it 
> has been a very useful tool for me for a while now *in conjunction 
with 
> other confirming and entry methods*
> 
> Bear in mind that the purpose of the indicator is to find the 
*clearest* 
> cycle amongst those present, i.e. the one that conforms most 
closely to 
> a sine wave, and is therefore tradeable *on that time frame*. I 
will 
> manually switch between time-frames to get the various major 
cycles 
> (e.g. 1-hour, 4-hour, daily and weekly charts). Work on 'auto-ing' 
all 
> that would be very processor intensive and requires further 
thinking.
> 
> The plot you sent seems to bear out a further truth about trading 
with 
> cycles, one that I've experienced with this indicator more than 
once: 
> i.e. short-term cycles (measured in hours and a few days) are less 
> tradeable than longer-term ones (measured in a few days upwards to 
weeks 
> & months). Certainly, in the plot you sent, most of the smoothed 
price 
> behaviour can be explained by the interaction of the two longest 
> measured cycles (dark blue and cyan).
> 
> Anyway, I look forward to ploughing through all the good stuff 
you've 
> already posted and hope you can help keep this thread going. 
There's 
> lots of really cool stuff going on here.
> 
> Cheers for now,
> Andy
> 
> 
> Fred Tonetti wrote:
> >
> > Andy,
> >
> >  
> >
> > Can you describe in English what your AFL does ? ...
> >
> >  
> >
> > I've been playing with a Trig Fit a la Claud Cleeton the steps 
for 
> > which I would describe as follows ...
> >
> >  
> >
> > 1. Optional - Normalize the input i.e. Data = log10((H + L) / 2)
> >
> > 2. Calc an arbitrary length ( Parameterized but 11 at the 
moment ) 
> > centered moving average ( CMA ) of the data
> >
> > 3. Calc a 1st order least squares fit ( LSF ) of the CMA over 
the 
> > period desired ( from / to range marker )
> >
> > 4. Subtract the LSF points from the data points resulting in 
detrended 
> > data.
> >
> > 5. Take an n-bar sampling of the detrended data.  This array 
with 
> > "holes" or "gaps" in it needs either to be compressed or have 
the 
> > "gaps" filled ... I elected ( for the moment ) to calc a cubic 
spline 
> > to fill the gaps ( interpolation ) ...
> >
> > 6. Calc a LSF of the detrended data resulting in the coeffs for 
the 
> > Trig equation Y = A Cos wX + B * Sin wX
> >
> > 7. Calc the correlation of the resulting sin wave to the 
original 
> > detrended data.
> >
> >  
> >
> > Repeat steps 5 & 6 varying n from 1 to ? looking for n where the 
> > correlation is the highest.  This should yield the equation or 
data 
> > points that most closely correlate to the detrended data.
> >
> >  
> >
> > 8. Subtract the points in the sin wave from the detrended data 
> > resulting in a modified detrended data.
> >
> >  
> >
> > Repeat steps 5 - 8 looking for the next most significant cycle.  
This 
> > can be done repeatedly until overall correlation stops getting 
better 
> > and usually results in 2 - 6 cycles ...
> >
> >  
> >
> > See attached ...
> >
> >  
> >
> > The white line in the upper graph is detrended price ...
> >
> > The alternating green / red line is the trig fit, in sample up 
to the 
> > vertical line and out of sample projection afterwards ...
> >
> > The lines in the bottom section are the individual cycles found 
in the 
> > data.
> >
> >  
> >
> > Sometimes the projections are almost clairvoyant ... run time 
however 
> > is anything but quick ...
> >
> >  
> >
> >  
> >
> >  
> >
> >  
> >
> >  
> >
> >
> > -----------------------------------------------------------------
-------
> > I am using the free version of SPAMfighter for private users.
> > It has removed 8649 spam emails to date.
> > Paying users do not have this message in their emails.
> > Try SPAMfighter <http://www.spamfighter.com/go.asp?t=249> for 
free now!
> >
>




Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006