Quarterly Highs and Lows

DmitryOlk

New member
Plus
Hello!
I'm new to ThinkScript. Thanks to artificial intelligence, I figured out some things, and some things I didn't.
I hope someone can help me write a simple script to
automate the task of drawing simple horizontal lines
(highs and lows) that extend along the entire length of the
corresponding period - quarter (3,6,9,12).

(f) In detail:
If 1= before Friday or Friday, then the next Friday;
If 1= Saturday, then the next Friday = 1+12 (Sunday and 12 days);
If 1= Sunday, then the next Friday = +12 (12 days).

AggregationPeriod :

(f) 4H -> YTD
(f) 12H -> YTD
(f) 1 D -> YTD
1 W -> YTD
1 M -> YTD

Last relevant quarter :
the remaining bars to the actual bar and, accordingly,
the remaining future bars in the current quarter's plot.

code :
Code:
# AggregationPeriod
#
def tf_now = GetAggregationPeriod() ;
#
def tf_4H = AggregationPeriod.FOUR_HOURS ;
# def tf_12H = AggregationPeriod.12_HOURS ;
def tf_day = AggregationPeriod.DAY ;
def tf_week = AggregationPeriod.WEEK ;
def tf_month = AggregationPeriod.MONTH ;
#
def is_tf_4H = ( tf_now == tf_4H ) ;
# def is_tf_12H = ( tf_now == tf_12H ) ;
def is_tf_day = ( tf_now == tf_day ) ;
def is_tf_week = ( tf_now == tf_week ) ;
def is_tf_month = ( tf_now == tf_month ) ;
#



def h = high ;
def l = low ;

def is_active = !IsNaN(h) and !IsNaN(l);

def na = Double.NaN;
def bn = BarNumber ();

def is_real_Bar = !IsNaN(close) and IsNaN(close[-1]); # lastBar
def real_Bar = if IsNaN(close[-1]) then bn else real_Bar [1]; # lastBar
# def numBars = HighestAll( is_real_Bar );

def current_Date = GetYYYYMMDD (); # current date
def current_D = GetDay (); # number current day

def current_W = GetWeek(); # number current week in year
def current_M = GetMonth(); # number current Month in year
def current_Y = GetYear(); # current Year

def current_D_M = GetDayOfMonth( current_Date ); # number day of month ( 1 .. 31 )


# secondFriday in Month of Quarter

def DayWeek = GetDayOfWeek( current_Date ); # number day of week

def secondFridayOffset =
if DayWeek <= 5 then 5 - DayWeek + 7
else
if DayWeek == 6 then
14 # Sat.
else
13 ; # Sun.

def is_Friday = GetDayOfWeek( current_Date ) == 5;

def Quarter_Date =
( current_M == 3 or current_M == 6 or current_M == 9 or current_M == 12 )
and
( current_D_M == secondFridayOffset )
;

# def is_Quarter = Quarter_Date != Quarter_Date [1] ; # ? = + 1 bar

def Quarter_Bn = if Quarter_Date then Bn else Double.NaN;


# secondFridayOffset, day
AddChartBubble( bn == Quarter_Bn , high, " current Quarter_Bn : " + Quarter_Bn , Color.LIGHT_GREEN , 1 );


# plot High/Low
def Ql_High = if Quarter_Date then h else Ql_High[1] ;
def Ql_Low = if Quarter_Date then l else Ql_Low [1] ;

# High
plot q_High = Ql_High;
q_High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_High.SetDefaultColor(Color.YELLOW);

# Quartal Low
plot q_Low = Ql_Low;
q_Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_Low.SetDefaultColor(Color.GREEN);

# vertical Lines befor new Quartal
AddVerticalLine( (real_Bar <1) && Quarter_Date , " n e w Quarter : " + Quarter_Date , Color.ORANGE, Curve.SHORT_DASH);

# end
 

Attachments

  • q.png
    q.png
    225.5 KB · Views: 62
Last edited by a moderator:
Solution
There is a built in DailyHighLow study in ToS that should accomplish what you are asking.

