MTF Previous Week Open / Close

Buckbull

Active member
I've had this script for a while, its very handy.
It plots the previous week candle High and low on smaller time frame.
Could someone add in the Open and Close as well?
Thanks

Ruby:
input ShowTodayOnly = yes;

def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay();

plot HighLW = if !today then Double.NaN else high(period = "week")[1];
     HighLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot LowLW = if !today then Double.NaN else low(period = "week")[1];
     LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

http://tos.mx/!jUnRKf7U
 
Last edited by a moderator:
Solution
I've had this script for a while, its very handy.
It plots the previous week candle High and low on smaller time frame.
Could someone add in the Open and Close as well?
Thanks

Ruby:
input ShowTodayOnly = yes;

def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay();

plot HighLW = if !today then Double.NaN else high(period = "week")[1];
     HighLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot LowLW = if !today then Double.NaN else low(period = "week")[1];
     LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

http://tos.mx/!jUnRKf7U

added open and close lines.

draws 4 lines, OHLC, over the current bar, from a previous week.
can choose the week, 0 = current week, 1 = 1 week ago,...
cyan line...
I've had this script for a while, its very handy.
It plots the previous week candle High and low on smaller time frame.
Could someone add in the Open and Close as well?
Thanks

Ruby:
input ShowTodayOnly = yes;

def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay();

plot HighLW = if !today then Double.NaN else high(period = "week")[1];
     HighLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot LowLW = if !today then Double.NaN else low(period = "week")[1];
     LowLW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

http://tos.mx/!jUnRKf7U

added open and close lines.

draws 4 lines, OHLC, over the current bar, from a previous week.
can choose the week, 0 = current week, 1 = 1 week ago,...
cyan line is open. yellow line is close.

used addchart() to draw a candle after the last candle, to represent the weeks data.
a cyan candle is rising. a purple candle is falling.

a label shows the week offset.

Code:
#prev_week_mtf

#https://usethinkscript.com/threads/mtf-previous-week-open-close.19623/
#MTF Previous Week Open / Close

def na = double.nan;
def bn = barnumber();

input ShowTodayOnly = yes;
input week_offset = 1;
def today = if !ShowTodayOnly then 1 else GetDay() == GetLastDay();

plot HighW = if !today then na else high(period = "week")[week_offset];
HighW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
highW.SetDefaultColor(Color.gray);

plot LowW = if !today then na else low(period = "week")[week_offset];
LowW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
lowW.SetDefaultColor(Color.gray);

plot openW = if !today then na else open(period = "week")[week_offset];
openW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
openW.SetDefaultColor(Color.CYAN);

plot closeW = if !today then na else close(period = "week")[week_offset];
closeW.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
closeW.SetDefaultColor(Color.YELLOW);

AddLabel(1, week_offset + " weeks ago", Color.YELLOW);

input candle_offset = 3;
def x = (!IsNaN(close[candle_offset]) and IsNaN(close[candle_offset - 1]));

def o = openW[candle_offset];
def h = HighW[candle_offset];
def l = LowW[candle_offset];
def c = closeW[candle_offset];

def cond = if x and c >= o then 1 else 0;
def o1 = if cond then if o < c then c else o else na;
def c1 = if cond then if o < c then o else c else na;
#def o1 = if cond then if o < c then o else c else Double.NaN;
#def c1 = if cond then if o < c then c else o else Double.NaN;
# solid green , low to high
#def o1 = if cond then if o < c then l else h else Double.NaN;
#def c1 = if cond then if o < c then h else l else Double.NaN;
def h1 = if cond then h else na;
def l1 = if cond then l else na;


#AddChart(growColor = Color.green, fallColor = Color.green, neutralColor = Color.green, high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);
AddChart(growColor = Color.CYAN, fallColor = Color.GREEN, neutralColor = Color.GREEN, high = h1, low = l1, open = c1, close = o1, type = ChartType.CANDLE);

def cond1 = if x and c < o then 1 else 0;
def o2 = if cond1 then if o < c then c else o else na;
def c2 = if cond1 then if o < c then o else c else na;
def h2 = if cond1 then h else na;
def l2 = if cond1 then l else na;

#AddChart(growColor = Color.red, fallColor = Color.RED, neutralColor = Color.RED, high = h2, low = l2, open = c2, close = o2, type = ChartType.CANDLE);
AddChart(growColor = Color.MAGENTA, fallColor = Color.RED, neutralColor = Color.RED, high = h2, low = l2, open = c2, close = o2, type = ChartType.CANDLE);


#to draw a filled bar with addchart(), with grow color,
#swap these in addchart(),
#set open to lower level and close to higher level. 
#
 

Attachments

  • img1.JPG
    img1.JPG
    50.5 KB · Views: 38
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Thread starter Similar threads Forum Replies Date
R MTF Previous Candle Questions 3
C Previous H/L MTF Questions 2
P MTF Stacked Averages? Questions 0
S MTF Shaded EMA Questions 4
T Repaints MTF EMA Scalper For ThinkOrSwim Questions 1

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
249 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