Converting Custom MACD Script To Use With MT4 API

 

Hi All,

I'm new to MT4 and have been really struggling to convert a short MACD scrip to use a custom indicator with the MT4 API. The script below if for a MACD crossover and histogram chart similar to MT4's default one, however the histogram is color coded to indicate if the %K line is positive or negative and also indicates if %K is trending higher or lower, any assistance would be very much appreciated as my frustration has reached boiling point.

Many thanks in advance.

Conor.

<-------------------------------------------------------------------------------------------------------->
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input AverageType = {SMA, default EMA};

plot Value;
plot Avg;
switch (AverageType) {
case SMA:
    Value = Average(close, fastLength) - Average(close, slowLength);
    Avg = Average(Value, MACDLength);
case EMA:
    Value = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
    Avg = ExpAverage(Value, MACDLength);
}

plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));
 

  1. For large amounts of code, attach it
  2. Use this and you would have found this
 
Many thanks for the feed back. this thread in now closed
 
conord:
Many thanks for the feed back. this thread in now closed

You can't close a thread . . .   and next time . . .

Use SRC