Code:
#
# Charles Schwab & Co. (c) 2011-2025
#

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4))...
There is a built in DailyHighLow study in ToS that should accomplish what you are asking.

Code:
#
# Charles Schwab & Co. (c) 2011-2025
#

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
    DailyHigh = Double.NaN;
    DailyLow = Double.NaN;
} else {
    DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
    DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited by a moderator:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Hello!
I'm new to ThinkScript. Thanks to artificial intelligence, I figured out some things, and some things I didn't.
I hope someone can help me write a simple script to
automate the task of drawing simple horizontal lines
(highs and lows) that extend along the entire length of the
corresponding period - quarter (3,6,9,12).

(f) In detail:
If 1= before Friday or Friday, then the next Friday;
If 1= Saturday, then the next Friday = 1+12 (Sunday and 12 days);
If 1= Sunday, then the next Friday = +12 (12 days).

AggregationPeriod :

(f) 4H -> YTD
(f) 12H -> YTD
(f) 1 D -> YTD
1 W -> YTD
1 M -> YTD

Last relevant quarter :
the remaining bars to the actual bar and, accordingly,
the remaining future bars in the current quarter's plot.

code :
Code:
# AggregationPeriod
#
def tf_now = GetAggregationPeriod() ;
#
def tf_4H = AggregationPeriod.FOUR_HOURS ;
# def tf_12H = AggregationPeriod.12_HOURS ;
def tf_day = AggregationPeriod.DAY ;
def tf_week = AggregationPeriod.WEEK ;
def tf_month = AggregationPeriod.MONTH ;
#
def is_tf_4H = ( tf_now == tf_4H ) ;
# def is_tf_12H = ( tf_now == tf_12H ) ;
def is_tf_day = ( tf_now == tf_day ) ;
def is_tf_week = ( tf_now == tf_week ) ;
def is_tf_month = ( tf_now == tf_month ) ;
#



def h = high ;
def l = low ;

def is_active = !IsNaN(h) and !IsNaN(l);

def na = Double.NaN;
def bn = BarNumber ();

def is_real_Bar = !IsNaN(close) and IsNaN(close[-1]); # lastBar
def real_Bar = if IsNaN(close[-1]) then bn else real_Bar [1]; # lastBar
# def numBars = HighestAll( is_real_Bar );

def current_Date = GetYYYYMMDD (); # current date
def current_D = GetDay (); # number current day

def current_W = GetWeek(); # number current week in year
def current_M = GetMonth(); # number current Month in year
def current_Y = GetYear(); # current Year

def current_D_M = GetDayOfMonth( current_Date ); # number day of month ( 1 .. 31 )


# secondFriday in Month of Quarter

def DayWeek = GetDayOfWeek( current_Date ); # number day of week

def secondFridayOffset =
if DayWeek <= 5 then 5 - DayWeek + 7
else
if DayWeek == 6 then
14 # Sat.
else
13 ; # Sun.

def is_Friday = GetDayOfWeek( current_Date ) == 5;

def Quarter_Date =
( current_M == 3 or current_M == 6 or current_M == 9 or current_M == 12 )
and
( current_D_M == secondFridayOffset )
;

# def is_Quarter = Quarter_Date != Quarter_Date [1] ; # ? = + 1 bar

def Quarter_Bn = if Quarter_Date then Bn else Double.NaN;


# secondFridayOffset, day
AddChartBubble( bn == Quarter_Bn , high, " current Quarter_Bn : " + Quarter_Bn , Color.LIGHT_GREEN , 1 );


# plot High/Low
def Ql_High = if Quarter_Date then h else Ql_High[1] ;
def Ql_Low = if Quarter_Date then l else Ql_Low [1] ;

# High
plot q_High = Ql_High;
q_High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_High.SetDefaultColor(Color.YELLOW);

# Quartal Low
plot q_Low = Ql_Low;
q_Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_Low.SetDefaultColor(Color.GREEN);

# vertical Lines befor new Quartal
AddVerticalLine( (real_Bar <1) && Quarter_Date , " n e w Quarter : " + Quarter_Date , Color.ORANGE, Curve.SHORT_DASH);

# end
Code:
plot QH = Highest(high(Period=AggregationPeriod.QUARTER)[0],1);
plot QL = Lowest(low(Period=AggregationPeriod.QUARTER)[0],1);
 
For my part, I went a little different way, but a problem arose ThinkScript
for some reason it reacts incorrectly to variable integer values, taking into account only constants?

Please tell me
how to correctly shift the quarterly lines by the number of bars - " bars_count "
according to the beginning of a certain quarter - " Kvartal_Date "

based on the code below :


Rich (BB code):
input TF = AggregationPeriod.QUARTER;

def hh   =  high ;
def ll   =  low ;

def h = high( period = TF) ;
def l = low(  period = TF) ;
def o = open( period = TF) ;
def c = close(period = TF) ;

def na  =  Double.NaN;
def bn  =  BarNumber ();


def is_real_Bar = !IsNaN(close) and IsNaN(close[-1]);               #  lastBar
def    real_Bar = if IsNaN(close[-1]) then  bn  else real_Bar [1];  #  lastBar

def  current_Date  =  GetYYYYMMDD ();       #  current  date
def  current_D     =  GetDay ();            #  number  current  day

def current_W  =  GetWeek();    #  number  current  week    in year
def current_M  =  GetMonth();   #  number  current  Month   in year
def current_Y  =  GetYear();    #          current  Year

def current_D_W  = GetDayOfWeek ( current_Date );    #  number  day  of week   ( 1 = Mon  ..  7 = Sun )
def current_D_M  = GetDayOfMonth( current_Date );    #  number  day  of month  ( 1  ..  31 )
 
def DayWeek = GetDayOfWeek( current_Date );

def secondFridayOffset =         #     ( 1 = Mon  ..  7 = Sun )
    if DayWeek <= 5 then 5 - DayWeek + 7
    else
       if  DayWeek == 6  then
          14      # Sat.
       else
          13  ;   # Sun.

def is_Friday  =  GetDayOfWeek( current_Date ) == 5;


#   Kvartal_Date :

def Kvartal_Date =
 ( current_M == 3  or  current_M == 6  or  current_M == 9  or  current_M == 12 )
     and
 ( current_D_M  ==  secondFridayOffset ) ;


def Kvartal_Bn  =    if  Kvartal_Date  then  bn  else Kvartal_Bn[1];   

def is_active =  !IsNaN(h) and !IsNaN(l);

# Detect start of new TF candle when open or close changes
def newCandle =  (o != o[1]) or (c != c[1]);

# Cumulative candle count increments only on new candle
rec candleCount = if newCandle then candleCount[1] + 1 else candleCount[1];

def is_plot  =  is_active and candleCount ;


#   lines :

#    Quartal  High
#    Quartal  Low

plot DayHigh = if  is_plot  then h else Double.NaN ;
plot DayLow  = if  is_plot  then l else Double.NaN ;

DayHigh.SetDefaultColor(GetColor(4));
DayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DayLow.SetDefaultColor(GetColor(1));
DayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


#  vertical Lines befor new Quartal
# 

AddVerticalLine( (real_Bar < 1)  &&  Kvartal_Date , "  n e w     k v a r t a l  :       " + Kvartal_Date , Color.ORANGE, Curve.SHORT_DASH);


#      end


Thank you for your support .
 

Attachments

  • e.png
    e.png
    197 KB · Views: 30
Hello!
I'm new to ThinkScript. Thanks to artificial intelligence, I figured out some things, and some things I didn't.
I hope someone can help me write a simple script to
automate the task of drawing simple horizontal lines
(highs and lows) that extend along the entire length of the
corresponding period - quarter (3,6,9,12).

(f) In detail:
If 1= before Friday or Friday, then the next Friday;
If 1= Saturday, then the next Friday = 1+12 (Sunday and 12 days);
If 1= Sunday, then the next Friday = +12 (12 days).

AggregationPeriod :

(f) 4H -> YTD
(f) 12H -> YTD
(f) 1 D -> YTD
1 W -> YTD
1 M -> YTD

Last relevant quarter :
the remaining bars to the actual bar and, accordingly,
the remaining future bars in the current quarter's plot.

code :
Code:
# AggregationPeriod
#
def tf_now = GetAggregationPeriod() ;
#
def tf_4H = AggregationPeriod.FOUR_HOURS ;
# def tf_12H = AggregationPeriod.12_HOURS ;
def tf_day = AggregationPeriod.DAY ;
def tf_week = AggregationPeriod.WEEK ;
def tf_month = AggregationPeriod.MONTH ;
#
def is_tf_4H = ( tf_now == tf_4H ) ;
# def is_tf_12H = ( tf_now == tf_12H ) ;
def is_tf_day = ( tf_now == tf_day ) ;
def is_tf_week = ( tf_now == tf_week ) ;
def is_tf_month = ( tf_now == tf_month ) ;
#



def h = high ;
def l = low ;

def is_active = !IsNaN(h) and !IsNaN(l);

def na = Double.NaN;
def bn = BarNumber ();

def is_real_Bar = !IsNaN(close) and IsNaN(close[-1]); # lastBar
def real_Bar = if IsNaN(close[-1]) then bn else real_Bar [1]; # lastBar
# def numBars = HighestAll( is_real_Bar );

def current_Date = GetYYYYMMDD (); # current date
def current_D = GetDay (); # number current day

def current_W = GetWeek(); # number current week in year
def current_M = GetMonth(); # number current Month in year
def current_Y = GetYear(); # current Year

def current_D_M = GetDayOfMonth( current_Date ); # number day of month ( 1 .. 31 )


# secondFriday in Month of Quarter

def DayWeek = GetDayOfWeek( current_Date ); # number day of week

def secondFridayOffset =
if DayWeek <= 5 then 5 - DayWeek + 7
else
if DayWeek == 6 then
14 # Sat.
else
13 ; # Sun.

def is_Friday = GetDayOfWeek( current_Date ) == 5;

def Quarter_Date =
( current_M == 3 or current_M == 6 or current_M == 9 or current_M == 12 )
and
( current_D_M == secondFridayOffset )
;

# def is_Quarter = Quarter_Date != Quarter_Date [1] ; # ? = + 1 bar

def Quarter_Bn = if Quarter_Date then Bn else Double.NaN;


# secondFridayOffset, day
AddChartBubble( bn == Quarter_Bn , high, " current Quarter_Bn : " + Quarter_Bn , Color.LIGHT_GREEN , 1 );


# plot High/Low
def Ql_High = if Quarter_Date then h else Ql_High[1] ;
def Ql_Low = if Quarter_Date then l else Ql_Low [1] ;

# High
plot q_High = Ql_High;
q_High.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_High.SetDefaultColor(Color.YELLOW);

# Quartal Low
plot q_Low = Ql_Low;
q_Low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
q_Low.SetDefaultColor(Color.GREEN);

# vertical Lines befor new Quartal
AddVerticalLine( (real_Bar <1) && Quarter_Date , " n e w Quarter : " + Quarter_Date , Color.ORANGE, Curve.SHORT_DASH);

# end

i have no idea what you are talking about here,
start over and describe what you want.
(f) In detail:
If 1= before Friday or Friday, then the next Friday;
If 1= Saturday, then the next Friday = 1+12 (Sunday and 12 days);
If 1= Sunday, then the next Friday = +12 (12 days).

AggregationPeriod :
(f) 4H -> YTD
(f) 12H -> YTD
(f) 1 D -> YTD
1 W -> YTD
1 M -> YTD

i have no idea what i am supposed to look at in the picture. you didn't describe it.
it looks like ORB lines, lines from some period at the start of the day. what does that have to do with drawing high/low lines during 3 months?


this draws 2 lines, at the highest and lowest prices, during some agg period

Code:
input agg = AggregationPeriod.DAY;

plot zhi = high(period = agg);
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.cyan);
zhi.hidebubble();

