Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Quad), 755 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Self-defined MACD #463452
12/04/16 22:26
12/04/16 22:26
Joined: Nov 2016
Posts: 5
M
mey Offline OP
Newbie
mey  Offline OP
Newbie
M

Joined: Nov 2016
Posts: 5
Dear community,

I am trying to define my own MACD, because I get huge signal deviations from Zorro’s pre-defined rMACD compared with that from ProRealTime.

Sounds easy to solve, but I got even stuck with declaration and definition of the pointer variables as a newbee in C.

Could anybody help me here please?

Here is the code from ProRealTime which I want to implement in lite-C:

myMAFastLength = ExponentialAverage[FastLength](close)
myMASlowLength = ExponentialAverage[SlowLength](close)
myMACD = myMAFastLength - myMASlowLength //MACD line
myMACDTrigger = ExponentialAverage[MACDTriggerLength](myMACD) //MACD signal line)
MACDHist = myMACD - myMACDTrigger

This is the definition for the implemented Zorro MACD:

Instead calculation of MACD use the implemented function
MACD(vars Data, int FastPeriod, int SlowPeriod, int SignalPeriod)
rMACD = EMA(Data,FastPeriod)-EMA(Data,SlowPeriod);
rMACDSignal = EMA(rMACD,SignalPeriod);
rMACDHist = rMACD - rMACDSignal;
Results in rMACD, rMACDSignal, rMACDHist. Returns: rMACD.
Parameters: FastPeriod (time period for the fast MA), SlowPeriod (time period for the slow MA), SignalPeriod (time period for smoothing the signal line).

Implementation:
MACD(Price,FastPeriod,SlowPeriod,SignalPeriod);

vars MACDLine = series(rMACD);
vars SignalLine = series(rMACDSignal);
vars Hist = series(rMACDHist);


Here's my trial for implementation:

int
FastPeriod = 12,
SlowPeriod = 26,
SignalPeriod = 9;

vars Price = series(price());
vars myMASlowLength = series(EMA(Price,SlowPeriod));
vars myMAFastLength = series(EMA(Price,FastPeriod));
vars MyMACD = series(EMA(Price,FastPeriod) - EMA(Price,SlowPeriod)); //myMAFastLength - myMASlowLength;
//why does the following not work for MyMACD:?
// vars MyMACD = myMAFastLength – myMASlowLength;

vars MySignalline = series(EMA(MyMACD,SignalPeriod));
vars MyHist = series();

// Calculate the slow EMA.
myMASlowLength = series(EMA(Price,SlowPeriod));

// Calculate the fast EMA.
myMAFastLength = series(EMA(Price,FastPeriod));

// Calculate (fast EMA) - (slow EMA) --> MyMACD
MyMACD = myMAFastLength - myMASlowLength;

Here I get first error message: Syntax error: Wrong type SUB:POINTER:POINTER:POINTER
< MyMACD = myMAFastLength - myMASlowLength; >

// Calculate the signal/trigger line.
MySignalline = EMA(MyMACD,SignalPeriod);

// Calculate the histogram.
MyHist = MyMACD - MySignalline;


Thanks so much for any help in advance.

Re: Self-defined MACD [Re: mey] #463462
12/05/16 10:46
12/05/16 10:46
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's not myMAFastLength - myMASlowLength, but myMAFastLength[0] - myMASlowLength[0] for the last value of the series.

Re: Self-defined MACD [Re: jcl] #463464
12/05/16 18:55
12/05/16 18:55
Joined: Nov 2016
Posts: 5
M
mey Offline OP
Newbie
mey  Offline OP
Newbie
M

Joined: Nov 2016
Posts: 5
Hi jcl,
thanks for quick reply.
I changed it to
MyMACD = myMAFastLength[0] - myMASlowLength[0];
but I still receive the same error message and assume,
that my vars declarations are the problem.

I tried also this (which works without error message):
vars MyMACD = series(myMAFastLength[0] - myMASlowLength[0]);
..but then I receive same error again for the MyMACD definition.

What is wrong here?
Thanks so much.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1