Hi friends,
This study is similar to one I've done earlier (Multi-timeframe HLOC) but is using a candle overlay vs plotting lines for higher timeframe candles. I got the inspiration after seeing a new Nephew Sam study on TradingView and gave me an excuse to try something new.
This uses the AddChart function to show previous daily or weekly candles. The relevance of these levels are something I've highlighted before: Larger TF
HLOCs
How to use this study? I add this to my charts twice. Once for weekly and once for daily. You can choose to show only the previous day or all previous. And you have some options for extending HLOC lines out from the candle as shown in the upper right on the chart above. These provide a handy visual for shorter term trading. One last thing to note is that if your expansion area is set large enough, you will see the current larger timeframe candle to the right of the chart. The determination of when the day or week changes might be a bit messy. Feedback is welcomed!
This study is similar to one I've done earlier (Multi-timeframe HLOC) but is using a candle overlay vs plotting lines for higher timeframe candles. I got the inspiration after seeing a new Nephew Sam study on TradingView and gave me an excuse to try something new.
This uses the AddChart function to show previous daily or weekly candles. The relevance of these levels are something I've highlighted before: Larger TF
HLOCs
How to use this study? I add this to my charts twice. Once for weekly and once for daily. You can choose to show only the previous day or all previous. And you have some options for extending HLOC lines out from the candle as shown in the upper right on the chart above. These provide a handy visual for shorter term trading. One last thing to note is that if your expansion area is set large enough, you will see the current larger timeframe candle to the right of the chart. The determination of when the day or week changes might be a bit messy. Feedback is welcomed!
Ruby:
# Created by @tony_futures
# Display an overlay of previous daily or weekly candles
#hint: This study plot HLOC levels for prior candles on a larger timeframe
def NAN = Double.NaN;
input aggPeriod1 = AggregationPeriod.DAY;
input showOpens = no;
input showCloses = no;
input showExtensions = no;
input oneDayOnly = yes;
def xO = open(period = aggPeriod1)[1];
def xH = high(period = aggPeriod1)[1];
def xL = low(period = aggPeriod1)[1];
def xC = close(period = aggPeriod1)[1];
def isUP = xO < xC;
def isDN = xO > xC;
def isDoji = xO == xC;
# setup Colors
DefineGlobalColor("lowColor", CreateColor(109, 59, 81));
DefineGlobalColor("highColor", CreateColor(59, 109, 88));
DefineGlobalColor("openColor", CreateColor(169, 169, 169));
DefineGlobalColor("greenCandle", CreateColor(105,105,105));
DefineGlobalColor("redCandle", CreateColor(160,82,45));
def Today = if GetLastDay() == GetDay() then 1 else 0;
plot prevDayOpen = if showExtensions and Today and showOpens then xO else NAN;
plot prevDayLow = if showExtensions and Today then xL else NAN;
plot prevDayHigh = if showExtensions and Today then xH else NAN;
prevDayLow.SetDefaultColor(GlobalColor("lowColor"));
prevDayLow.hideBubble();
prevDayHigh.SetDefaultColor(GlobalColor("highColor"));
prevDayHigh.hideBubble();
prevDayOpen.SetDefaultColor(GlobalColor("openColor"));
prevDayOpen.hideBubble();
plot prevDayClose = if showExtensions and Today and showCloses then xC else NAN;
prevDayClose.SetDefaultColor(GlobalColor("openColor"));
prevDayClose.hideBubble();
def thisDay = getDay();
def thisWeek = getWeek();
def dayChange = thisDay[1] != thisDay;
def weekChange = thisWeek[1] != thisWeek;
def printCandle = if aggPeriod1 == AGGregationPeriod.WEEK then weekChange else if oneDayOnly then today and !today[1] else dayChange;
def candleHigh = if printCandle and isUp then xH else NAN;
def candleLow = if printCandle and isUp then xL else NAN;
def candleOpen = if printCandle and isUp then xO else NAN;
def candleClose = if printCandle and isUp then xC else NAN;
def candleHigh2 = if printCandle and !isUp then xH else NAN;
def candleLow2 = if printCandle and !isUp then xL else NAN;
def candleOpen2 = if printCandle and !isUp then xO else NAN;
def candleClose2 = if printCandle and !isUp then xC else NAN;
AddChart(candleHigh, candleLow, candleOpen, candleClose, ChartType.CANDLE, GlobalColor("greenCandle"));
AddChart(candleHigh2, candleLow2, candleOpen2, candleClose2, ChartType.CANDLE, GlobalColor("redCandle"));
input showWeeklyBubble = no;
def showBubble = showWeeklyBubble and weekChange and aggPeriod1 == AGGRegationPeriod.WEEK;
AddChartBubble(showBubble,xL,"Week",Color.WHITE,no);