Hi again,
I'm back with a twist on a concept I have seen mentioned on Twitter a few times. The idea is to track the percentage change of the 5 biggest stocks in the market as to provide a modified view of market internals. In theory, the movement of the biggest stocks will define the movement of the market and when trending strongly in one direction, the market will follow suit. When divergences occur, one should take note.
This study has two 'modes'. One that visualizes as a histogram that plots the movement of the underlying 'top 5' for each candle:
In the image above, I have the divergence activated to paint the candles when divergence shows up. The other mode is as a moving average:
Using the average might be a bit easier to visually identify divergence as new highs/lows are made. Crossovers might also be useful in identifying trend exhaustion. Both versions will default to adding a label showing the current 'trend'. This can be switched off or can show the actual averages and current trend for more detailed information.
A few notes. The divergence calculation for candle coloring is based on an 'extreme' reading. I have not come up with a great way of standardizing these levels across all timeframes. I have found this works best of a 1 or 2 minute chart where the value is set to 2 or 3. You may have to experiment to come up with a suitable level on different timeframes. In addition, this study references those other 5 tickers so cannot be run on tick or range charts. And finally, because this is using stock tickers, I find it best to run against /ES or /NQ on time charts that do have extended hours turned OFF. As a result, the average portion of the study requires a few candles at the start of the session before it starts printing:
Give it a whirl and let me know if anyone has thoughts on standardizing the extreme levels or other suggestions for improvement.
I'm back with a twist on a concept I have seen mentioned on Twitter a few times. The idea is to track the percentage change of the 5 biggest stocks in the market as to provide a modified view of market internals. In theory, the movement of the biggest stocks will define the movement of the market and when trending strongly in one direction, the market will follow suit. When divergences occur, one should take note.
This study has two 'modes'. One that visualizes as a histogram that plots the movement of the underlying 'top 5' for each candle:
In the image above, I have the divergence activated to paint the candles when divergence shows up. The other mode is as a moving average:
Using the average might be a bit easier to visually identify divergence as new highs/lows are made. Crossovers might also be useful in identifying trend exhaustion. Both versions will default to adding a label showing the current 'trend'. This can be switched off or can show the actual averages and current trend for more detailed information.
A few notes. The divergence calculation for candle coloring is based on an 'extreme' reading. I have not come up with a great way of standardizing these levels across all timeframes. I have found this works best of a 1 or 2 minute chart where the value is set to 2 or 3. You may have to experiment to come up with a suitable level on different timeframes. In addition, this study references those other 5 tickers so cannot be run on tick or range charts. And finally, because this is using stock tickers, I find it best to run against /ES or /NQ on time charts that do have extended hours turned OFF. As a result, the average portion of the study requires a few candles at the start of the session before it starts printing:
Give it a whirl and let me know if anyone has thoughts on standardizing the extreme levels or other suggestions for improvement.
Ruby:
# created by @tony_futures to identify trend and divergence between the futures and the top 5 tickers
declare lower;
input TICKER = "AAPL";
input TICKER2 = "MSFT";
input TICKER3 = "AMZN";
input TICKER4 = "TSLA";
input TICKER5 = "GOOGL";
def stock1 = close(symbol=TICKER);
def stock2 = close(symbol=TICKER2);
def stock3 = close(symbol=TICKER3);
def stock4 = close(symbol=TICKER4);
def stock5 = close(symbol=TICKER5);
def percentChange = (((stock1 - stock1[1]) + (stock2 - stock2[1]) + (stock3 - stock3[1]) + (stock4 - stock4[1]) + (stock5 - stock5[1])) / (stock1[1] + stock2[1] + stock3[1] + stock4[1] + stock5[1])) * 1000;
input showHisto = yes;
def rth = secondsfromTime(0930)>=0 and secondsfromTime(1600)<0;
plot change = if showHisto and rth then percentChange else Double.NaN;
change.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
DefineGlobalColor("bullish", CreateColor(51,107,135));
DefineGlobalColor("extrabullish", CreateColor(51,107,255));
DefineGlobalColor("bearish", CreateColor(208,150,131));
DefineGlobalColor("extrabearish", CreateColor(255,150,131));
DefineGlobalColor("neutral", Color.GRAY);
plot zero = if showHisto then 0 else Double.NaN;
zero.setDefaultColor(GlobalColor("neutral"));
input extremeLevel = 2;
plot bullish = if showHisto then extremeLevel else Double.NaN;
bullish.setDefaultColor(GlobalColor("neutral"));
bullish.hideBubble();
plot bearish = if showHisto then -extremeLevel else Double.NaN;
bearish.setDefaultColor(GlobalColor("neutral"));
bearish.hideBubble();
change.DefineColor("Up", GlobalColor("bullish"));
change.DefineColor("ExtraUp", GlobalColor("extrabullish"));
change.DefineColor("Down", GlobalColor("bearish"));
change.DefineColor("ExtraDown", GlobalColor("extrabearish"));
change.AssignValueColor(if percentChange > bullish then change.color("ExtraUp") else if percentChange >= 0 then change.color("Up") else if percentChange < bearish then change.color("ExtraDown") else change.color("Down"));
change.hideBubble();
def NYOpen = 0930;
def isNYOpen = secondsFromTime(NYOpen) == 0;
def upAvg = if isNYOpen then 0 else if percentChange > 0 then upAvg[1] + percentChange else upAvg[1];
def downAvg = if isNYOpen then 0 else if percentChange < 0 then downAvg[1] + percentChange else downAvg[1];
def totalAvg = upAvg + downAvg;
def totalAvgChange = totalAvg - totalAvg[5];
def bearishAvg = (totalAvg < (-extremeLevel * 10));
def bullishAvg = (totalAvg > (extremeLevel * 10));
input showLabels = yes;
input showAvgs = no;
AddLabel(showLabels and showAvgs,"Avg: " + Round(totalAvg,1) + " | " + Round((totalAvgChange),1), if bearishAvg then GlobalColor("bearish") else if bullishAvg then GlobalColor("bullish") else GlobalColor("neutral"));
AddLabel(showLabels and !showAvgs and bullishAvg, "Momo Up",GlobalColor("bullish"));
AddLabel(showLabels and !showAvgs and bearishAvg, "Momo Down",GlobalColor("bearish"));
AddLabel(showLabels and !showAvgs and !bullishAvg and !bearishAvg, "Neutral",GlobalColor("neutral"));
bullish.DefineColor("Up", GlobalColor("bullish"));
bullish.DefineColor("Down", GlobalColor("bearish"));
bullish.AssignValueColor(if bullishAvg then bullish.color("Up") else if bearishAvg then bullish.color("Down") else Color.CURRENT);
bearish.DefineColor("Up", GlobalColor("bullish"));
bearish.DefineColor("Down", GlobalColor("bearish"));
bearish.AssignValueColor(if bullishAvg then bullish.color("Up") else if bearishAvg then bullish.color("Down") else Color.CURRENT);
plot avg = if rth and !showHisto then totalAvg else Double.NaN;
avg.setDefaultColor(GlobalColor("bearish"));
plot avgAVG = if !showHisto then Average(totalAvg,10) else Double.NaN;
avgAVG.setDefaultColor(GlobalColor("neutral"));
def isUp = close > open;
def isDown = close < open;
input showArrows = no;
def bullDiv = isDown[2] and isDown[1] and (percentChange[1] > 0) and (percentChange > (extremeLevel/2));
def bearDiv = isUp[2] and isUp[1] and (percentChange[1] < 0) and (percentChange < (-extremeLevel/2));
plot divUp = if showArrows and bullDiv and showHisto then zero else if showArrows and bullDiv then avg else Double.NaN;
divUp.setPaintingStrategy(PaintingStrategy.ARROW_UP);
divUp.setDefaultColor(GlobalColor("neutral"));
plot divDown = if showArrows and bearDiv and showHisto then zero else if showArrows and bearDiv then avg else Double.NaN;
divDown.setPaintingStrategy(PaintingStrategy.ARROW_DOWN);
divDown.setDefaultColor(GlobalColor("neutral"));
input colorCandles = no;
AssignPriceColor(if colorCandles and bullDiv then Color.GREEN else Color.CURRENT);
AssignPriceColor(if colorCandles and bearDiv then Color.RED else Color.CURRENT);
Last edited: