|
Ehler's Instantaneous Trendline
#432557
11/08/13 09:52
11/08/13 09:52
|
Joined: Oct 2013
Posts: 2 Prague
zcom001
OP
Guest
|
OP
Guest
Joined: Oct 2013
Posts: 2
Prague
|
Hi guys, I am just starting with Zorro and I am sorry for such a silly question. I have been trying to code Instantaneous Trendline indicator from Ehler's Cybernetic Analysis book and I am unfortunately still getting screwed output... :-/ Could you please have a look on my code and advise me what I am doing wrong? Instantaneous Trendline formula in EasyLanguage from Ehler's book:
InstTrend = (α − (α/2)2) * Price + (α2/2) * Price[1]
− (α − 3α2/4) * Price[2]) + 2 * (1 − α)
* InstTrend[1] − (1 − α)2 * InstTrend[2];
My Zorro script:
var Alfa = 0.05;
var ITrend[4];
function run()
{
StartDate = 2012;
EndDate = 2013;
BarPeriod = 1440;
var* Price = series(price());
//Fill Instantaneous Trendline at time 0, 1 and 2 with some
//values in the beginning of the testing period.
if (Bar < 4)
{
ITrend[0] = (Price[0] + 2 * Price[1] + Price[2])/4;
ITrend[1] = (Price[1] + 2 * Price[2] + Price[3])/4;
ITrend[2] = (Price[2] + 2 * Price[3] + Price[4])/4;
}
else
{
// Formula for Instantaneous Trendline itself after Bar 3.
ITrend[0] = (Alfa - Alfa * Alfa/4)*Price[0] + 0.5 * Alfa * Alfa * Price[1] - (Alfa - 0.75 * Alfa * Alfa)*Price[2]+2*(1-Alfa)*ITrend[1]-(1-Alfa)*(1-Alfa)*ITrend[2];
}
// Plot ITrend value
plot("ITrend",ITrend[0],0,RED);
// Plot ITrend values at time 0, 1 and 2 for troubleshooting.
plot("ITrend0",ITrend[0],NEW,RED);
plot("ITrend1",ITrend[1],0,BLUE);
plot("ITrend2",ITrend[2],0,YELLOW);
set(PLOTNOW);
}
The problem obviously is that value of ITrend[1] and ITrend[2] remains constant from the beginning of the test period. I really don't understand why, because I think that every new run of run function after the new bar should shift the values of ITrend... Thank you very much for your help in advance, zcom001
|
|
|
Re: Ehler's Instantaneous Trendline
[Re: zcom001]
#432566
11/08/13 12:55
11/08/13 12:55
|
Joined: May 2013
Posts: 245
swingtraderkk
Member
|
Member
Joined: May 2013
Posts: 245
|
zcom,
On the first bar are you not trying to set the price & trend of non existent bars, ITrend[1] & Price[1] or higher don't exist yet?
I'd try simply setting ITrend[0] = Price[0] for the first 2 or 3 Bars and use Lookback to ignore the first several bars as teh distortion works through.
Does Ehlers specify using close prices i.e. priceClose() or average prices therefore price()?
Last edited by swingtraderkk; 11/08/13 12:58.
|
|
|
Re: Ehler's Instantaneous Trendline
[Re: DdlV]
#432568
11/08/13 13:40
11/08/13 13:40
|
Joined: May 2013
Posts: 245
swingtraderkk
Member
|
Member
Joined: May 2013
Posts: 245
|
I agree with Ddlv, a series would be better. I'd assumed on a quick look that you had used series, so my references to ITrend[1] not existing is of course only true if it was series like Price but not for the array.
vars Price = series(price());
vars ITrendline = series();
if (Bar < 4)
{
ITrendline[0] = Price[0];
}
else
{
ITrendline[0] = (((Alfa - ((Alfa /2) * (Alfa/2))) * Price[0])
+ (((Alfa * Alfa)/2) * Price[1])
- ((Alfa - ((3 * (Alfa * Alfa)) / 4)) * Price[2])
+ ((2*(1-Alfa)) * ITrendline[1])
- (((1-Alfa) * (1-Alfa)) * ITrendline[2]));
}
Seems to work.
|
|
|
Re: Ehler's Instantaneous Trendline
[Re: swingtraderkk]
#432595
11/08/13 21:47
11/08/13 21:47
|
Joined: Oct 2013
Posts: 2 Prague
zcom001
OP
Guest
|
OP
Guest
Joined: Oct 2013
Posts: 2
Prague
|
Hi swingtraderkk and DdlV, it's working, thank you very much for a quick help, much appreciated... :-) Regards, zcom001 I agree with Ddlv, a series would be better. I'd assumed on a quick look that you had used series, so my references to ITrend[1] not existing is of course only true if it was series like Price but not for the array.
vars Price = series(price());
vars ITrendline = series();
if (Bar < 4)
{
ITrendline[0] = Price[0];
}
else
{
ITrendline[0] = (((Alfa - ((Alfa /2) * (Alfa/2))) * Price[0])
+ (((Alfa * Alfa)/2) * Price[1])
- ((Alfa - ((3 * (Alfa * Alfa)) / 4)) * Price[2])
+ ((2*(1-Alfa)) * ITrendline[1])
- (((1-Alfa) * (1-Alfa)) * ITrendline[2]));
}
Seems to work.
|
|
|
|