MACD Colored Candles?

T

Tom4235

New member
hi everyone!
Is there a code for MACD color coordinated candles for ToS?
 
horserider

horserider

Well-known member
VIP
Someone already did this. Maybe search for it. Here is the code anyway.
Code:
#====== MACD.value is above MACD.avg (signal line)======
input fastLength_1 = 12;
input slowLength_1 = 26;
input MACDLength_1 = 9;
input AverageType_1 = {SMA, default EMA};
def macd_Val_1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Value;
def macd_Avg1 = MACD(fastLength_1, slowLength_1, MACDLength_1, AverageType_1).Avg;
AssignPriceColor(if macd_Val_1 > macd_Avg1 then Color.GREEN else  Color.RED );
#== end ====
 
horserider

horserider

Well-known member
VIP
Should have said so.

Code:
# MACD 4 color_colored candles

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;

plot Diff = MACD(fastLength, slowLength, MACDLength, averageType).Diff;

AssignPriceColor(if Diff >= 0 then if Diff > Diff[1] then color.GREEN else color.DARK_GREEN else if Diff < Diff[1] then color.RED else color.DARK_RED);
 
T

TraderGary

New member
Hello everyone. I'm new here, and I hope I'm posting this request in the appropriate forum/thread.

I'm not a coder but trying to learn some of the basics, and I'm hoping someone can help me with what I thought was going to be a relatively easy add-on to an existing code. What I'm trying to accomplish is to add color plots to the existing MACD in TOS, based on whether the fast line, slow line, and MACD lines are rising or falling.

I copied the existing code from the default MACD, created a new indicator and pasted that code into it, then added the following;

Code:
fastLength.DefineColor("Up", GetColor(1));

fastLength.DefineColor("Down", GetColor(0));

fastLength.AssignValueColor(if fastLength > fastLength [1] then fastLength.color("Up") else fastLength.color("Down"));

slowLength.DefineColor("Up", GetColor(1));

slowLength.DefineColor("Down", GetColor(0));

slowLength.AssignValueColor(if slowLength > slowLength [1] then slowLength.color("Up") else slowLength.color("Down"));

MACDLength.DefineColor("Up", GetColor(1));

MACDLength.DefineColor("Down", GetColor(0));

MACDLength.AssignValueColor(if MACDLength > MACDLength [1] then MACDLength.color("Up") else MACDLength.color("Down"));

Thought it would be fairly straight-forward, but since I know next to nothing about coding, it has turned out to be a challenge and I'm getting multiple errors. I'm hoping one of you experts on here would be able to look at this and tell me what I'm doing wrong?

Thank you so much!

If you would like to see the entire code, here it is;

Code:
declare lower;

input fastLength = 12;

input slowLength = 26;

input MACDLength = 9;

input averageType = AverageType.EXPONENTIAL;

input showBreakoutSignals = no;


plot Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);

plot Avg = MovingAverage(averageType, Value, MACDLength);


plot Diff = Value - Avg;

plot ZeroLine = 0;


plot UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;

plot DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;


UpSignal.SetHiding(!showBreakoutSignals);

DownSignal.SetHiding(!showBreakoutSignals);


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));

UpSignal.SetDefaultColor(Color.UPTICK);

UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

DownSignal.SetDefaultColor(Color.DOWNTICK);

DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

fastLength.SetDefaultColor(GetColor(9));

slowLength.SetDefaultColor(GetColor(5));

MACDLength.SetDefaultColor(GetColor(8));


fastLength.DefineColor("Up", GetColor(1));

fastLength.DefineColor("Down", GetColor(0));

fastLength.AssignValueColor(if fastLength > fastLength [1] then fastLength.color("Up") else fastLength.color("Down"));

slowLength.DefineColor("Up", GetColor(1));

slowLength.DefineColor("Down", GetColor(0));

slowLength.AssignValueColor(if slowLength > slowLength [1] then slowLength.color("Up") else slowLength.color("Down"));

MACDLength.DefineColor("Up", GetColor(1));

MACDLength.DefineColor("Down", GetColor(0));

MACDLength.AssignValueColor(if MACDLength > MACDLength [1] then MACDLength.color("Up") else MACDLength.color("Down"));

FYI, I didn't change any of the code from the existing MACD, but only added the color plots at the end.
 
Last edited by a moderator:
Thread starter Similar threads Forum Replies Date
Vince Field Best Settings for MACD and RSI on 1 Minute Chart? Questions 1
bspratt22 MACD and Stochastic with 3/8 ema Questions 25
E Positive Momentum Divergence on MACD Questions 3
J MACD alert question Questions 5
I MACD scan question Questions 3

Similar threads

Top