Gamestudio Links
Zorro Links
Newest Posts
nba2king Latest Roster Update Breakdown
by joenxxx. 10/14/25 06:06
Help!
by VoroneTZ. 10/14/25 05:04
Zorro 2.70
by jcl. 10/13/25 09:01
ZorroGPT
by TipmyPip. 10/12/25 13:58
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 10/11/25 18:45
Reality Check results on my strategy
by dBc. 10/11/25 06:15
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (Grant, joenxxx), 9,921 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
joenxxx, Jota, krishna, DrissB, James168
19170 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Sine Trend system code by John Ehlers #442410
06/21/14 04:12
06/21/14 04:12
Joined: Feb 2014
Posts: 183
R
RTG Offline OP
Member
RTG  Offline OP
Member
R

Joined: Feb 2014
Posts: 183
[size:17pt]Hello. I am recoding the Sine Trend system published in Ehlers book, "Rocket Science for Traders". Now I think there is an obvious error in the code.

This is the orginal EasyLanguage code. I have made the error as I see it in bold and large type.

The variable "Period" doesn't have a value when it is called upon resulting in the undeclared indentifier error.

Am I seeing this right?

{***************************************

Written by: Ehlers - Rocket science for traders
typed by Henry Amand

Description: SineTrend system, page 120

****************************************}

Inputs: Price((H+L)/2);

Vars: Smooth (0),
Detrender (O) ,
I1 (0),
Q1 (O),
jI (O),
JQ (0),
I2 (0),
Q2 (0),
Re (0),
Im (0),
Period (0),
SmoothPeriod (O),
SmoothPrice (O),
DCPeriod (O),
RealPart (0),
Imagpart (O),
count (0),
DCPhase (O),
DCSine (O),
LeadSine (O),
Itrend (O),
Trendline (O),
Trend (0),
DaysinTrend (O);



If CurrentBar > 5 then begin


Smooth = (4*Price + 3*Price[1] + 2*Price[2] + Price[3]) / 10;
Detrender = (.0962 * Smooth + .5769 * Smooth[2] - .5769 *
Smooth[4] - .0962*Smooth[6]) * (.075 * Period[1] + .54);


{Compute InPhase and Quadrature components.}

Q1 = (.0962 * Detrender + .5769 * Detrender[2] - .5769
* Detrender[4] - .0962 * Detrender[6]) * (.075 * Period[1] + .54);
I1 = Detrender[3];

[/size]

Last edited by RTG; 06/21/14 04:14.
Re: Sine Trend system code by John Ehlers [Re: RTG] #442413
06/21/14 05:39
06/21/14 05:39
Joined: Jul 2000
Posts: 28,028
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,028
Frankfurt
The code by Ehlers is ok. Period is declared under "Vars", and is 0 as long as no other value is assigned.

However a sine wave indicator is much simpler. You only need the sine of the dominant phase plus an offset:

var LeadSine = sin(DominantPhase(Price,30)+PI/4);

Re: Sine Trend system code by John Ehlers [Re: jcl] #442436
06/21/14 23:57
06/21/14 23:57
Joined: Feb 2014
Posts: 183
R
RTG Offline OP
Member
RTG  Offline OP
Member
R

Joined: Feb 2014
Posts: 183
Thanks Johann.

Do you believe that


var LeadSine = sin(DominantPhase(Price,30)+PI/4);

can replace the original Q1 calculation?

{Compute InPhase and Quadrature components.}

Q1 = (.0962 * Detrender + .5769 * Detrender[2] - .5769
* Detrender[4] - .0962 * Detrender[6]) * (.075 * Period[1] + .54);
I1 = Detrender[3];

Re: Sine Trend system code by John Ehlers [Re: RTG] #442461
06/23/14 10:00
06/23/14 10:00
Joined: Jul 2000
Posts: 28,028
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,028
Frankfurt
No, LeadSine does not replace Q1, it replaces the Sine(DCPhase + 45) expression from Ehler's book.

Re: Sine Trend system code by John Ehlers [Re: jcl] #442589
06/25/14 23:52
06/25/14 23:52
Joined: Feb 2014
Posts: 183
R
RTG Offline OP
Member
RTG  Offline OP
Member
R

Joined: Feb 2014
Posts: 183
OK.

I've managed to get a bit further along with this project. Although I am getting a script crash error in the section in bold type. Any ideas?



