# 10-day Highs and Lows for month of January

#### teddybear555

##### New member
Hi,

I'm trying to plot the January opening range based off the highest high and lowest low only for the first 10 trading days of each January.

The code below does not seems to plot correctly. Appreciate if anyone can help out please.

Code:
``````def highrange = highest(high,10)[1];

def lowrange = lowest(low,10)[1];

def JanMonth = if GetMonth() ==1 then 1 else 0;

rec jH = compoundValue(1, if JanMonth then highrange else jH[1], high);

rec jL = compoundValue(1, if JanMonth then lowrange else jL[1], low);

plot JanHigh = jH;

plot JanLow = jL;

JanHigh.setDefaultColor(color.blue);

JanLow.setDefaultColor(color.blue);

JanHigh.setLineWeight(2);

JanLow.setLineWeight(2);``````

Thanks!

Rgds

Last edited by a moderator:
This is not quite what you asked for but here is one way that captures the High/Low for the first 10 days in December. I tested is against tickers like AAPL, FB. This has the method to help you extract some ideas for your project. Load this study on a daily aggregation chart

Code:
``````# High Low First 10 Bars December
# tomsk
# 12.30.2019

def bn = barNumber();
def StartMonthBar = if GetMonth() == 12 and GetMonth()[1] == 11 then bn else StartMonthBar[1];

def PeriodHigh = if StartMonthBar and !StartMonthBar[1]
then high
else if between(bn, StartMonthBar+1, StartMonthBar+10)
then if high > PeriodHigh[1]
then high
else PeriodHigh[1]
else PeriodHigh[1];

def PeriodLow = if StartMonthBar and !StartMonthBar[1]
then low
else if between(bn, StartMonthBar+1, StartMonthBar+10)
then if low < PeriodLow[1]
then low
else PeriodLow[1]
else PeriodLow[1];

AddLabel(1, "December First 10 Bars High = " + PeriodHigh + " Low = " + PeriodLow, Color.Yellow);
# End High Low First 10 Bars December``````

Hi Tomsk,

Thanks and appreciate the code. Will try to adapt it.

Hi Tomsk,

I tried to adapt the code below, I'm able to plot the January highs correctly but not the lows. Able to help out please.
Sorry I need a lot of help with thinkscript.

Code:
``````# High Low First 10 Bars January
# tomsk

def bn = barNumber();
def StartMonthBar = if GetMonth() == 1 and GetMonth()[1] == 12 then bn else StartMonthBar[1];

def PeriodHigh = if StartMonthBar and !StartMonthBar[1]
then high
else if between(bn, StartMonthBar+1, StartMonthBar+10)
then if high > PeriodHigh[1]
then high
else PeriodHigh[1]
else PeriodHigh[1];

def PeriodLow = if StartMonthBar and !StartMonthBar[1]
then low
else if between(bn, StartMonthBar+1, StartMonthBar+10)
then if low < PeriodLow[1]
then low
else PeriodLow[1]
else PeriodLow[1];

Plot JanHigh = PeriodHigh;

Plot JanLow = PeriodLow;

JanHigh.setDefaultColor(color.blue);

JanLow.setDefaultColor(color.blue);

JanHigh.setLineWeight(2);

JanLow.setLineWeight(2);

# End High Low First 10 Bars January``````

I loaded your code and it worked just fine. Just make sure you are running a daily aggregation and under Chart Settings > Time Axis set the time internal to 1 year. Otherwise if you set the time internal to 2 years, the plots seem to be off.

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

Start a new thread and receive assistance from our community.

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