Market Confluence Direction - Color Bar Heikin Ashi Trend

quijanoj44

Member
VIP
Hi, I would like to create a color bar indicator to compile the Heikin Ashi trend of the top three market drivers tickers for /ES and /NQ which are (AAPL, NVDA, MSFT) and see the overall trend of them. If all are uptrend, then colorBar green, if all are downtrend then color bar red else orange. I have this code, but still needs to fix to do that:

Ruby:
declare upper;

input colorBars = yes;

# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4("AAPL");
def haOpenAAPL = (haOpenAAPL[1] + haCloseAAPL[1]) / 2;
def haTrendUpAAPL = if haCloseAAPL >= haOpenAAPL then 1 else 0;
def haTrendDnAAPL = if haCloseAAPL < haOpenAAPL then 1 else 0;

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4("NVDA");
def haOpenNVDA = (haOpenNVDA[1] + haCloseNVDA[1]) / 2;
def haTrendUpNVDA = if haCloseNVDA >= haOpenNVDA then 1 else 0;
def haTrendDnNVDA = if haCloseNVDA < haOpenNVDA then 1 else 0;


# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4("MSFT");
def haOpenMSFT = (haOpenMSFT[1] + haCloseMSFT[1]) / 2;
def haTrendUpMSFT = if haCloseMSFT >= haOpenMSFT then 1 else 0;
def haTrendDnMSFT = if haCloseMSFT < haOpenMSFT then 1 else 0;


def haSignal =
if ((haTrendUpAAPL == 1 and haTrendUpAAPL[1] == 1) and
(haTrendUpNVDA == 1 and haTrendUpNVDA[1] == 1) and
(haTrendUpMSFT == 1 and haTrendUpMSFT[1] == 1)) then 1
else
if ((haTrendDnAAPL == 1 and haTrendDnAAPL[1] == 1) and
(haTrendDnNVDA == 1 and haTrendDnNVDA[1] == 1) and
(haTrendDnMSFT == 1 and haTrendDnMSFT[1] == 1))
then -1 else 0;

DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.DARK_ORANGE);


AssignPriceColor(if colorBars then
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
  else color.current
);


If someone can help to achieve this will help me a lot. The idea is to see all three top tickers confluence in the same direction so that I can open a trade based on that.

Thanks for your help

@samer800 @chewie76 @rad14733

@MerryDay
 
Last edited:
  • I'm watching this!
Reactions: sum
Solution
Hi, I would like to create a color bar indicator to compile the Heikin Ashi trend of the top three market drivers tickers for /ES and /NQ which are (AAPL, NVDA, MSFT) and see the overall trend of them. If all are uptrend, then colorBar green, if all are downtrend then color bar red else orange. I have this code, but still needs to fix to do that:

Ruby:
declare upper;

input colorBars = yes;

# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4("AAPL");
def haOpenAAPL = (haOpenAAPL[1] + haCloseAAPL[1]) / 2;
def haTrendUpAAPL = if haCloseAAPL >= haOpenAAPL then 1 else 0;
def haTrendDnAAPL = if haCloseAAPL < haOpenAAPL then 1 else 0;

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4("NVDA");
def haOpenNVDA = (haOpenNVDA[1] + haCloseNVDA[1]) / 2;
def...
Hi, I would like to create a color bar indicator to compile the Heikin Ashi trend of the top three market drivers tickers for /ES and /NQ which are (AAPL, NVDA, MSFT) and see the overall trend of them. If all are uptrend, then colorBar green, if all are downtrend then color bar red else orange. I have this code, but still needs to fix to do that:

Ruby:
declare upper;

input colorBars = yes;

# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4("AAPL");
def haOpenAAPL = (haOpenAAPL[1] + haCloseAAPL[1]) / 2;
def haTrendUpAAPL = if haCloseAAPL >= haOpenAAPL then 1 else 0;
def haTrendDnAAPL = if haCloseAAPL < haOpenAAPL then 1 else 0;

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4("NVDA");
def haOpenNVDA = (haOpenNVDA[1] + haCloseNVDA[1]) / 2;
def haTrendUpNVDA = if haCloseNVDA >= haOpenNVDA then 1 else 0;
def haTrendDnNVDA = if haCloseNVDA < haOpenNVDA then 1 else 0;


# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4("MSFT");
def haOpenMSFT = (haOpenMSFT[1] + haCloseMSFT[1]) / 2;
def haTrendUpMSFT = if haCloseMSFT >= haOpenMSFT then 1 else 0;
def haTrendDnMSFT = if haCloseMSFT < haOpenMSFT then 1 else 0;