#include <profile.c>
#include <indicators.c>
#include <default.c>

function run()
{
vars Price = series(price());
vars Period = series();

vars Smooth = series((Price[0]*4 + Price[1]* 3 + Price[2]*2 + Price[3])/10);
vars Detrender = series((.0962 * Smooth[0] + .5769 * Smooth[2] - .5769 * Smooth[4] - .0962*Smooth[6]) * (.075 * Period[1] + .54));



// {Compute InPhase and Quadrature components.}

vars Q1 = series((.0962 * Detrender[0] + .5769 * Detrender[2] - .5769 * Detrender[4] - .0962 * Detrender[6]) * (.075 * Period[1] + .54));
vars I1 = series(Detrender[3]);



// {Advance the phase of I1 and Q1 by 90 degrees}

vars jI = series((.0962 * I1[0] + .5769 * I1[2] - .5769 * I1[4] - .0962 * I1[6]) * (.075 * Period[1] + .54));
vars JQ = series((.0962 * Q1[0] + .5769 * Q1[2] - .5769 * Q1[4] - .0962 * Q1[6]) * (.075 * Period[1] + .54));

// {Phasor addition for 3 bar averaging)}

vars I2 = series(I1[0] - JQ[0]);
vars Q2 = series(Q1[0] + jI[0]);




// {Smooth the I and Q components before applying the discriminator}

vars I2 = series(.2 * I2[0] + .8 * I2[1]);
vars Q2 = series(.2 * Q2[0] + .8 * Q2[1]);

plot("Smooth", Smooth[0], MAIN,BLUE);


plot("Detrender",Detrender[0], NEW,RED);
plot("I1", I1[0],0, BLUE);
plot("jI",jI[0], 0,ORANGE);
plot("Q1", Q1[0], 0, ORANGE);
plot("JQ",JQ[0], 0, GREEN);
plot("I2", I2[0], 0, PURPLE);
plot("Q2", Q2[0], 0, YELLOW);

// {Homodyne Discriminator}

vars Re = series(I2[0] * I2[1] + Q2[0] * Q2[1]);
vars Im = series(I2[0] * Q2[1] - Q2[0] * I2[1]);
vars Re = series(.2 * Re[0] + .8 * Re[1]);
vars Im = series(.2 * Im[0] + .8 * Im[1]);

plot("Smooth", Smooth[0], MAIN,BLUE);

plot("Detrender",Detrender[0], NEW,RED);
plot("I1", I1[0],0, BLUE);
plot("jI",jI[0], 0,ORANGE);
plot("Q1", Q1[0], 0, ORANGE);
plot("JQ",JQ[0], 0, GREEN);
plot("I2", I2[0], 0, PURPLE);
plot("Q2", Q2[0], 0, YELLOW);

plot("Re", Re[0], NEW, BLACK);
plot("Im", Im[0], 0, OLIVE);

vars SmoothPeriod = series();

if(Im != 0 and Re != 0)
vars Period = series((2*PI) / atan2(Im[0],Re[0])); // This line and below line are causing the script to crash when both are active
if(Period[0] > 1.5 * Period[1])
vars Period = series(1.5 * Period[1]);
if(Period[0] < .67 * Period[1])
vars Period = series(.67 * Period[1]);
if(Period[0] < 6)
Period = 6;
if(Period[0] > 50)
Period = 50;

vars Period = series((.2 * Period[0] + .8 * Period[1])); // This line and above


vars SmoothPeriod = series(.33 * Period[0] + .67 * SmoothPeriod[1]);
}

Re: Sine Trend system code by John Ehlers [Re: RTG] #442627
06/27/14 09:04
06/27/14 09:04
Joined: Jul 2000
Posts: 28,028
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 28,028
Frankfurt
You've defined I2, Q2 and Period several times. Also don't define a series at a wrong place after an if(..). Setting a series to 6 or 50 will immediately crash. Also, check if the atan2 can be zero - in that case dividing by it would crash too.

Re: Sine Trend system code by John Ehlers [Re: jcl] #442721
07/01/14 00:21
07/01/14 00:21
Joined: Feb 2014
Posts: 183
R
RTG Offline OP
Member
RTG  Offline OP
Member
R

Joined: Feb 2014
Posts: 183
Divide by 0 should crash the universe.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1