Self-defined MACD

Posted By: mey

Self-defined MACD - 12/04/16 22:26

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

Re: Self-defined MACD - 12/05/16 10:46

It's not myMAFastLength - myMASlowLength, but myMAFastLength[0] - myMASlowLength[0] for the last value of the series.
Posted By: mey

Re: Self-defined MACD - 12/05/16 18:55

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.
© 2024 lite-C Forums