# Showing previous month high on daily chart

#### bvesco

##### New member
Trying to learn how to reference data from other aggregation periods. Getting the previous month with [1] seems to only get the month from the previous candle. This very simple code and screenshot are maybe showing a clearer explanation. I would expect that MH[1] would have returned a value of 140.18 because that was last month's high. Instead, MH and MH[1] are both returning this month's high. Is there a reliable way to get last month's high? I did try searching the forums and the ThinkScript manual but both places seem to suggest MH[1] is the correct way and should have worked.

Code:
``````def MONTH = AggregationPeriod.MONTH;

def monthHigh = high(period = MONTH);

AddLabel(yes, "MH0: " + monthHigh + ", MH1: " + monthHigh[1], Color.WHITE);``````

### SOLVED:

(thanks @generic)
Code:
``````def MH = high (period = MONTH);
def MH1 = high (period = MONTH)[1];

# MH[1] is NOT equal to MH1``````

Last edited:
Solution
@bvesco Add another line specific for MH1. Not sure why this is but I think it has something to do with how thinkscript handles agg above daily.
Code:
``def mh1 = high(period = month)[1];``
@bvesco Add another line specific for MH1. Not sure why this is but I think it has something to do with how thinkscript handles agg above daily.
Code:
``def mh1 = high(period = month)[1];``

@bvesco What error is the circled "!" in the upper left corner of your chart saying when you click on it...??? I think the idea @generic provided should help...

Thanks everyone for the help. Indeed these are different things:

Code:
``````def MH = high (period = MONTH);
def MH1 = high (period = MONTH)[1];

# MH[1] is NOT equal to MH1``````

At least this is true if you are not on the monthly chart itself. MH[1] seems to give the monthly price of the previous candle on the current chart. I suppose if you are on the very first candle of the month they would be the same but as soon as you print a second candle in the same month it becomes incorrect.

@rad14733, good eye on the script error but that's for a different script I had loaded and not related to this one.

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
206 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?