plot zlo = low(period = agg);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.cyan);
zhi.hidebubble();
 
i have no idea what you are talking about here,
start over and describe what you want.


i have no idea what i am supposed to look at in the picture. you didn't describe it.
it looks like ORB lines, lines from some period at the start of the day. what does that have to do with drawing high/low lines during 3 months?


this draws 2 lines, at the highest and lowest prices, during some agg period

Code:
input agg = AggregationPeriod.DAY;

plot zhi = high(period = agg);
zhi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.cyan);
zhi.hidebubble();

plot zlo = low(period = agg);
zlo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zhi.SetDefaultColor(Color.cyan);
zhi.hidebubble();
Is the request to start the quarter on the friday after first friday? That the start of the quarter would always be on a Friday between the 8th and the 14th day of the month.

My next question is when do you want to end the quarter?
 
Is the request to start the quarter on the friday after first friday? That the start of the quarter would always be on a Friday between the 8th and the 14th day of the month.

My next question is when do you want to end the quarter?
Maybe this?

Code:
def Qtr_Month = if getMonth() == 1 OR getMonth() == 4 OR getMonth() == 7 OR getMonth() == 10 then 1 else double.NaN;

def DoW_First = if getDayofMonth(GetYyyyMmDd()) == 1 then getDayofWeek(GetYyyyMmDd()) else DoW_First[1];

