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.