MACD with Bollinger Bands Indicator for ThinkorSwim

yellowlogic

New member
VIP
it will not let me load a picture (and Yes I followed the instructions from this site) so I will try and explain what I am looking for help on this for. I wanted to know if anyone could help me with adding arrows. I would like a down arrow on the first dot after the green/yellow bullish dots. I not sure what color it is because I am colorblind. but after the bullish dots turn any color then the bullish color on the next dot show a down arrow. I also want a up arrow for the first dot after a red Dot (Bearish dots) that is no longer Red.


Thanks in advanced and thanks for the help everyone has given me on this site.
 

Trader Raider

Well-known member
VIP
it will not let me load a picture (and Yes I followed the instructions from this site) so I will try and explain what I am looking for help on this for. I wanted to know if anyone could help me with adding arrows. I would like a down arrow on the first dot after the green/yellow bullish dots. I not sure what color it is because I am colorblind. but after the bullish dots turn any color then the bullish color on the next dot show a down arrow. I also want a up arrow for the first dot after a red Dot (Bearish dots) that is no longer Red.


Thanks in advanced and thanks for the help everyone has given me on this site.


@yellowlogic, my dad was colorblind, therefore I can imagine having some difficulty with the indicator. I cannot program arrows in the manner you requested. But maybe there's another workaround? Attached is an image to show what I mean.


On the left, I changed the green bullish dots to black. If you can discern when black is no longer black on a white background, then you will know the bullish color has changed. On the right are the red dots changed to white on a black background. If you can discern when white is no longer white on a black background, then you will know the bearish dots have changed. In other words, if you can find a color that you can discriminate on a white and/or black background, you can customize the dot color accordingly.

Another option may be to change the size of the dot that plots with color change. But that's beyond my coding ability, sorry.

Best wishes and happy trading.
 

s1111

Active member
@yellowlogic I use this macd for arrows. You can use this macd script or use macd BB and use this script just for arrows but turn off all indicators. Hope this helps
Ruby:
#converted from mobisu macd to ppo
# this is actually macd and sqz indicator in one
# added pivots

declare lower;

input fastPeriod = 12; #9/18/6 for 5m
input slowPeriod = 26;
input signalPeriod = 9;
input price = close;
input show = yes;
input agg1 = AggregationPeriod.FIVE_MIN;

def fastEma = ExpAverage( price, fastPeriod );
def slowEma = ExpAverage( price, slowPeriod );
def periodOK = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def _ppo = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal = ExpAverage( _ppo, signalPeriod );

# generic plots wiht colors
plot pmain = _ppo;
pmain.SetDefaultColor( Color.BLUE );
pmain.SetLineWeight(2);
pmain.AssignValueColor(if pmain < 0 and pmain < pmain[1] then Color.RED
else if pmain < 0 and pmain > pmain[1] then Color.DARK_GREEN
else if pmain > 0 and pmain > pmain[1] then Color.GREEN
else Color.DARK_RED);
pmain.HideBubble();

plot mainEma = _signal;
mainEma.SetDefaultColor( Color.RED );
mainEma.HideBubble();
AddCloud(pmain, mainEma, Color.Green, Color.RED);

#diff as histogram
plot diff = _ppo - _signal;
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"));

#mobius divergence calc
def pmainh = CompoundValue(1,
if pmain < 0 then Double.NaN
else if pmain crosses above 0 then pmain
else if pmain > 0 and pmain > pmainh[1]
then pmain else pmainh[1], 0);

def Valueh = CompoundValue(1,
if pmain < 0 then Double.NaN
else if pmain crosses above 0 then high
else if pmain > 0 and high > Valueh[1] then high
else Valueh[1], 0);

plot divLowSignal = if pmain > 0 and high > Valueh[1] and pmain < pmainh[1] then 0
else Double.NaN;
divLowSignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
divLowSignal.SetLineWeight(5);
divLowSignal.SetDefaultColor(Color.dark_orange);

def pmainL = CompoundValue(1, if pmain > 0 then Double.NaN
else if pmain crosses below 0 then pmain
else if pmain < 0 and pmain < pmainl[1] then pmain
else pmainl[1], 0);

def ValueL = CompoundValue(1, if pmain > 0 then Double.NaN
else if pmain crosses below 0 then low
else if pmain < 0 and low < Valuel[1] then low
else Valuel[1], 0);

plot divUpSignall = if pmain < 0 and low < Valuel[1] and pmain > pmainl[1] then 0
else Double.NaN;
divupSignall.SetPaintingStrategy(PaintingStrategy.SQUARES);
divUpSignall.SetLineWeight(5);
divUPSignall.SetDefaultColor(Color.blue);

#zeroline

plot zeroLine = 0;
zeroLine.SetPaintingStrategy(PaintingStrategy.LINE);
zeroLine.SetLineWeight(1);
zeroLine.SetDefaultColor(Color.Gray);

#pivots

def ptrend = pmain;
def prange = 2;
def pivotHigh = if IsNaN(ptrend[-1]) then 0 else Lowest(ptrend, prange)[1] > ptrend and Lowest(ptrend, prange)[-prange] > ptrend ;
def pivotLow = if IsNaN(ptrend[-1]) then 0 else Highest(ptrend, prange)[1] < ptrend and Highest(ptrend, prange)[-prange] < ptrend ;
#study
plot plotPH = if pivotHigh and show then ptrend else Double.NaN;
plotPH.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plotPH.SetDefaultColor(Color.GREEN);