def haSignal =
if ((haTrendUpAAPL == 1 and haTrendUpAAPL[1] == 1) and
(haTrendUpNVDA == 1 and haTrendUpNVDA[1] == 1) and
(haTrendUpMSFT == 1 and haTrendUpMSFT[1] == 1)) then 1
else
if ((haTrendDnAAPL == 1 and haTrendDnAAPL[1] == 1) and
(haTrendDnNVDA == 1 and haTrendDnNVDA[1] == 1) and
(haTrendDnMSFT == 1 and haTrendDnMSFT[1] == 1))
then -1 else 0;

DefineGlobalColor("UpTrend", Color.GREEN);
DefineGlobalColor("DnTrend", Color.RED);
DefineGlobalColor("Transition", Color.DARK_ORANGE);


AssignPriceColor(if colorBars then
  if haSignal == 1 then GlobalColor("UpTrend")
  else if haSignal == -1 then GlobalColor("DnTrend")
  else GlobalColor("Transition")
  else color.current
);


If someone can help to achieve this will help me a lot. The idea is to see all three top tickers confluence in the same direction so that I can open a trade based on that.

Thanks for your help

@samer800 @chewie76 @rad14733

@MerryDay
check the below:

CSS:
declare upper;

input colorBars = yes;
input symbol1 = "AAPL";
input symbol2 = "NVDA";
input symbol3 = "MSFT";

Script nz {
input src = close;
    def bool = if isNaN(src) then 0 else src;
    plot out = bool;
}
# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4(symbol1);
def haOpenAAPL = if !haOpenAAPL[1] then (high(symbol1) + low(symbol1)) / 2 else (haOpenAAPL[1] + haCloseAAPL[1]) / 2;
def haTrendUpAAPL = (haCloseAAPL > haOpenAAPL) and (haCloseAAPL[1] >= haOpenAAPL[1]);

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4(symbol2);
def haOpenNVDA = if !haOpenNVDA[1] then (high(symbol2) + low(symbol2)) / 2 else (haOpenNVDA[1] + haCloseNVDA[1]) / 2;
def haTrendUpNVDA = haCloseNVDA > haOpenNVDA and (haCloseNVDA[1] >= haOpenNVDA[1]);

# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4(symbol3);
def haOpenMSFT = if !haOpenMSFT[1] then (high(symbol3) + low(symbol3)) / 2 else (haOpenMSFT[1] + haCloseMSFT[1]) / 2;
def haTrendUpMSFT = (haCloseMSFT > haOpenMSFT) and (haCloseMSFT[1] >= haOpenMSFT[1]);


def haSignal = nz(haTrendUpAAPL) + nz(haTrendUpNVDA) + nz(haTrendUpMSFT);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if haSignal == 3 then Color.GREEN else
                 if haSignal == 2 then Color.DARK_GREEN else
                 if haSignal == 1 then Color.DARK_RED else
                 if haSignal == 0 then Color.RED else Color.GRAY);

#-- END of CODE
 
Solution
check the below:

CSS:
declare upper;

input colorBars = yes;
input symbol1 = "AAPL";
input symbol2 = "NVDA";
input symbol3 = "MSFT";

Script nz {
input src = close;
    def bool = if isNaN(src) then 0 else src;
    plot out = bool;
}
# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4(symbol1);
def haOpenAAPL = if !haOpenAAPL[1] then (high(symbol1) + low(symbol1)) / 2 else (haOpenAAPL[1] + haCloseAAPL[1]) / 2;
def haTrendUpAAPL = (haCloseAAPL > haOpenAAPL) and (haCloseAAPL[1] >= haOpenAAPL[1]);

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4(symbol2);
def haOpenNVDA = if !haOpenNVDA[1] then (high(symbol2) + low(symbol2)) / 2 else (haOpenNVDA[1] + haCloseNVDA[1]) / 2;
def haTrendUpNVDA = haCloseNVDA > haOpenNVDA and (haCloseNVDA[1] >= haOpenNVDA[1]);

# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4(symbol3);
def haOpenMSFT = if !haOpenMSFT[1] then (high(symbol3) + low(symbol3)) / 2 else (haOpenMSFT[1] + haCloseMSFT[1]) / 2;
def haTrendUpMSFT = (haCloseMSFT > haOpenMSFT) and (haCloseMSFT[1] >= haOpenMSFT[1]);


