10-day Highs and Lows for month of January

T

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:
T

tomsk

Well-known member
VIP
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
 
T

teddybear555

New member
Hi Tomsk,

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

teddybear555

New member
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
 
T

tomsk

Well-known member
VIP
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.
 

Similar threads

Top