SINE TREND system from Ehler

To add comments, please log in or register
EBTAFOLLOWER
148
EBTAFOLLOWER  

Hello:

I could not find a thread on this topic, so I decided to start a new one. I did not want to put it inthe digital filters one, as it (I think) deserves a topic on its own.

In his book "rocket science for traders" John Ehlers describes a systemn that may have some value.

I am not a MQL4 programmer, so I wanted to bring this up to the programming community here. perhaps this system described in Ehlers book can be coded in MQL4 and used effectively.

The system basically detects/senses the state (cycle) of the market in question, and if it detects the market is trending, it switches to trend mode trading, and if it detects the market is ranging, it switches to range mode.

Here is the code of the system in Ehlers' code's, can a programmer in this forum convert this to MQL4?

Thanks and regards to all.

EF

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

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];

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

jI = (.0962 * I1 + .5769 * I1[2] - .5769 * I1[4] -

.0962 * I1[6]) * (.075 * Period[1] + .54);

JQ = (.0962 * Q1 + .5769 * Q1[2] - .5769 * Q1[4] -

.0962 * Q1[6]) * (.075 * Period[1] + .54);

{Phasor addition for 3 bar averaging)}

I2 = I1 - JQ;

Q2 = Q1 + jI;

{Smooth the I and Q components before applying

the discriminator}

I2 = .2 * I2 + .8 * I2[1];

Q2 = .2 * Q2 + .8 * Q2[1];

{Homodyne Discriminator}

Re = I2 * I2[1] + Q2 * Q2[1];

Im = I2 * Q2[1] - Q2 * I2[1];

Re = .2 * Re + .8 * Re[1];

Im = .2 * Im + .8 * Im[1];

If Im 0 and Re 0 then Period = 360 / ArcTangent (Im/Re);

If Period > 1.5 * Period[1] then Period = 1.5 * Period[1];

If Period < .67 * Period[1] then Period = .67 * Period[1];

If Period < 6 then Period = 6;

If Period > 50 then Period = 50;

Period = .2 * Period + .8 * Period[1];

SmoothPeriod = .33 * Period + .67 * SmoothPeriod[1];

{Compute Dominant Cycle Phase}

SmoothPrice = (4 * price + 3 * Price[1] + 2 * Price[2] +

Price[3]) / 10;

DCPeriod = IntPortion(SmoothPeriod + .5);

RealPart = 0;

ImagPart = 0;

For count = 0 To DCPeriod - 1 begin

RealPart = RealPart + sine (360 * count / DCPeriod) *

(SmoothPrice[count]);

ImagPart = imagPart + CoSine (360 * count / DCPeriod) *

(SmoothPrice[count]);

End;

If AbsValue(ImagPart) > 0 then DCPhase =

Arctangent(RealPart / ImagPart);

If AbsValue(ImagPart) <= .001 then DCPhase =

DCPhase + 90 * Sign(RealPart);

DCPhase = DCPhase + 90;

{Compensate for one bar lag of the Weighted Moving Average}

DCPhase = DCPhase + 360 / SmoothPeriod;

If ImagPart < 0 then DCPhase = DCPhase + 180;

If DCPhase > 315 then DCPhase = DCPhase - 360;

{Compute the Sine and LeadSine Indicators}

DCSine = Sine(DCPhase);

LeadSine = Sine(DCPhase + 45);

{Compute Trendline as simple average over the measured

dominant cycle period}

ITrend = 0;

For count = 0 to DCPeriod - 1 begin

ITrend = ITrend + Price[count];

End;

If DCPeriod > 0 then ITrend = ITrend / DCPeriod;

Trendline = (4 * ITrend + 3 * ITrend[1] + 2 * ITrend[2]

+ ITrend[3]) / 10;

If CurrentBar < 12 then Trendline = Price;

{Assume Trend Mode}

Trend = 1;

{Measure days in trend from last crossing of the

Sinewave Indicator lines}

If Sine(DCPhase) Crosses Over Sine(DCPhase + 45) or

Sine(DCPhase) Crosses Under Sine(DCPHase + 45) Then begin

DaysInTrend = 0;

Trend = 0;

End;

DaysInTrend = DaysInTrend + 1;

If DaysInTrend < .5 * SmoothPeriod then Trend = 0;

{Cycle Mode If delta phase is +/- 50% of dominant cycle

change of phase}

If SmoothPeriod 0 and (DCPhase - DCPhase[1] > .67 * 360 /

SmoothPeriod and DCPhase - DCPhase[1] < 1.5 * 360 /

SmoothPeriod) then Trend = 0;

{Declare a Trend Mode if the SmoothPrice is more than 1.5%

from the Trendline}

If AbsValue ((SmoothPrice - Trendline) / Trendline) >=

.015 then Trend = 1;

If Trend = 1 then begin

If Trend [1] = 0 then begin

If MarketPosition = -1 and SmoothPrice >= Trendline then buy;

If MarketPosition = 1 and SmoothPrice < Trendline then sell;

End;

If SmoothPrice Crosses Over Trendline then buy;

If SmoothPrice Crosses Under Trendline then sell;

End;

If Trend = 0 then begin

