Hourly Trading System (Zeiierman)
Hourly Trading System (Zeiierman)
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Zeiierman
//@version=5
indicator("Hourly Trading System (Zeiierman)", overlay=true, max_lines_count=100,
max_bars_back = 200, max_labels_count=100)
// ~~ Tooltips {
var t1 = "Sets the color for the 1-Hour Open line. Changing the color helps
distinguish it from other lines on the chart.
\n\nChoose between displaying the 1-Hour Open as a Line or a Zone. A zone shows an
area around the open price, providing a visual representation of a price range.
\n\nSets the line style for the 1-Hour Open (Solid, Dotted, Dashed). Different
styles can help visually differentiate the lines on your chart."
var t2 = "Sets the color for the 4-Hour Open line. Adjusting the color can help you
easily identify this line on your chart.
\n\nSets the line style for the 4-Hour Open (Solid, Dotted, Dashed). Different
styles can help visually differentiate the lines on your chart."
var t3 = "Specifies the width of the zone around the 1-Hour Open as a percentage.
Increasing this value widens the zone, showing a larger range around the open
price."
var t4 = "Enables or disables the display of retest markers. When enabled, markers
show where the price retested the 1-Hour Open line."
var t5 = "Sets the number of retests to display. Increasing this value shows more
retest markers on the chart."
var t6 = "Enables or disables the volume filter for retests. When enabled, only
retests with higher volume are displayed.
\n\nSets the length of the volume filter. Increasing this value smooths the volume
filter, potentially reducing the number of retest markers."
var t7 = "Enables or disables the 1-hour average line. This line shows the average
price over the past hour."
var t8 = "Enables or disables the display of hourly high and low labels. These
labels mark the highest and lowest prices within each hour."
var t9 = "Enables or disables the display of candlesticks on the chart.
Candlesticks provide a detailed view of price action.
\n\nEnables or disables bar coloring based on price direction. Up bars are colored
green and down bars are colored red."
var t10 = "Sets the timeframe for higher timeframe candles. Changing this value
adjusts the period over which higher timeframe candles are calculated."
var t11 = "Sets the number of higher timeframe candles to display. Increasing this
value shows more candles on the chart."
var t12 = "Sets the location for higher timeframe candles. Adjusting this value
moves the higher timeframe candles left or right on the chart."
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Settings {
H_col = input.color(color.rgb(105, 255, 190), title="1-Hour Open",
group="Levels", inline="1")
H_line_box = input.string("Zone", title="", options=["Line", "Zone"],
group="Levels", inline="1")
H_style = input.string("Solid", title="", options=["Solid", "Dotted", "Dashed"],
group="Levels", inline="1")
H_width = input.int(1, "", 1, 4, group="Levels", inline="1", tooltip=t1)
// ~~ Functions {
Style(styleInput) =>
switch styleInput
"Solid" => line.style_solid
"Dotted" => line.style_dotted
"Dashed" => line.style_dashed
Box(left,top,right,bot,width,col)=>box.new(left,top,right,bot,border_color=col,bord
er_style=Style(H_style),border_width=width,bgcolor=color.new(col,75),xloc=xloc.bar_
time)
bars_per_hour() =>
var int bars_per_hour = na
if (timeframe.isintraday)
if (timeframe.multiplier == 1)
bars_per_hour := 60
else if (timeframe.multiplier == 5)
bars_per_hour := 12
else if (timeframe.multiplier == 15)
bars_per_hour := 4
else
bars_per_hour := na
else
bars_per_hour := na
bars_per_hour
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Line Style {
H_StyleOption = Style(H_style)
H4_StyleOption = Style(H4_style)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Arrays {
var line deletedLine = na
open_l = array.new_line()
start_points = array.new_float()
end_points = array.new_float()
retest_counts = array.new_int()
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Var {
var line1 = line(na)
var line2 = line(na)
var box1 = box(na)
var box2 = box(na)
var count = 0
var end = int(na)
var pos = false
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Time {
time_hour = hour(time)
time_4hour = (timeframe.isintraday and minute(time) == 0 and hour(time) % 4 == 0)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
if time_hour != time_hour[1]
start_point := open
if H_line_box=="Line"
line2 := Line(time, open, 3600000, H_col, H_StyleOption, H_width)
else
box2 := Box(time,open*(1+zoneDev),time+3600000,open*(1-
zoneDev),H_width,H_col)
count := 0
end := time + 3600000
pos := true
//Line_Vert(end, color.white, line.style_dotted)
//Label(end, start_point[1],"1 Hour")
if hourly_hl
//Change the previous Labels
if hourHL.size()>0
for i=0 to hourHL.size()-1 by 2
hourHL.get(i+1).set_text("H["+str.tostring(i/2+2)+"]")
hourHL.get(i).set_text("L["+str.tostring(i/2+2)+"]")
//Save High & Low Labels
hourHL.unshift(label.new(hourHighi,hourHigh,"H[1]",xloc.bar_time,textcolor
= color.white, color=color.new(color.green,0),style=label.style_label_down))
hourHL.unshift(label.new(hourLowi,hourLow,"L[1]",xloc.bar_time,textcolor =
color.white, color=color.new(color.red,0), style=label.style_label_up))
//High & Low Reset
hourHigh := high
hourLow := low
// Calculate how many bars are left until the next hour
bars_left = 0
if not na(bars_hour)
bars_passed = 0
if timeframe.isintraday
bars_passed := minute / timeframe.multiplier
bars_left := bars_hour - bars_passed
t = ""
if not na(bars_left)
t := str.tostring(math.round(bars_left))
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Direction {
dir(start_)=>
var dir = 0
if (not na(start_))
dir := close >= start_ ? 1 : -1
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Plots {
plot(ma_hour, color=time_hour==time_hour[2]?ma_col:na, linewidth=1, title="Hourly
Average Price")
plotcandle(candle?open:na,candle?high:na,candle?low:na,candle?close:na,
color=candle?col:na, bordercolor =candle?col:na, wickcolor=candle?col:na,
title="Candlesticks")
barcolor(bar?col:na, title="BarColor")
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Table {
var Table = table.new(position = position.top_right, columns = 2, rows = 4,
border_color = color.white, frame_color = color.white, bgcolor = color.blue,
border_width = 1)
if not na(prev_hour_close)
hourly_change := (close - prev_hour_close) / prev_hour_close * 100
if not na(prev_4hour_close)
four_hour_change := (close - prev_4hour_close) / prev_4hour_close * 100
if not na(prev_daily_close)
daily_change := (close - prev_daily_close) / prev_daily_close * 100
H1_color = hourly_change>0?color.lime:color.red
H4_color = four_hour_change>0?color.lime:color.red
D_color = daily_change>0?color.lime:color.red
// Table
if barstate.islast
table.cell(table_id = Table, column = 0, row = 0, text = "1 hour closes in:",
text_color = color.white)
table.cell(table_id = Table, column = 1, row = 0, text = t + " bars", bgcolor =
color.blue, text_color = color.white)
table.cell(table_id = Table, column = 0, row = 1, text = "1H Δ%:", text_color =
color.white)
table.cell(table_id = Table, column = 1, row = 1, text =
str.tostring(hourly_change, format.percent), bgcolor = H1_color, text_color =
color.white)
table.cell(table_id = Table, column = 0, row = 2, text = "4H Δ%:", text_color =
color.white)
table.cell(table_id = Table, column = 1, row = 2, text =
str.tostring(four_hour_change, format.percent), bgcolor = H4_color, text_color =
color.white)
table.cell(table_id = Table, column = 0, row = 3, text = "Daily Δ%:",
text_color = color.white)
table.cell(table_id = Table, column = 1, row = 3, text =
str.tostring(daily_change, format.percent), bgcolor = D_color, text_color =
color.white)
// ~~ HFT Candle {
// ~~ HTF Error Message {
tfs = str.tonumber(tf)
if str.tostring(tf) == "1D"
tfs := 1440
error = str.tonumber(timeframe.period)>=tfs
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ UDT {
type HTF
array<box> candle
array<line> wickH
array<line> wickL
array<float> hl
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Variables {
b = bar_index
var candle1 =
HTF.new(array.new<box>(numb),array.new<line>(numb),array.new<line>(numb),array.new<
float>(numb*2))
[o,h,l,c] = request.security(syminfo.tickerid,tf,
[open,high,low,close],lookahead=barmerge.lookahead_on)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
// ~~ Code {
if numb>0
if o!=o[1] //New candle declaration
candle1.candle.shift().delete()
candle1.wickH.shift().delete()
candle1.wickL.shift().delete()
candle1.hl.shift()
candle1.hl.shift()
candle1.candle.push(box.new(b+numb*4+loc,math.max(o,c),b+numb*4+loc+2,math.min(o,c)
,color(na),bgcolor=o>c?dn_col:up_col))
candle1.wickH.push(line.new(b+numb*4+loc+1,math.max(o,c),b+numb*4+loc+1,h,color=o>c
?dn_col:up_col))
candle1.wickL.push(line.new(b+numb*4+loc+1,math.min(o,c),b+numb*4+loc+1,l,color=o>c
?dn_col:up_col))
candle1.hl.push(h)
candle1.hl.push(l)
else // Relocate previous & current candles
d = loc
for [i,x] in candle1.candle
if i<numb-1
x.set_left(b+d*2)
x.set_right(b+d*2+2)
candle1.wickH.get(i).set_x1(b+d*2+1)
candle1.wickH.get(i).set_x2(b+d*2+1)
candle1.wickL.get(i).set_x1(b+d*2+1)
candle1.wickL.get(i).set_x2(b+d*2+1)
else
x.set_lefttop(b+d*2,math.max(o,c))
x.set_rightbottom(b+d*2+2,math.min(o,c))
x.set_bgcolor(o>c?dn_col:up_col)
candle1.wickH.get(i).set_xy1(b+d*2+1,math.max(o,c))
candle1.wickH.get(i).set_xy2(b+d*2+1,h)
candle1.wickH.get(i).set_color(o>c?dn_wick:up_wick)
candle1.wickL.get(i).set_xy1(b+d*2+1,math.min(o,c))
candle1.wickL.get(i).set_xy2(b+d*2+1,l)
candle1.wickL.get(i).set_color(o>c?dn_wick:up_wick)
candle1.hl.set(numb*2-2,h)
candle1.hl.set(numb*2-1,l)
d += 2
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
if pos and count > 1 and time <= end and retest_count_1h < retests and
(H4_style=="Line"?low[1] > linePrice1 and low <= linePrice1 and
close >= linePrice1 : low[1] > box2.get_top() and low <= box2.get_top()
and close >= box2.get_bottom())
repos_1 := true
pos := false
count := 0
retest_count_1h += 1
if pos and count > 1 and time <= end and retest_count_1h < retests and
(H4_style=="Line"?high[1] < linePrice1 and high >= linePrice1 and
close <= linePrice1 : high[1] < box2.get_bottom() and high >=
box2.get_bottom()
and close <= box2.get_top())
reneg_1 := true
pos := false
count := 0
retest_count_1h += 1
count += 1
if (count > 1)
pos := true
if (hour(time) != hour(time[1]))
retest_count_1h := 0
// ~~ Plots {
plotshape(HourPosRetest ? low : na, color=HourPosRetest ? re_up : na,
location=location.belowbar, style=shape.triangleup, size=size.tiny)
plotshape(HourNegRetest ? high : na, color=HourNegRetest ? re_dn : na,
location=location.abovebar, style=shape.triangledown, size=size.tiny)
//
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}