OHLC (open-high-low-close) Indicator for ThinkorSwim

Hi guys,

I'm running into a wall when tweaking this code to plot HLOC for the previous week and was hoping someone could help. It plots previous OH, but plots LC of the previous week:

Code:
declare upper;

declare hide_on_daily;

input WeeksAgo = 1;#hint WeeksAgo: Excludes today

input PlotHigh = yes;

input PlotLow = yes;

input PlotClose = yes;

input PlotOpen = yes;

input ShowBubbles = no;



def  AdjWeeksAgo = WeeksAgo + 1;#Adjusted to match a true LastDate which includes today



def week = GetWeek();

def lastWeek = GetLastWeek();

def year = GetYear();

def lastYear = GetLastYear();

def yyyymmdd = GetYYYYMMDD();

def lastDate = HighestAll( if week == lastWeek and year == lastYear then yyyymmdd else Double.NaN );

def currentDate = if yyyymmdd < lastDate then yyyymmdd else lastDate;

def tradingWeeksAgo = CountTradingDays( currentDate, lastDate );

def previousWeekPlus = tradingWeeksAgo <= AdjWeeksAgo;

def today = lastDate == currentDate;



script previousPlot {

input today = no;

input previousWeekPlus = no;

input data = high;



plot previousPlot = if previousWeekPlus then

                        HighestAll(if today then data else Double.NaN)

                    else Double.NaN;

}



plot previousHigh = previousPlot(today, plotHigh and previousWeekPlus, high( period = "WEEK" )[WeeksAgo]);

plot PreviousLow = previousPlot(today, plotLow and previousWeekPlus, low( period = "WEEK" )[WeeksAgo]);

plot PreviousClose =  previousPlot(today, plotClose and previousWeekPlus, close( period = "WEEK" )[WeeksAgo]);

plot PreviousOpen =  previousPlot(today, plotOpen and previousWeekPlus, open( period = "WEEK" )[WeeksAgo]);



#=========== Chart Bubbles ===================

def FirstBar = ShowBubbles and today != today[1];

addchartbubble(FirstBar, PreviousHigh, ("High of " + WeeksAgo + " week(s) ago"), color = PreviousHigh.takeValueColor());

addchartbubble(FirstBar, PreviousLow, ("Low of " + WeeksAgo + " week(s) ago"), color = PreviousLow.takeValueColor());

addchartbubble(FirstBar, PreviousClose, ("Close of " + WeeksAgo + " week(s) ago"), color = PreviousClose.takeValueColor());

addchartbubble(FirstBar, PreviousOpen, ("Open of " + WeeksAgo + " week(s) ago"), color = PreviousOpen.takeValueColor());
 
@hydroflask At first glance, and I'm too tired and lazy at the moment to dig deeper, it seems like you have a lot of unnecessary code with all that date calculation. If you just want to plot OHLC for a week ago here's simpler code modeled after TOS's built in DailyHighLow study. And, actually, the built in DailyHighLow and DailyOpen studies take the aggregation period as an input so you could just use those rather than needing anything custom. It's weird they don't have one for close.

Code:
input aggregationPeriod = AggregationPeriod.WEEK;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot PlotOpen;
plot PlotHigh;
plot PlotLow;
plot PlotClose;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    PlotOpen = Double.NaN;
    PlotHigh = Double.NaN;
    PlotLow = Double.NaN;
    PlotClose = Double.NaN;
} else {
    PlotOpen = Highest(open(period = aggregationPeriod)[-displace], length);
    PlotHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    PlotLow = Lowest(low(period = aggregationPeriod)[-displace], length);
    PlotClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

The use of Highest/Lowest in their code seems odd. I'm guessing it's a hack to not have to check for IsNaN(). It doesn't seem to have any real impact.
 
Hi Guys, I have an indicator from here that plots the Prior days Open, High, Low, Close, and overnight Highs/Lows for my futures trading on TOS. Is it possible to somehow program an alert code to send me a sound / phone notification anytime ES, NQ, CL or GC hit the aforementioned pivots so I can quickly check my phone/pc if I want to take the trade or not vs waiting all day and manually checking?

All the best,
B
 

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