# What date is the second Friday, based on the day of week of the first of the month
def Second_Friday = if DoW_First == 1 then 12 else if DoW_First == 2 then 11 else if DoW_First == 3 then 10 else if DoW_First == 4 then 9 else if DoW_First == 5 then 8 else if DoW_First == 6 then 14 else if DoW_First == 7 then 13 else double.NAN;

def Dark_Period = if Qtr_Month AND  getDayofMonth(GetYyyyMmDd()) < Second_Friday then 1 else double.NAN;

plot QH = if isNAN(Dark_Period) then Highest(high(Period=AggregationPeriod.QUARTER)[0],1) else double.NAN;
plot QL = if isNAN(Dark_Period) then Lowest(low(Period=AggregationPeriod.QUARTER)[0],1) else double.NAN;
 
Thanks for support.

for example, 2025,
lines of highs and lows :
 

Attachments

  • Screenshot 2025-08-07 052110.png
    Screenshot 2025-08-07 052110.png
    202.1 KB · Views: 18
  • clr2025.png
    clr2025.png
    168.7 KB · Views: 18
  • Screenshot 2025-08-07 060027.png
    Screenshot 2025-08-07 060027.png
    213.8 KB · Views: 18
Rich (BB code):
# AggregationPeriod
#
def tf_now = GetAggregationPeriod() ;
#
def tf_4H = AggregationPeriod.FOUR_HOURS ;
# def tf_12H = AggregationPeriod.12_HOURS ;
def tf_day = AggregationPeriod.DAY ;
def tf_week = AggregationPeriod.WEEK ;
def tf_month = AggregationPeriod.MONTH ;
#
def is_tf_4H = ( tf_now == tf_4H ) ;
# def is_tf_12H = ( tf_now == tf_12H ) ;
def is_tf_day = ( tf_now == tf_day ) ;
def is_tf_week = ( tf_now == tf_week ) ;
def is_tf_month = ( tf_now == tf_month ) ;
#



