Change color candle based on histogram conditions


Category:
0
0

Hello Hahn,

I was wondering if you can help me set up candle colors based on  the following conditions being met of the two oscillators.

  1. When the Awesome Oscillator and AccelerationDecelerationOsc histogram are green then candle is green.
  2. When the Awesome Oscillator and AccelerationDecelerationOsc histogram are red then candle is Red.
  3. When the Awesome Oscillator and AccelerationDecelerationOsc histogram are mismatched  then candle is yellow.

 

Thank you so much Hahn. Hope all is well. Here is the code below.

Awesome Oscillator:

#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;
declare zerobase;

plot AO = Average(hl2, 5) – Average(hl2, 34);
plot Zero = 0;

AO.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AO.SetLineWeight(3);
AO.DefineColor(“Up”, Color.UPTICK);
AO.DefineColor(“Down”, Color.DOWNTICK);
AO.AssignValueColor(if AO > AO[1] then AO.color(“Up”) else if AO < AO[1] then AO.color(“Down”) else GetColor(1));
Zero.SetDefaultColor(GetColor(5));

 

AccelerationDecelerationOsc

#
# TD Ameritrade IP Company, Inc. (c) 2010-2019
#

declare lower;

def AO = AwesomeOscillator();

plot AC = AO – Average(AO, 5);
plot ZeroLine = 0;

AC.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AC.SetLineWeight(3);
AC.DefineColor(“Up”, Color.UPTICK);
AC.DefineColor(“Down”, Color.DOWNTICK);
AC.AssignValueColor(if AC > AC[1] then AC.color(“Up”) else if AC < AC[1] then AC.color(“Down”) else GetColor(1));
ZeroLine.SetDefaultColor(GetColor(5));

 

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on August 29, 2019 5:31 pm
349 views
0
Private answer

Since you did not supply any code showing that you tried to do this on your own I will simply provide the solution. If you are trying to learn how to do this, be sure to include your own best attempt along with your request.

Here is the code. Screenshot below shows the result:

def ao = Average(hl2, 5) - Average(hl2, 34);
def ac = ao - Average(ao, 5);
def colorGreen = ao > ao[1] and ac > ac[1];
def colorRed = ao < ao[1] and ac < ac[1];
def colorFlat = !colorGreen and !colorRed;
DefineGlobalColor("Up", Color.GREEN);
DefineGlobalColor("Down", Color.RED);
DefineGlobalColor("Flat", Color.YELLOW);
AssignPriceColor(if colorGreen then GlobalColor("Up") else if colorRed then GlobalColor("Down") else GlobalColor("Flat"));

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on August 31, 2019 11:59 am