Professional Documents
Culture Documents
0 at
https://mozilla.org/MPL/2.0/
// © tradeforopp
//@version=5
szn_pivots = input.bool(false, "Seasonal Pivots", tooltip = "Shows when the current asset tends
to make highs and lows throughout the year, based on an aggregation of daily performance", group
= g_ANALYSIS)
pivot_strength = input.int(10, "Pivot Strength", tooltip = "Using a value of 10 for example, a high
must be greater than the 10 bars to the left and 10 bars to the right of it in order to be a valid pivot,
and vice versa for lows", group = g_ANALYSIS)
highlight_today = input.bool(true, "Highlight Current Trading Day", tooltip = "Easily find where the
current trading day meets up with seasonal averages", group = g_EXTRAS)
qdiv_style = input.string('Dotted', "", ['Dotted', 'Dashed', 'Solid'], inline = "QDIV", group = g_DIV)
text_size = input.string('Normal', "Text Size", options = ['Auto', 'Tiny', 'Small', 'Normal', 'Large',
'Huge'], group = g_STYLE)
get_table_pos(i) =>
result = switch i
result
get_text_size(i) =>
result = switch i
result
get_line_style(i) =>
result = switch i
result
get_month(i) =>
result = switch i
1 => 'JAN'
2 => 'FEB'
3 => 'MAR'
4 => 'APR'
5 => 'MAY'
6 => 'JUN'
7 => 'JUL'
8 => 'AUG'
9 => 'SEP'
10 => 'OCT'
11 => 'NOV'
12 => 'DEC'
get_qr(i) =>
result = switch i
1 => 'Q1'
2 => 'Q2'
3 => 'Q3'
4 => 'Q4'
get_period() =>
//
//
var int doy = na
//
first_xoy := bar_index
first_yoy := close[1]
doy := 0
if na(first_year)
first_year := year
if not na(doy)
doy += 1
//
highlight_offset = 20
days_in_year = 252
days_in_month = 21
days_in_qr = 63
period = get_period()
text_size := get_text_size(text_size)
mdiv_style := get_line_style(mdiv_style)
qdiv_style := get_line_style(qdiv_style)
table_pos := get_table_pos(table_pos)
//
idx = arr_days.indexof(doy)
if idx == -1
arr_days.push(doy)
d_pct.push(pct)
d_points.push(points)
d_count.push(1)
else
d_count.set(idx, d_count.get(idx) + 1)
dividers(base) =>
if month_div
for i = 0 to m_pct_avg.size()
line.new(left, base, left, base, color = mdiv_color, style = mdiv_style, extend = extend.both,
width = divider_width)
if qr_div
for i = 0 to q_pct_avg.size()
line.new(left, base, left, base, color = qdiv_color, style = qdiv_style, extend = extend.both,
width = divider_width)
plot_analysis(period, szn_arr, szn_idx, num_days, base) =>
for i = 0 to szn_arr.size() - 1
'D' => na
perf = szn_arr.get(i)
if not_daily
box.new(left, base + perf, right, base, bgcolor = col, border_color = col, text = box_text,
text_color = col)
else
if show_labels
next_perf = szn_arr.get(i + 1)
line.new(label_x, base + perf, label_x + (not_daily ? num_days : 1), base + next_perf, color =
track_color, width = 2)
if i == szn_arr.size() - 1
var table stats = table.new(table_pos, 50, 50, bgcolor = table_bg, frame_color = table_frame,
border_color = table_border, frame_width = 1, border_width = 1)
if barstate.islast
if timeframe.in_seconds() != timeframe.in_seconds("D")
else
temp_arr_days = arr_days.copy()
for i = temp_arr_days.size() - 1 to 0
min = arr_days.indexof(temp_arr_days.min())
d_sorted_pct.push(d_pct.get(min))
d_sorted_points.push(d_points.get(min))
d_sorted_count.push(d_count.get(min))
d_sorted_day.push(d_day.get(min))
temp_arr_days.set(min, na)
for i = 0 to d_sorted_pct.size() - 1
d_sorted_pct.set(i, d_sorted_pct.get(i) / d_sorted_count.get(i))
m_pct_avg.clear()
for i = 0 to 11
sum = 0.0
for j = 0 to days_in_month - 1
m_pct_avg.push(sum)
q_pct_avg.clear()
for i = 0 to 3
sum = 0.0
for j = 0 to days_in_qr - 1
q_pct_avg.push(sum)
szn_pct = szn_arr.get(szn_idx)
base = 1.0
if szn_pivots
x1 = start_idx
y1 = base
x2 = x1 + 1
for i = 0 to d_pct.size() - 1
price_projection.push(y1)
y2 = y1 * (1 + d_sorted_pct.get(i))
y1 := y2
x1 += 1
x2 += 1
left_bound = pivot_strength
new_low = true
new_high = true
if i != j
new_low := false
break
if i != j
new_high := false
break
if new_low
if szn_lows.indexof(new_low_month) == -1
szn_lows.push(new_low_month)
line.new(start_idx + i, base, start_idx + i, base, extend = extend.both, color = low_color,
width = pivot_width)
if new_high
if szn_highs.indexof(new_high_month) == -1
szn_highs.push(new_high_month)
dividers(base)
if show_analysis
// Table --------------------------------------------------
if show_table
if szn_pivots
table.cell(stats, 0, 6, "Major Lows Made in: ", text_size = text_size, text_color = table_text)
table.cell(stats, 0, 7, "Major Highs Made in: ", text_size = text_size, text_color = table_text)
// Table --------------------------------------------------