plot phline = if pivotHigh then pmain else Double.NaN;
phline.SetDefaultColor(Color.DARK_GREEN);
phline.EnableApproximation();phline.Hide();
#
plot plotPL = if pivotLow and show then ptrend else Double.NaN;
plotPL.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
plotPL.SetDefaultColor(Color.RED);

plot plline = if pivotLow then pmain else Double.NaN;
plline.SetDefaultColor(Color.RED);
plline.EnableApproximation(); plline.hide();
 
Last edited by a moderator:

s1111

Active member
@Britt95 Great minds think alike! I have been coloring my candles with this indicator and it works great!
Add the following code to the end of the study:
Ruby:
# ########################################################
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;
input paintbar = yes ;

AssignPriceColor(
if !paintbar then Color.CURRENT else
if MACD_Line > BB_Upper then GlobalColor("LabelGreen") else
if MACD_Line < BB_Lower then GlobalColor("LabelRed") else
Color.gray);
sawVrNF.png

HTH

Hi @MerryDay I have quick questions. On your color price, Why is "!" there before paintbar line? 2nd question, is there a way to color candles green or red only after it's above or below zero line? If macd cross but above or below zero line then yellow or something. I'm trying to use this script with your color price mod.
Thanks in advance


#converted from mobisu macd to ppo
# this is actually macd and sqz indicator in one
# added pivots

declare lower;

input fastPeriod = 12; #9/18/6 for 5m
input slowPeriod = 26;
input signalPeriod = 9;
input price = close;
input show = yes;
input agg1 = AggregationPeriod.FIVE_MIN;

def fastEma = ExpAverage( price, fastPeriod );
def slowEma = ExpAverage( price, slowPeriod );
def periodOK = fastPeriod < slowPeriod;
AddLabel( !periodOK, "ERROR: fastPeriod MUST be less than slowPeriod" );
def _ppo = if periodOK then ((fastEma - slowEma) / slowEma) * 100 else 0;
def _signal = ExpAverage( _ppo, signalPeriod );

# generic plots wiht colors
plot pmain = _ppo;
pmain.SetDefaultColor( Color.BLUE );
pmain.SetLineWeight(2);
pmain.AssignValueColor(if pmain < 0 and pmain < pmain[1] then Color.RED
else if pmain < 0 and pmain > pmain[1] then Color.DARK_GREEN
else if pmain > 0 and pmain > pmain[1] then Color.GREEN
else Color.DARK_RED);
pmain.HideBubble();

plot mainEma = _signal;
mainEma.SetDefaultColor( Color.RED );
mainEma.HideBubble();
AddCloud(pmain, mainEma, Color.Green, Color.RED);

#diff as histogram
plot diff = _ppo - _signal;
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"));

#mobius divergence calc
def pmainh = CompoundValue(1,
if pmain < 0 then Double.NaN
else if pmain crosses above 0 then pmain
else if pmain > 0 and pmain > pmainh[1]
then pmain else pmainh[1], 0);

def Valueh = CompoundValue(1,
if pmain < 0 then Double.NaN
else if pmain crosses above 0 then high
else if pmain > 0 and high > Valueh[1] then high
else Valueh[1], 0);

plot divLowSignal = if pmain > 0 and high > Valueh[1] and pmain < pmainh[1] then 0
else Double.NaN;
divLowSignal.SetPaintingStrategy(PaintingStrategy.SQUARES);
divLowSignal.SetLineWeight(5);
divLowSignal.SetDefaultColor(Color.dark_orange);

def pmainL = CompoundValue(1, if pmain > 0 then Double.NaN
else if pmain crosses below 0 then pmain
else if pmain < 0 and pmain < pmainl[1] then pmain
else pmainl[1], 0);

def ValueL = CompoundValue(1, if pmain > 0 then Double.NaN
else if pmain crosses below 0 then low
else if pmain < 0 and low < Valuel[1] then low
else Valuel[1], 0);

plot divUpSignall = if pmain < 0 and low < Valuel[1] and pmain > pmainl[1] then 0
else Double.NaN;
divupSignall.SetPaintingStrategy(PaintingStrategy.SQUARES);
divUpSignall.SetLineWeight(5);
divUPSignall.SetDefaultColor(Color.blue);

#zeroline

plot zeroLine = 0;
zeroLine.SetPaintingStrategy(PaintingStrategy.LINE);
zeroLine.SetLineWeight(1);
zeroLine.SetDefaultColor(Color.Gray);

#pivots

def ptrend = pmain;
def prange = 2;
def pivotHigh = if IsNaN(ptrend[-1]) then 0 else Lowest(ptrend, prange)[1] > ptrend and Lowest(ptrend, prange)[-prange] > ptrend ;
def pivotLow = if IsNaN(ptrend[-1]) then 0 else Highest(ptrend, prange)[1] < ptrend and Highest(ptrend, prange)[-prange] < ptrend ;
#study
plot plotPH = if pivotHigh and show then ptrend else Double.NaN;
plotPH.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
plotPH.SetDefaultColor(Color.GREEN);

plot phline = if pivotHigh then pmain else Double.NaN;
phline.SetDefaultColor(Color.DARK_GREEN);
phline.EnableApproximation();phline.Hide();
#
plot plotPL = if pivotLow and show then ptrend else Double.NaN;
plotPL.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
plotPL.SetDefaultColor(Color.RED);

plot plline = if pivotLow then pmain else Double.NaN;
plline.SetDefaultColor(Color.RED);
plline.EnableApproximation(); plline.hide();
 

Similar threads

Top