If LeadSine Crosses Over DCSine then buy;

If LeadSine Crosses Under DCSine then sell;

End;

End;

kidhudi
165
kidhudi  

what program is this written for?

EBTAFOLLOWER
148
EBTAFOLLOWER  

easylanguage code

I believe it is called easylanguage code, but can't recall right now the name of the platform that it is for.

Malcik
158
Malcik  

It is written for TradeStation. I too tried to rewrite it to MQL4 some time ago but never got it to work. This is why I don't read Ehlers very much anymore because I'm not even able to test his ideas. I'd be glad if we could figure it out because it's sure worth it.

Maybe even smarter and more useful thing to do would be to rewrite his indicator for measuring market -- it's called Cycle Period and is described in Cybernetics Analysis for Stocks and Futures.

billbss
56
billbss  

Ehler likes complexity.

If you want to see how his methods really work, go to Futures Truth and check the performance of his Mesa systems. They monitor futures systems and report the results.

SIMBA
2078
SIMBA  

Complexity..116.9%

billbss:
Ehler likes complexity. If you want to see how his methods really work, go to Futures Truth and check the performance of his Mesa systems. They monitor futures systems and report the results.

Hi..I too like THIS kind of complexity..

Top 10 S&P Systems

Rank System Name Annual % Return

1. Keystone 126.2% 2. R-mesa 3 116.9%

3. R-Breaker 72.3%

4. %C Daybreaker 69.3%

5. STC S&P Daytrade 68.0%

6. RC Success 56.9%

7. RC Edge 54.9%

8. Cyclone 54.6%

9. Tzar 49.1%

10. Mechwarrior 47.

R-Mesa 3 John Ehlers/Mike Barna

Top 10 Systems Since Their Release Date

Rank System Name Annual % Return

1. Anticipation 254.0%

2. Samurai 35 221.8%

3. Qtech Bellies 191.5%

4. ATS-3200 174.7%

5. Natural Gas Offense 164.5%

6. Natural Gas Trader - MA 151.9%

7. Natural Gas Trader - GA 128.0%

8. Natural Gas Trader - LA 124.5%

9. Anticipation II 118.6% 10. R-Mesa 3 116.9%

Regards

billbss
56
billbss  

Then buy his books and implement his methods.

Gramski
415
Gramski  

This is the closest indicator I've seen to at least resembling Sinewave.

TDI...obviously not the same but the concept is similar.

Personally over time I've found I don't care much for this stuff....

Files:
tdi-2.mq4 4 kb
SIMBA
2078
SIMBA  

Books And Methods

billbss:
Then buy his books and implement his methods.

I already did,both,and I shared some of my views on them,extensively, in this Forum..By the way,that is what we were supposedly trying to do in this thread,implement one of his methods in mt4..;)...did you notice ?

So ..what was the meaning of your posts ?

Where a child will see three letters, the student will see one word.... the master will understand its meaning....;)

billbss
56
billbss  
SIMBA:
I already did,both,and I shared some of my views on them,extensively, in this Forum..By the way,that is what we were supposedly trying to do in this thread,implement one of his methods in mt4..;)...did you notice ?

So ..what was the meaning of your posts ?

Where a child will see three letters, the student will see one word.... the master will understand its meaning....;)

What is the meaning of my posts?

Here is the meaning of my first post.

Ehler likes complexity. If you want to see how his methods really work, go to Futures Truth and check the performance of his Mesa systems. They monitor futures systems and report the results.

1.

Ehler likes complexity.

Complexity= The quality or condition of being complex.

Complex= Involved or intricate- complicated.

2.

If you want to see how his methods really work, go to Futures Truth and check the performance of his Mesa systems. They monitor futures systems and report the results.

This means that Ehler's mesa system is monitored and reported on at a web site called Futures Truth.

I meant you can go there and see its results.

It appears you did that. What did you not understand about this post?

My other post:

Then buy his books and implement his methods.

You replied that you had already done this. What did you not understand about it?

By the way,that is what we were supposedly trying to do in this thread,implement one of his methods in mt4..;

Its likely that I noticed since my post was about Ehler. Don't you think?

EBTAFOLLOWER
148
EBTAFOLLOWER  

Fwiw

Hello all:

Thanks for all yor replies, everyone.

I do appreciate the fact that people are reading this post and providing information. I do think that Ehlers' work has some merit, granted, the work is a bit complex, as has been mentioned before.

I am new is this field of electronic trading, and I am trying to learn from all the kind people that post in this forum. I have been monitoring this site for about 11 months now, and this is only my second or third post.

I started with live accounts about 1 year ago, with three different brokers, and I am learning so much about trading, the markets, about MQL4 programming, about people, etc, etc...

One of the things I know is that if I come up with an idea, most likely someone else has thought about it too (or already).

In the future, as I learn more about this remarkable field, I will try to teach what I learn and think worth passing on. I was a teacher for about 20 years, so I think I can do a good work at that.

The amount of sharing and good teachings here in this forum is to be commended.

And so, I would like to please ask everyone interested, to continue this exchange of ideas, with a cool head.

Many thanks!!!

EF

123
To add comments, please log in or register