Previous Daily Candle Overlay For ThinkOrSwim

FutureTony

Well-known member
VIP
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.

sLRoKtj.png


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);
 

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
475 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