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: 22
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.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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