paint following two candles after MacD Cross

Atombomb

New member
Hello, I am hoping someone could help me out. I want to script a Indicator but i have no idea how to get it to work. I think it may be too complicated to script for TOS.

Would i be able to paint the following two candles after a MacD Cross over? But only if they close above or below the cross signals open?

So an example would be that when the MacD produces an up signal and the next two candles close above the open of that up signal bar the three bars would be painted Yellow. See Attachment

The three bars in the picture are the ones i would want painted.
 

Attachments

  • Screenshot (14).png
    Screenshot (14).png
    72.2 KB · Views: 89
Solution
Hello, I am hoping someone could help me out. I want to script a Indicator but i have no idea how to get it to work. I think it may be too complicated to script for TOS.

Would i be able to paint the following two candles after a MacD Cross over? But only if they close above or below the cross signals open?

So an example would be that when the MacD produces an up signal and the next two candles close above the open of that up signal bar the three bars would be painted Yellow. See Attachment

The three bars in the picture are the ones i would want painted.

you didn't specify what the upsignal is, so i used the variable in macd.

i changed the color, up signal is cyan and down signal is yellow
this is a modified lower macd...
Hello, I am hoping someone could help me out. I want to script a Indicator but i have no idea how to get it to work. I think it may be too complicated to script for TOS.

Would i be able to paint the following two candles after a MacD Cross over? But only if they close above or below the cross signals open?

So an example would be that when the MacD produces an up signal and the next two candles close above the open of that up signal bar the three bars would be painted Yellow. See Attachment

The three bars in the picture are the ones i would want painted.

you didn't specify what the upsignal is, so i used the variable in macd.

i changed the color, up signal is cyan and down signal is yellow
this is a modified lower macd. it just has the zero line and a diff line.


Code:
# macd_cross_yellow

#https://usethinkscript.com/threads/paint-following-two-candles-after-macd-cross.19152/
#paint following two candles after MacD Cross
# MacD produces an up signal
# the next two candles close above the open of that up signal bar, the three bars would be painted Yellow


# macd
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

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

def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def 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);


def up = if (!isnan(UpSignal) and close[-1] > open and close[-2] > open) or 
(!isnan(UpSignal[1]) and close[0] > open[1] and close[-1] > open[1]) or
(!isnan(UpSignal[2]) and close[1] > open[2] and close[0] > open[2])
then 1 else 0;

def dwn = if (!isnan(downSignal) and close[-1] < open and close[-2] < open) or 
(!isnan(downSignal[1]) and close[0] < open[1] and close[-1] < open[1]) or
(!isnan(downSignal[2]) and close[1] < open[2] and close[0] < open[2])
then 1 else 0;

AssignPriceColor(if up then color.cyan else if dwn then color.yellow else color.current);


addchartbubble(0, 0,
upsignal
, color.yellow, no);
#
 

Attachments

  • Capture.JPG
    Capture.JPG
    67.1 KB · Views: 86
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

you didn't specify what the upsignal is, so i used the variable in macd.

i changed the color, up signal is cyan and down signal is yellow
this is a modified lower macd. it just has the zero line and a diff line.


Code:
# macd_cross_yellow

#https://usethinkscript.com/threads/paint-following-two-candles-after-macd-cross.19152/
#paint following two candles after MacD Cross
# MacD produces an up signal
# the next two candles close above the open of that up signal bar, the three bars would be painted Yellow


# macd
declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

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

def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def 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);


def up = if (!isnan(UpSignal) and close[-1] > open and close[-2] > open) or
(!isnan(UpSignal[1]) and close[0] > open[1] and close[-1] > open[1]) or
(!isnan(UpSignal[2]) and close[1] > open[2] and close[0] > open[2])
then 1 else 0;

def dwn = if (!isnan(downSignal) and close[-1] < open and close[-2] < open) or
(!isnan(downSignal[1]) and close[0] < open[1] and close[-1] < open[1]) or
(!isnan(downSignal[2]) and close[1] < open[2] and close[0] < open[2])
then 1 else 0;

AssignPriceColor(if up then color.cyan else if dwn then color.yellow else color.current);


addchartbubble(0, 0,
upsignal
, color.yellow, no);
#
Thank you very much good sir. That is exactly what i needed! I changed it up a bit for what i needed but it definitely pointed me in the right direction.

Great way to pinpoint the bars that needed the coloring. Genius stuff. I really got to learn this .nan and double.nan stuff. Im not a coder.

Is there a way to code it so that i can choose the bar color as an option in the properties screen? I see you coded it as Cyan or Yellow but it would be cool to have the option per chart without having to change the code.

I tried up.setpaintingstrategy(color.orange) for example and it didnt work.


On another note... why is it that when i upload the study to my chart it opens up extremely compact and i have to zoom in like crazy to see my chart? it all basically comes out as one tight line and then i have to expand it way more than usual.

Screenshot 2024-07-23 231307.png



This is what happens now when i upload the script.
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
420 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top