def h = high ;
def l = low ;

def is_active = !IsNaN(h) and !IsNaN(l);

def na = Double.NaN;
def bn = BarNumber ();

def is_real_Bar = !IsNaN(close) and IsNaN(close[-1]); # lastBar
def real_Bar = if IsNaN(close[-1]) then bn else real_Bar [1]; # lastBar
# def numBars = HighestAll( is_real_Bar );

def current_Date = GetYYYYMMDD (); # current date
def current_D = GetDay (); # number current day

def current_W = GetWeek();  # number current week in year
def current_M = GetMonth(); # number current Month in year
def current_Y = GetYear();  # current Year

def current_D_M = GetDayOfMonth( current_Date ); # number day of month ( 1 .. 31 )


# secondFriday in Month of Quarter

def DayWeek = GetDayOfWeek( current_Date );    #  number day of week


def is_new_Month  =  current_M != current_M[1] ;    #    first  date    new  month

def is_Q_Month =
( current_M == 3  or  current_M == 6  or  current_M == 9  or  current_M == 12 ) ;




# !
#  If the 1st or 2nd of the month falls on a Sat or Sun,
#  thinkScript ignores week 1 of the month.
#

def day   =       (current_Date % 100);                #    is  first  date  month

def is_New_Quarter  =  If  (  is_Q_Month  &&  is_new_Month , 1 , 0 ) ;


