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
Adrian Choong
 
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

declare hide_on_intraday;

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,

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


declare hide_on_intraday;

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.
 

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