I have a MACD version that is supposedly more accurate. It uses EMA for the signal calculation as well. I tried making the same MACD by modifying the MACD in MT4 but it is not coming up with the same numbers.
Can we port this over to MT4? I've been working on this for a long time, and I've labeled a few pieces but I don't know why they are doing some things.
Here is the *gasp gasp finally* source code to the version of MACD that I'd like to port over, written in Java:
Code:
public static void a(float[] fs, int i, int i_47_, float f, float f_48_,
float f_49_, float[] fs_50_, float[] fs_51_,
float[] fs_52_) { //f[],i,i,f,f,f,f[],f[],f[]
//history, counter1?, counter2?, param1, param2, paramSignal, line1, line2, lineSignal
float f_53_ = 2.0F / (f + 1.0F);
float f_54_ = 2.0F / (f_48_ + 1.0F);
float f_55_ = 2.0F / (f_49_ + 1.0F); //Is this how an EMA is made exponential?
for (int i_56_ = 0; i_56_ <= i && i_56_ < i_47_; i_56_++) //counter less than i_47_
{ //i_56_ is a bar counter? //i is number of bars to count
fs_50_[i_56_] = 0.0F; //is this zeroing out values? YES. Overwritten at end...
fs_51_[i_56_] = 0.0F;
fs_52_[i_56_] = 0.0F;
}
if (i < i_47_)
{
a(fs, i, i_47_, f_54_, (int) f_48_, fs_51_); //Is that an MA? f[],i,i,f,i,f[]
a(fs, i, i_47_, f_53_, (int) f, fs_52_); //Is that an MA? f[],i,i,f,i,f[]
for (int i_57_ = 0; i_57_ < i; i_57_++)
fs_50_[i_57_] = 0.0F; //Zero line on range
for (int i_58_ = i; i_58_ < i_47_; i_58_++)
fs_50_[i_58_] = fs_51_[i_58_] - fs_52_[i_58_]; //Calculates Signal line
a(fs_50_, i + (int) f - 1, i_47_, f_55_, (int) f_49_, fs_51_); //f[],i,i,f,i,f[] //EMA on signal
for ( int i_59_ = 0;
i_59_ < i+ (int)f_48_ - 1;
i_59_++
)
fs_52_[i_59_] = 0.0F;
for ( int i_60_ = i+ (int)f_48_ - 1;
i_60_ < i_47_;
i_60_++
)
fs_52_[i_60_] = fs_50_[i_60_] - fs_51_[i_60_];
int i_61_ = i + (int) f + (int) f_49_ - 1;
for (int i_62_ = 0; i_62_ < i_61_; i_62_++) //WTF?
{
fs_50_[i_62_] = fs_50_[i_61_];
fs_51_[i_62_] = fs_51_[i_61_];
fs_52_[i_62_] = fs_52_[i_61_];
}
}
}
public static float[] a(float[] fs, int i, int i_91_, float f, int i_92_,
float[] fs_93_) { //THIS IS EMA //f[],i,i,f,i,f[]
//a(fs, i, i_47_, f_54_, (int) f_48_, fs_51_);
//a(fs, i, i_47_, f_53_, (int) f, fs_52_);
//a(fs_50_, i + (int) f - 1, i_47_, f_55_, (int) f_49_, fs_51_);
if (fs_93_ == null || fs_93_.length < i_91_)
fs_93_ = new float[i_91_];
if (i >= i_91_)
return fs_93_;
float f_94_ = 0.0F;
for (int i_95_ = i; i_95_ < i + i_92_ && i_95_ < i_91_; i_95_++)
f_94_ += fs[i_95_];
fs_93_[i + i_92_ - 1] = f_94_ / (float) i_92_;
for (int i_96_ = i + i_92_; i_96_ < i_91_; i_96_++)
fs_93_[i_96_] = (1.0F - f) * fs_93_[i_96_ - 1] + f * fs[i_96_];
int i_97_ = i + i_92_ - 1;
for (int i_98_ = 0; i_98_ < i_97_ && i_98_ < i_91_; i_98_++)
fs_93_[i_98_] = fs_93_[i_97_];
return fs_93_;
}