Hello friends, I'm back with another study. This one automatically plots the Monthly/Weekly/Daily highs, lows, opens and closes. It also automatically plots monthly and weekly fib levels - midpoint, 0.618 from the top to bottom and 0.618 from the bottom to the top. The fib level can be changed via the options. There is so much packed into this one. Many of the levels here are ones that I've been manually marking on charts for some time. I took some inspiration from this study Welkin posted: Daily High/Low/Close and from SpacemanBTC that creates indicators for TradingView. Use it on timeframes less than 4 hrs or hide the daily levels if using on something larger.
This study has loads of options to show/hide different combinations of lines. By default, 'name' bubbles are turned off and appear at the left edge or the start of the timeframe (ie. Monthly bubble appears at the start of the month). You can change the bubbles to show at the right edge but this requires you have an 'Expansion Area' of 5 bars:
All of the other variables are mostly self-explanatory and turn off or on different levels. The only other odd one is the showVertical option that will plot a vertical line at the start of the Month and Week. There is a lot here and I've designed it to be an all-in-one indicator with very little changes required but I will also be working on a smaller version of this that will automatically plot for a single timeframe and could potentially be added to a chart several times. Because there can be so many lines, I've created a color scheme to try to make them subtle and not so aggressive. These can be changed in the global variable section.
I've designed this with the day trader in mind but believe the larger levels may work well for swing trading many different instruments. I will not be adding a scanner for this study and I do not require on. If someone wants one but cannot create one for themselves, I'm sure the amazing community here can help.
One last note. I have mentioned in other threads that thinkscript does not allow you to access the Settlement price via code. For this reason, the 'Close' value will always be slightly different as it is based on the last candle of the day and not the actual Settlement. This cannot be avoided and in general I do not show the 'Close' on my charts. Cheers!
This study has loads of options to show/hide different combinations of lines. By default, 'name' bubbles are turned off and appear at the left edge or the start of the timeframe (ie. Monthly bubble appears at the start of the month). You can change the bubbles to show at the right edge but this requires you have an 'Expansion Area' of 5 bars:
All of the other variables are mostly self-explanatory and turn off or on different levels. The only other odd one is the showVertical option that will plot a vertical line at the start of the Month and Week. There is a lot here and I've designed it to be an all-in-one indicator with very little changes required but I will also be working on a smaller version of this that will automatically plot for a single timeframe and could potentially be added to a chart several times. Because there can be so many lines, I've created a color scheme to try to make them subtle and not so aggressive. These can be changed in the global variable section.
I've designed this with the day trader in mind but believe the larger levels may work well for swing trading many different instruments. I will not be adding a scanner for this study and I do not require on. If someone wants one but cannot create one for themselves, I'm sure the amazing community here can help.
One last note. I have mentioned in other threads that thinkscript does not allow you to access the Settlement price via code. For this reason, the 'Close' value will always be slightly different as it is based on the last candle of the day and not the actual Settlement. This cannot be avoided and in general I do not show the 'Close' on my charts. Cheers!
Code:
# Created by @tony_futures
# Plot Monthly/Weekly/Daily levels along with associated fibs
#hint: This study plot HLOC levels for Monthly and Weekly timeframes
#hint ShowBubblesLeft: Will show the bubbles on the left - turn to no to show on the right
def NAN = Double.NaN;
input addPeriod1 = AggregationPeriod.DAY;
input addPeriod2 = AggregationPeriod.WEEK;
input addPeriod3 = AggregationPeriod.MONTH;
input showOpens = no;
input showCloses = no;
input showDayBubbles = yes;
input showWeeklyBubbles = yes;
input showMonthlyBubbles = yes;
input showDaily = yes;
input showBubblesLeft = yes;
input showValuesInBubbles = no;
input RoundLevel = 0;
input displaceBubbles = 3;
# setup Colors
DefineGlobalColor("lowColor", CreateColor(109, 59, 81));
DefineGlobalColor("highColor", CreateColor(59, 109, 88));
DefineGlobalColor("openColor", CreateColor(169, 169, 169));
DefineGlobalColor("midColor", CreateColor(94, 110, 59));
DefineGlobalColor("fibColor", CreateColor(28, 96, 109));
def Today = if GetLastDay() == GetDay() then 1 else 0;
def showBubbleNow = !IsNaN(close) and IsNaN(close[-1]);
# plot Daily Levels;
plot prevDayOpen = if showDaily and Today and showOpens then open("period"=addPeriod1)[1] else NAN;
plot prevDayLow = if showDaily and Today then low("period"=addPeriod1)[1] else NAN;
plot prevDayHigh = if showDaily and Today then high("period"=addPeriod1)[1] else NAN;
#currentOpen.SetDefaultColor(Color.WHITE);
prevDayLow.SetDefaultColor(GlobalColor("lowColor"));
prevDayLow.hideBubble();
prevDayHigh.SetDefaultColor(GlobalColor("highColor"));
prevDayHigh.hideBubble();
prevDayOpen.SetDefaultColor(GlobalColor("openColor"));
prevDayOpen.hideBubble();
AddChartBubble(showDayBubbles and showOpens and !showBubblesLeft and showBubbleNow[displaceBubbles], prevDayOpen[1] , if showValuesInBubbles then "YDay Open: " + prevDayOpen[1] else "YDay Open", GlobalColor("openColor"), yes);
AddChartBubble(showDayBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], prevDayLow[1], if showValuesInBubbles then "YDay Low: " + prevDayLow[1] else "YDay Low", GlobalColor("lowColor"), no);
AddChartBubble(showDayBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], prevDayHigh[1], if showValuesInBubbles then "YDay High: " + prevDayHigh[1] else "YDay High", GlobalColor("highColor"), yes);
AddChartBubble(showDayBubbles and showOpens and showBubblesLeft and Today and !Today[1], prevDayOpen[1] , if showValuesInBubbles then "YDay Open: " + prevDayOpen[1] else "YDay Open", GlobalColor("openColor"), yes);
AddChartBubble(showDayBubbles and !showBubblesLeft and Today and !Today[1], prevDayLow[1], if showValuesInBubbles then "YDay Low: " + prevDayLow[1] else "YDay Low", GlobalColor("lowColor"), no);
AddChartBubble(showDayBubbles and !showBubblesLeft and Today and !Today[1], prevDayHigh[1], if showValuesInBubbles then "YDay High: " + prevDayHigh[1] else "YDay High", GlobalColor("highColor"), yes);
# Weekly Levels
def ThisWeek = if GetLastWeek() == GetWeek() then yes else 0;
plot prevWeekOpen = if ThisWeek and showOpens then open("period"=addPeriod2)[1] else NAN;
plot prevWeekClose = if ThisWeek and showCloses then close("period"=addPeriod2)[1] else NAN;
plot prevWeekLow = if ThisWeek then low("period"=addPeriod2)[1] else NAN;
plot prevWeekHigh = if ThisWeek then high("period"=addPeriod2)[1] else NAN;
prevweekLow.SetDefaultColor(GlobalColor("lowColor"));
prevWeekLow.hideBubble();
prevWeekHigh.SetDefaultColor(GlobalColor("highColor"));
prevWeekHigh.hideBubble();
prevWeekOpen.SetDefaultColor(GlobalColor("openColor"));
prevWeekOpen.hideBubble();
prevWeekClose.SetDefaultColor(GlobalColor("openColor"));
prevWeekClose.hideBubble();
AddChartBubble(showOpens and showWeeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], prevWeekOpen, if showValuesInBubbles then "Prev Weekly Open: " + prevWeekOpen else "Prev Week Open", GlobalColor("openColor"), yes);
AddChartBubble(showWeeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles],PrevWeekLow, if showValuesInBubbles then "Weekly Low: " + PrevWeekLow else "Prev Weekly Low", GlobalColor("lowColor"), no);
AddChartBubble(showWeeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], PrevWeekHigh, if showValuesInBubbles then "Weekly High: " + PrevWeekHigh else "Prev Weekly High", GlobalColor("highColor"), yes);
AddChartBubble(showOpens and showWeeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1], prevWeekOpen, if showValuesInBubbles then "Prev Weekly Open: " + prevWeekOpen else "Prev Week Open", GlobalColor("openColor"), yes);
AddChartBubble(showWeeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1],PrevWeekLow, if showValuesInBubbles then "Weekly Low: " + PrevWeekLow else "Prev Weekly Low", GlobalColor("lowColor"), no);
AddChartBubble(showWeeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1], PrevWeekHigh, if showValuesInBubbles then "Weekly High: " + PrevWeekHigh else "Prev Weekly High", GlobalColor("highColor"), yes);
# Monthly Levels
input showMonthly = yes;
def ThisMonth = GetLastMonth() == GetMonth();
def prevMoOpen = open("period"=addPeriod3)[1];
plot prevMonthOpen = if showMonthly and showOpens and ThisMonth then prevMoOpen else NAN;
def prevMoClose = close("period"=addPeriod3)[1];
plot prevMonthClose = if showMonthly and showOpens and ThisMonth then prevMoClose else NAN;
plot prevMonthLow = if showMonthly and ThisMonth then low("period"=addPeriod3)[1] else NAN;
plot prevMonthHigh = if showMonthly and ThisMonth then high("period"=addPeriod3)[1] else NAN;
prevMonthLow.SetDefaultColor(GlobalColor("lowColor"));
prevMonthLow.hideBubble();
prevMonthHigh.SetDefaultColor(GlobalColor("highColor"));
prevMonthHigh.hideBubble();
prevMonthOpen.SetDefaultColor(GlobalColor("openColor"));
prevMonthOpen.hideBubble();
prevMonthClose.SetDefaultColor(GlobalColor("openColor"));
prevMonthClose.hideBubble();
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], prevMonthOpen, if showValuesInBubbles then "Prev Monthly Open: " + prevMonthOpen else "Prev Monthly Open", GlobalColor("openColor"), yes);
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles],PrevMonthLow, if showValuesInBubbles then "Prev Monthly Low: " + PrevMonthLow else "Prev Monthly Low", GlobalColor("lowColor"), no);
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], PrevMonthHigh, if showValuesInBubbles then "Prev Monthly High: " + PrevMonthHigh else "Prev Monthly High", GlobalColor("highColor"), yes);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1], prevMonthOpen, if showValuesInBubbles then "Prev Monthly Open: " + prevMonthOpen else "Prev Monthly Open", GlobalColor("openColor"), yes);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1],PrevMonthLow, if showValuesInBubbles then "Prev Monthly Low: " + PrevMonthLow else "Prev Monthly Low", GlobalColor("lowColor"), no);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1], PrevMonthHigh, if showValuesInBubbles then "Prev Monthly High: " + PrevMonthHigh else "Prev Monthly High", GlobalColor("highColor"), yes);
input showVertical = yes;
AddVerticalLine(showVertical and thisMonth and !thisMonth[1], " Month Start", GlobalColor("openColor"));
AddVerticalLine(showVertical and thisWeek and !thisWeek[1], " Week Start", GlobalColor("openColor"));
# monthly fibs
input showMonthlyFibs = yes;
input monthlyFibAmt = 0.618;
def monthlyFib1 = Round(PrevMonthLow + ((PrevMonthHigh - PrevMonthLow) * monthlyFibAmt),RoundLevel);
plot monthlyFib1Line = if showMonthly and showMonthlyFibs and thisMonth then monthlyFib1 else NAN;
monthlyFib1Line.setDefaultColor(GlobalColor("fibColor"));
monthlyFib1Line.hideBubble();
def monthlyFib2 = Round(PrevMonthHigh - ((PrevMonthHigh - PrevMonthLow) * monthlyFibAmt),RoundLevel);
plot monthlyFib2Line = if showMonthly and showMonthlyFibs and thisMonth then monthlyFib2 else NAN;
monthlyFib2Line.setDefaultColor(GlobalColor("fibColor"));
monthlyFib2Line.hideBubble();
def monthlyMid = Round(PrevMonthHigh - ((PrevMonthHigh - PrevMonthLow) /2),RoundLevel);
plot monthlyMidLine = if showMonthly and showMonthlyFibs and thisMonth then monthlyMid else NAN;
monthlyMidLine.setDefaultColor(GlobalColor("midColor"));
monthlyMidLine.hideBubble();
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], monthlyFib1, if showValuesInBubbles then "Monthly Fib 1: " + monthlyFib1 else "Monthly Fib 1", GlobalColor("fibColor"), no);
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], monthlyFib2, if showValuesInBubbles then "Monthly Fib 2: " + monthlyFib2 else "Monthly Fib 2", GlobalColor("fibColor"), no);
AddChartBubble(showMonthlyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], monthlyMid, if showValuesInBubbles then "Monthly Mid: " + monthlyMid else "Monthly Mid", GlobalColor("midColor"), no);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1], monthlyFib1, if showValuesInBubbles then "Monthly Fib 1: " + monthlyFib1 else "Monthly Fib 1", GlobalColor("fibColor"), no);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1],monthlyFib2, if showValuesInBubbles then "Monthly Fib 2: " + monthlyFib2 else "Monthly Fib 2", GlobalColor("fibColor"), no);
AddChartBubble(showMonthlyBubbles and showBubblesLeft and thisMonth and !thisMonth[1], monthlyMid, if showValuesInBubbles then "Monthly Mid: " + monthlyMid else "Monthly Mid", GlobalColor("midColor"), no);
# weekly fibs
input showWeeklyFibs = yes;
input weeklyFibAmt = 0.618;
def weeklyFib1 = Round(PrevWeekLow + ((PrevWeekHigh - PrevWeekLow) * weeklyFibAmt),RoundLevel);
plot weeklyFib1Line = if showWeeklyFibs and thisWeek then weeklyFib1 else NAN;
weeklyFib1Line.setDefaultColor(GlobalColor("fibColor"));
weeklyFib1Line.hideBubble();
def weeklyFib2 = Round(PrevWeekHigh - ((PrevWeekHigh - PrevWeekLow) * weeklyFibAmt),RoundLevel);
plot weeklyFib2Line = if showWeeklyFibs and thisWeek then weeklyFib2 else NAN;
weeklyFib2Line.setDefaultColor(GlobalColor("fibColor"));
weeklyFib2Line.hideBubble();
def weeklyMid = Round(PrevWeekHigh - ((PrevWeekHigh - PrevWeekLow) /2),RoundLevel);
plot weeklyMidLine = if showWeeklyFibs and thisWeek then weeklyMid else NAN;
weeklyMidLine.setDefaultColor(GlobalColor("midColor"));
weeklyMidLine.hideBubble();
AddChartBubble(showweeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], weeklyFib1, if showValuesInBubbles then "weekly Fib 1: " + weeklyFib1 else "weekly Fib 1", GlobalColor("fibColor"), no);
AddChartBubble(showweeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], weeklyFib2, if showValuesInBubbles then "weekly Fib 2: " + weeklyFib2 else "weekly Fib 2", GlobalColor("fibColor"), no);
AddChartBubble(showweeklyBubbles and !showBubblesLeft and showBubbleNow[displaceBubbles], weeklyMid, if showValuesInBubbles then "weekly Mid: " + weeklyMid else "weekly Mid", GlobalColor("midColor"), no);
AddChartBubble(showweeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1], weeklyFib1, if showValuesInBubbles then "weekly Fib 1: " + weeklyFib1 else "weekly Fib 1", GlobalColor("fibColor"), no);
AddChartBubble(showweeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1],weeklyFib2, if showValuesInBubbles then "weekly Fib 2: " + weeklyFib2 else "weekly Fib 2", GlobalColor("fibColor"), no);
AddChartBubble(showweeklyBubbles and showBubblesLeft and thisWeek and !thisWeek[1], weeklyMid, if showValuesInBubbles then "weekly Mid: " + weeklyFib1 else "weekly Mid", GlobalColor("midColor"), no);
Last edited: