How to put last month open close on today's 5 minute chart in thinkorswim

nebulanectar

New member
Hi usethinkscript community

I am struggling to put last month open close on today's 5 minute chart without loading 20 days 5 minute charts?

Does anyone know to get the last month data points and show in today's 5 minute chart?

It is frustrating to load 20 days 5 minute chart unnecessarily.
 
Try this

plot PMC = close(period = aggregationPeriod.MONTH)[1];
plot PMO = open(period = aggregationPeriod.MONTH)[1];
Thank you that indeed plotted it even on one day 5 min chart.

Can I ask one more thing?

How to label these lines as MO and MC to show on the plot that they are monthly close and open as I will be adding these lines along with other lines and want to visually see the label to prepare for the trade.
 
Thank you that indeed plotted it even on one day 5 min chart.

Can I ask one more thing?

How to label these lines as MO and MC to show on the plot that they are monthly close and open as I will be adding these lines along with other lines and want to visually see the label to prepare for the trade.

This adds lines and optional bubbles

Screenshot-2023-03-15-092133.png
Code:
def PMC = if IsNaN(close(period = AggregationPeriod.MONTH)[1]) then PMC[1] else close(period = AggregationPeriod.MONTH)[1];
def PMO = if IsNaN(open(period = AggregationPeriod.MONTH)[1]) then PMO[1] else open(period = AggregationPeriod.MONTH)[1];

plot MC = PMC;
plot MO = PMO;

input showbubbles = yes;
input bubblemover = 2;
def bm  = bubblemover;
def bm1 = bm + 1;
def mover = IsNaN(close[bm]) and !IsNaN(close[bm1]);
AddChartBubble(showbubbles and mover, MC[bm1], "MC", MC.TakeValueColor());
AddChartBubble(showbubbles and mover, MO[bm1], "MO", MO.TakeValueColor());
 
This adds lines and optional bubbles
@SleepyZ

Thank you so much. I feel so grateful for this. I had struggle to find this out for so long and my chart were always too long to show these monthly levels. Now I can make them more simpler.

I appreciate how kindly and without any expectation of benefit back you solve my problem. I am glad I asked for help.

Thank you!
 
Hello, I was wondering if you could help me move the bubbles to the right in this code. I can't seem to figure it out. i use it to plot the highs and lows of the last 3 days.

Code:
input timeFrame = {default DAY};
input timeFrame2 = {default DAY};
input timeFrame3 = {default DAY};
input ShowChartBubbles = yes;
input showValuesInBubbles = yes;
input showlines= yes;
def nan = Double.NaN;


plot DH1 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame)[2], Double.NaN);
plot DL1 = If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame)[2], Double.NaN);


plot DH2 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame2)[3], Double.NaN);
plot DL2= If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame2)[3], Double.NaN);


plot DH3 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame3)[4], Double.NaN);
plot DL3 = If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame3)[4], Double.NaN);

DH1.SetHiding(!ShowLines);
DH1.SetDefaultColor (Color.YELLOW);
DH1.SetPaintingStrategy(PaintingStrategy.DASHES);
DL1.SetHiding(!ShowLines);
DL1.SetDefaultColor(Color.YELLOW);
DL1.SetPaintingStrategy(PaintingStrategy.DASHES);

DH2.SetHiding(!ShowLines);
DH2.SetDefaultColor (Color.YELLOW);
DH2.SetPaintingStrategy(PaintingStrategy.DASHES);
DL2.SetHiding(!ShowLines);
DL2.SetDefaultColor(Color.YELLOW);
DL2.SetPaintingStrategy(PaintingStrategy.DASHES);

DH3.SetHiding(!ShowLines);
DH3.SetDefaultColor (Color.YELLOW);
DH3.SetPaintingStrategy(PaintingStrategy.DASHES);
DL3.SetHiding(!ShowLines);
DL3.SetDefaultColor(Color.YELLOW);
DL3.SetPaintingStrategy(PaintingStrategy.DASHES);

AddChartBubble(ShowChartBubbles, if IsNaN(DH1[1]) and !IsNaN(DH1) then DH1 else NAN, if showValuesInBubbles then "H $" + DH1 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL1[1]) and !IsNaN(DL1) then DL1 else NAN, if showValuesInBubbles then "L $" + DL1 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DH2[1]) and !IsNaN(DH2) then DH2 else NAN, if showValuesInBubbles then "H $" + DH2 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL2[1]) and !IsNaN(DL2) then DL2 else NAN, if showValuesInBubbles then "L $" + DL2 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DH3[1]) and !IsNaN(DH3) then DH3 else NAN, if showValuesInBubbles then "H $" + DH3 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL3[1]) and !IsNaN(DL3) then DL3 else NAN, if showValuesInBubbles then "L $" + DL3 else "L", Color.Yellow, yes);
 
Last edited by a moderator:
Hello, I was wondering if you could help me move the bubbles to the right in this code. I can't seem to figure it out. i use it to plot the highs and lows of the last 3 days.

input timeFrame = {default DAY};
input timeFrame2 = {default DAY};
input timeFrame3 = {default DAY};
input ShowChartBubbles = yes;
input showValuesInBubbles = yes;
input showlines= yes;
def nan = Double.NaN;


plot DH1 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame)[2], Double.NaN);
plot DL1 = If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame)[2], Double.NaN);


plot DH2 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame2)[3], Double.NaN);
plot DL2= If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame2)[3], Double.NaN);


plot DH3 = If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame3)[4], Double.NaN);
plot DL3 = If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame3)[4], Double.NaN);

DH1.SetHiding(!ShowLines);
DH1.SetDefaultColor (Color.YELLOW);
DH1.SetPaintingStrategy(PaintingStrategy.DASHES);
DL1.SetHiding(!ShowLines);
DL1.SetDefaultColor(Color.YELLOW);
DL1.SetPaintingStrategy(PaintingStrategy.DASHES);

DH2.SetHiding(!ShowLines);
DH2.SetDefaultColor (Color.YELLOW);
DH2.SetPaintingStrategy(PaintingStrategy.DASHES);
DL2.SetHiding(!ShowLines);
DL2.SetDefaultColor(Color.YELLOW);
DL2.SetPaintingStrategy(PaintingStrategy.DASHES);

DH3.SetHiding(!ShowLines);
DH3.SetDefaultColor (Color.YELLOW);
DH3.SetPaintingStrategy(PaintingStrategy.DASHES);
DL3.SetHiding(!ShowLines);
DL3.SetDefaultColor(Color.YELLOW);
DL3.SetPaintingStrategy(PaintingStrategy.DASHES);

AddChartBubble(ShowChartBubbles, if IsNaN(DH1[1]) and !IsNaN(DH1) then DH1 else NAN, if showValuesInBubbles then "H $" + DH1 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL1[1]) and !IsNaN(DL1) then DL1 else NAN, if showValuesInBubbles then "L $" + DL1 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DH2[1]) and !IsNaN(DH2) then DH2 else NAN, if showValuesInBubbles then "H $" + DH2 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL2[1]) and !IsNaN(DL2) then DL2 else NAN, if showValuesInBubbles then "L $" + DL2 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DH3[1]) and !IsNaN(DH3) then DH3 else NAN, if showValuesInBubbles then "H $" + DH3 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(DL3[1]) and !IsNaN(DL3) then DL3 else NAN, if showValuesInBubbles then "L $" + DL3 else "L", Color.Yellow, yes);

See if this helps by placing the bubbles in the right expansion where the input bubblemover will move the bubbles sideways. An input option to show the lines only on today for the last lines wase added.

Screenshot-2023-03-31-072301.png
Code:
input timeFrame = {default DAY};
input timeFrame2 = {default DAY};
input timeFrame3 = {default DAY};
input showonlyontoday = yes;
input ShowChartBubbles = yes;
input showValuesInBubbles = yes;
input showlines= yes;
def nan = Double.NaN;


plot DH1 = if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame)[2], Double.NaN);
plot DL1 = if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame)[2], Double.NaN);


plot DH2 = if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame2)[3], Double.NaN);
plot DL2= if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame2)[3], Double.NaN);


plot DH3 = if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, high(period = timeFrame3)[4], Double.NaN);
plot DL3 = if showonlyontoday and getday()!= getlastday() then nan else If(GetAggregationPeriod() <= AggregationPeriod.day, low(period = timeFrame3)[4], Double.NaN);

DH1.SetHiding(!ShowLines);
DH1.SetDefaultColor (Color.YELLOW);
DH1.SetPaintingStrategy(PaintingStrategy.DASHES);
DL1.SetHiding(!ShowLines);
DL1.SetDefaultColor(Color.YELLOW);
DL1.SetPaintingStrategy(PaintingStrategy.DASHES);

DH2.SetHiding(!ShowLines);
DH2.SetDefaultColor (Color.YELLOW);
DH2.SetPaintingStrategy(PaintingStrategy.DASHES);
DL2.SetHiding(!ShowLines);
DL2.SetDefaultColor(Color.YELLOW);
DL2.SetPaintingStrategy(PaintingStrategy.DASHES);

DH3.SetHiding(!ShowLines);
DH3.SetDefaultColor (Color.YELLOW);
DH3.SetPaintingStrategy(PaintingStrategy.DASHES);
DL3.SetHiding(!ShowLines);
DL3.SetDefaultColor(Color.YELLOW);
DL3.SetPaintingStrategy(PaintingStrategy.DASHES);

input bubblemover = 3;
def b=bubblemover;
def b1=b+1;
AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DH1 else NAN, if showValuesInBubbles then "H2 $" + DH1 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DL1 else NAN, if showValuesInBubbles then "L2 $" + DL1 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DH2 else NAN, if showValuesInBubbles then "H3 $" + DH2 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DL2 else NAN, if showValuesInBubbles then "L3 $" + DL2 else "L", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DH3 else NAN, if showValuesInBubbles then "H4 $" + DH3 else "H", Color.Yellow, yes);

AddChartBubble(ShowChartBubbles, if IsNaN(close[b]) and !IsNaN(close[b1]) then DL3 else NAN, if showValuesInBubbles then "L4 $" + DL3 else "L", Color.Yellow, yes);
 
@SleepyZ
I tried to put previous Quarter Open-High-Low-Close on 20day 15min modifying your previous code.

I couldn't make it work as you can see in the image attached.

It is only marking todays high and close as this Quarter high and close instead of showing me previous quarter OHLC.

Can you help me put these previous quarter lines on todays 20 day chart?
 
@SleepyZ
I tried to put previous Quarter Open-High-Low-Close on 20day 15min modifying your previous code.

I couldn't make it work as you can see in the image attached.

It is only marking todays high and close as this Quarter high and close instead of showing me previous quarter OHLC.

Can you help me put these previous quarter lines on todays 20 day chart?

This is a modification of the codes that others provided above that should do what you requested.

Note that the image is zoomed to show all the previous quarter's lines as AAPL's previous quarter high/close were almost the same, but the low/open were much lower

Screenshot-2023-04-08-102146.png
Code:
input agg = AggregationPeriod.QUARTER;
input offset = 1;
input showtodayonly = yes;

def PMH = if IsNaN(high(period = agg)) then PMH[1] else high(period = agg)[offset];
def PML = if IsNaN(low(period = agg)) then PML[1] else low(period = agg)[offset];
def PMC = if IsNaN(close(period = agg)) then PMC[1] else close(period = agg)[offset];
def PMO = if IsNaN(open(period = agg)) then PMO[1] else open(period = agg)[offset];

plot MH = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else PMH;
plot ML = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else PML;
plot MC = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else PMC;
plot MO = if showtodayonly and GetDay() != GetLastDay() then Double.NaN else PMO;

MH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
ML.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
MO.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input showbubbles = yes;
input bubblemover = 2;
def bm  = bubblemover;
def bm1 = bm + 1;
def mover = IsNaN(close[bm]) and !IsNaN(close[bm1]);
AddChartBubble(showbubbles and mover, MH[bm1],
(if agg == AggregationPeriod.DAY then "D"
else if agg == AggregationPeriod.WEEK then "W"
else if agg == AggregationPeriod.MONTH then "M"
else if agg == AggregationPeriod.QUARTER then "Q"
else if agg == AggregationPeriod.YEAR then "Y"
else "") + "H",
MH.TakeValueColor());
AddChartBubble(showbubbles and mover, ML[bm1],
(if agg == AggregationPeriod.DAY then "D"
else if agg == AggregationPeriod.WEEK then "W"
else if agg == AggregationPeriod.MONTH then "M"
else if agg == AggregationPeriod.QUARTER then "Q"
else if agg == AggregationPeriod.YEAR then "Y"
else "") + "L", ML.TakeValueColor());
AddChartBubble(showbubbles and mover, MC[bm1],
(if agg == AggregationPeriod.DAY then "D"
else if agg == AggregationPeriod.WEEK then "W"
else if agg == AggregationPeriod.MONTH then "M"
else if agg == AggregationPeriod.QUARTER then "Q"
else if agg == AggregationPeriod.YEAR then "Y"
else "") + "C", MC.TakeValueColor());
AddChartBubble(showbubbles and mover, MO[bm1],
(if agg == AggregationPeriod.DAY then "D"
else if agg == AggregationPeriod.WEEK then "W"
else if agg == AggregationPeriod.MONTH then "M"
else if agg == AggregationPeriod.QUARTER then "Q"
else if agg == AggregationPeriod.YEAR then "Y"
else "") + "O", MO.TakeValueColor());
 

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