def  in_Two_FridayOffset =

 if  is_New_Quarter then

   if day == 1  then           #    is  first  date  month  in new Quarter
 
      5 - DayWeek + 7

   else

      if  day == 3 then 14    # Sat. 1 == 6 day of week
      else 13                 # Sun. 1 == 7 day of week
 
 else in_Two_FridayOffset[1] ;



def is_Friday = GetDayOfWeek( current_Date ) == 5;


def Quarter_Date =   is_Q_Month  and  ( current_D_M == in_Two_FridayOffset )  and is_Friday ;


def Quarter_Bn = if Quarter_Date then bn else Double.NaN;



# secondFridayOffset, day
AddChartBubble( bn == Quarter_Bn , high,
     " \n new Quarter_Date  : " + current_Date + " \n " , Color.VIOLET , 1 );




# Quartal  High

plot QH = Highest(high(Period = AggregationPeriod.QUARTER)[0], 1);
QH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
QH.SetDefaultColor(Color.GREEN);


# Quartal  Low

plot QL = Lowest (low(Period = AggregationPeriod.QUARTER)[0], 1);
QL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
QL.SetDefaultColor(Color.RED);


# vertical Lines befor new Quartal

AddVerticalLine( (real_Bar < 1) && Quarter_Date , "       n e w     Q u a r t e r  " , Color.LIGHT_GRAY, Curve.LONG_DASH );

# end
 
Hello whoDAT.
Thanks for support.

?
" The code in post #9 above does exactly that. "

:)
This is probably a good example, but what does it have to do with the above task?

"
Rich (BB code):
def Qtr_Month = if GetMonth() == 3 or GetMonth() == 6 or GetMonth() == 9 or GetMonth() == 12 then 1 else Double.NaN;

def DoW_First = if GetDayOfMonth(GetYYYYMMDD()) == 1 then GetDayOfWeek(GetYYYYMMDD()) else DoW_First[1];

# What date is the second Friday, based on the day of week of the first of the month

def Second_Friday =
 if DoW_First == 1 then 12
 else
    if DoW_First == 2 then 11
    else
       if DoW_First == 3 then 10
       else
           Double.NaN;

def Dark_Period = if Qtr_Month and  GetDayOfMonth(GetYYYYMMDD()) < Second_Friday then 1 else Double.NaN;