def haSignal = nz(haTrendUpAAPL) + nz(haTrendUpNVDA) + nz(haTrendUpMSFT);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if haSignal == 3 then Color.GREEN else
                 if haSignal == 2 then Color.DARK_GREEN else
                 if haSignal == 1 then Color.DARK_RED else
                 if haSignal == 0 then Color.RED else Color.GRAY);

#-- END of CODE
Hi Samer, not sure why everything is red candle when NVDA & MFT are up

1737565958364.png


Can you please check, thanks so much
 

Attachments

  • CleanShot 2025-01-22 at 12.13.28.png
    CleanShot 2025-01-22 at 12.13.28.png
    136.7 KB · Views: 41
  • I'm watching this!
Reactions: sum
Hi Samer, not sure why everything is red candle when NVDA & MFT are up

View attachment 23942

Can you please check, thanks so much
check the below:

CSS:
declare upper;

input colorBars = yes;
input symbol1 = "AAPL";
input symbol2 = "NVDA";
input symbol3 = "MSFT";

Script nz {
input src = close;
    def bool = if isNaN(src) then 0 else src;
    plot out = bool;
}

# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4(symbol1);
def haOpenAAPL = CompoundValue(1, (haOpenAAPL[1] + haCloseAAPL[1]) / 2, (open(symbol1) + close(symbol1)) / 2);
def haTrendUpAAPL = (haCloseAAPL >= haOpenAAPL) and (haCloseAAPL[1] >= haOpenAAPL[1]);

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4(symbol2);
def haOpenNVDA = CompoundValue(1, (haOpenNVDA[1] + haCloseNVDA[1]) / 2, (open(symbol2) + close(symbol2)) / 2);
def haTrendUpNVDA = haCloseNVDA >= haOpenNVDA and (haCloseNVDA[1] >= haOpenNVDA[1]);

# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4(symbol3);
def haOpenMSFT = CompoundValue(1, (haOpenMSFT[1] + haCloseMSFT[1]) / 2, (open(symbol3) + close(symbol3)) / 2);
def haTrendUpMSFT = (haCloseMSFT >= haOpenMSFT) and (haCloseMSFT[1] >= haOpenMSFT[1]);


def haSignal = nz(haTrendUpAAPL) + nz(haTrendUpNVDA) + nz(haTrendUpMSFT);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if haSignal == 3 then Color.GREEN else
                 if haSignal == 2 then Color.DARK_GREEN else
                 if haSignal == 1 then Color.DARK_RED else
                 if haSignal == 0 then Color.RED else Color.GRAY);

#-- END of CODE
 
  • Sad
Reactions: sum
check the below:

CSS:
declare upper;

input colorBars = yes;
input symbol1 = "AAPL";
input symbol2 = "NVDA";
input symbol3 = "MSFT";

Script nz {
input src = close;
    def bool = if isNaN(src) then 0 else src;
    plot out = bool;
}

# APPLE HEIKIN ASHI
def haCloseAAPL = ohlc4(symbol1);
def haOpenAAPL = CompoundValue(1, (haOpenAAPL[1] + haCloseAAPL[1]) / 2, (open(symbol1) + close(symbol1)) / 2);
def haTrendUpAAPL = (haCloseAAPL >= haOpenAAPL) and (haCloseAAPL[1] >= haOpenAAPL[1]);

# NVIDIA  HEIKIN ASHI
def haCloseNVDA = ohlc4(symbol2);
def haOpenNVDA = CompoundValue(1, (haOpenNVDA[1] + haCloseNVDA[1]) / 2, (open(symbol2) + close(symbol2)) / 2);
def haTrendUpNVDA = haCloseNVDA >= haOpenNVDA and (haCloseNVDA[1] >= haOpenNVDA[1]);

# MICROSOFT HEIKIN ASHI
def haCloseMSFT = ohlc4(symbol3);
def haOpenMSFT = CompoundValue(1, (haOpenMSFT[1] + haCloseMSFT[1]) / 2, (open(symbol3) + close(symbol3)) / 2);
def haTrendUpMSFT = (haCloseMSFT >= haOpenMSFT) and (haCloseMSFT[1] >= haOpenMSFT[1]);


def haSignal = nz(haTrendUpAAPL) + nz(haTrendUpNVDA) + nz(haTrendUpMSFT);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if haSignal == 3 then Color.GREEN else
                 if haSignal == 2 then Color.DARK_GREEN else
                 if haSignal == 1 then Color.DARK_RED else
                 if haSignal == 0 then Color.RED else Color.GRAY);

#-- END of CODE
It's still not doing it, when I copied and pasted the new code, it is still giving only red candles, not sure why:

1737737797312.png


Tahnk you for keep helping.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
217 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