Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, EternallyCurious, TipmyPip, Quad), 899 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Ehler's Instantaneous Trendline #432557
11/08/13 09:52
11/08/13 09:52
Joined: Oct 2013
Posts: 2
Prague
Z
zcom001 Offline OP
Guest
zcom001  Offline OP
Guest
Z

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:

Code:
InstTrend = (α − (α/2)2) * Price + (α2/2) * Price[1]
− (α − 3α2/4) * Price[2]) + 2 * (1 − α)
* InstTrend[1] − (1 − α)2 * InstTrend[2];



My Zorro script:

Code:
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
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

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: swingtraderkk] #432567
11/08/13 13:02
11/08/13 13:02
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi zcom001. Don't have time right now to look in detail or try to correct, but my 1st reaction is you should use a series for ITrend, not an array. There are examples in indicators.c, among other places.

HTH.

Re: Ehler's Instantaneous Trendline [Re: DdlV] #432568
11/08/13 13:40
11/08/13 13:40
Joined: May 2013
Posts: 245
S
swingtraderkk Offline
Member
swingtraderkk  Offline
Member
S

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.

Code:
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
Z
zcom001 Offline OP
Guest
zcom001  Offline OP
Guest
Z

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

Originally Posted By: swingtraderkk
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.

Code:
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: zcom001] #442761
07/02/14 01:17
07/02/14 01:17
Joined: Feb 2014
Posts: 181
R
RTG Offline
Member
RTG  Offline
Member
R

Joined: Feb 2014
Posts: 181
When I test ITrendline, it produces an oscillator, not a filtered moving average of price. Ehlers' book gives an example and shows the ITrendline moving along with an EMA of price much like a traditional moving average.

Is this the intention?

Re: Ehler's Instantaneous Trendline [Re: RTG] #442773
07/02/14 15:15
07/02/14 15:15
Joined: Jul 2000
Posts: 27,982
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,982
Frankfurt
You're probably mistaken. The code above does not look like an oscillator. Check if you plotted it correctly and used right parameter values.

Re: Ehler's Instantaneous Trendline [Re: jcl] #442826
07/04/14 02:22
07/04/14 02:22
Joined: Feb 2014
Posts: 181
R
RTG Offline
Member
RTG  Offline
Member
R

Joined: Feb 2014
Posts: 181
Which value are you using for Alfa?

Ehlers uses 0.07 in his book which is a 14 day average.

As Alfa approaches 1, ITrend more closely maps onto price. But an moving average of length 1 isn't averaging anything.


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1