plot QH = if IsNaN(Dark_Period) then Highest(high(Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;
plot QL = if IsNaN(Dark_Period) then Lowest( low( Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;

AddVerticalLine(  Dark_Period , " " , Color.LIGHT_ORANGE, Curve.LONG_DASH );

AddChartBubble(  Second_Friday == 2   &&    Qtr_Month  , high,
 " Second_Friday  : " + Second_Friday + " \n " ,  Color.CYAN , 1 );

# end

"
 

Attachments

  • Screenshot 2025-08-07 211954.png
    Screenshot 2025-08-07 211954.png
    231.6 KB · Views: 16
The situation is as follows, I did everything myself. Except for one thing, the same problem: drawing lines ( Highest & Lowest ) ?
ThinkScript incorrectly (gives an error) reacts to integer variables, considering only constants ?

Please tell me how to correctly draw horizontal lines of non-standard
(not constant from ThinkScript ) quarters by the
number of bars - "bars_count"
in accordance with the beginning of a certain quarter - "Kvartal_Date".

Rich (BB code):
#  error :
def plot_HiLine = if  ( bn == BAR_Next_Kvartal[-bars_count] )  then  H_Price else  plot_HiLine[1];

Thanks in advance for your answer.
 

Attachments

  • Screenshot 2025-08-07 215859.png
    Screenshot 2025-08-07 215859.png
    302.7 KB · Views: 7
Hello whoDAT.
Thanks for support.

?
" The code in post #9 above does exactly that. "

:)
This is probably a good example, but what does it have to do with the above task?

"
Rich (BB code):
def Qtr_Month = if GetMonth() == 3 or GetMonth() == 6 or GetMonth() == 9 or GetMonth() == 12 then 1 else Double.NaN;

def DoW_First = if GetDayOfMonth(GetYYYYMMDD()) == 1 then GetDayOfWeek(GetYYYYMMDD()) else DoW_First[1];

# What date is the second Friday, based on the day of week of the first of the month

def Second_Friday =
 if DoW_First == 1 then 12
 else
    if DoW_First == 2 then 11
    else
       if DoW_First == 3 then 10
       else
           Double.NaN;

def Dark_Period = if Qtr_Month and  GetDayOfMonth(GetYYYYMMDD()) < Second_Friday then 1 else Double.NaN;

plot QH = if IsNaN(Dark_Period) then Highest(high(Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;
plot QL = if IsNaN(Dark_Period) then Lowest( low( Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;

AddVerticalLine(  Dark_Period , " " , Color.LIGHT_ORANGE, Curve.LONG_DASH );

AddChartBubble(  Second_Friday == 2   &&    Qtr_Month  , high,
 " Second_Friday  : " + Second_Friday + " \n " ,  Color.CYAN , 1 );

# en
Rich (BB code):


My code in #9 works.

Now when I look deeper into your request you seem to think that quarters begin 1 month before everyone else in the entire world does. The start of the first quarter is January 1 in every place in the entire world other than your request.

What day do you want your quarter to end in your world? April 47th?
 
Hello whoDAT.
Thanks for support.

Your example is great :

Rich (BB code):
plot QH = if IsNaN(Dark_Period) then Highest(high(Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;
plot QL = if IsNaN(Dark_Period) then Lowest( low( Period = AggregationPeriod.QUARTER)[0], 1) else Double.NaN;

but there is one thing - it is a statutory constant of the quarter.
More precisely, from the 1st day of the month according to the correspondence to a certain 1st day of the month, respectively, of the quarter.
In my example, variable numbers are taken into account - not a constant, respectively.

Namely (for example, asset "AAR", tf.: "1Y:1D", at the current moment) :

1) (9th month, from the task condition) September 2024 - 1st day - Sunday, respectively Friday of the 3rd week, according to the calendar - 13th day ;

lines from the 13th day (September) to the 13th day (December)

2) ( 12 ) December 2024 - 1st day - Sunday, respectively Friday of the 3rd week, according to the calendar - 13th day ;

lines from the 13th (December) to the 14th (March)

3) ( 3 ) March 2025 - 1st - Saturday, respectively Friday of the 3rd week, according to the calendar - the 14th ;

lines from the 13th (March) to the 13th (June)

4) ( 6 ) June 2025 - 1st - Sunday, respectively Friday of the 3rd week, according to the calendar - the 13th ;

lines from the 13th (June) to the 13th (September)

5) ( 9 ) September 2025 - 1st - Monday, respectively Friday of the 2nd week, according to the calendar - the 12th ;

lines from the 12th (September) to the 12th (December)
...

?
 

Attachments

  • AAR.png
    AAR.png
    302.7 KB · Views: 4
  • clr2025.png
    clr2025.png
    168.7 KB · Views: 4

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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