Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- //@version=5
- indicator("Auto Fibonacci Of USA's Market Hour", overlay=true)
- // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
- //# * ══════════════════════════════════════════════════════════════════════════════════════════════
- //# *
- //# * Study : Auto Fibonacci Of USA's Market Hour
- //# *
- //# * Revision History
- //# * Release : Jan 018, 2024
- //# * Update : ver.001
- //# *
- //# * ══════════════════════════════════════════════════════════════════════════════════════════════
- // ══════════════════════════════════════════════════════════════════════════════════════════════════ //
- ////////////////////////////
- //// Setting Variables ////
- ////////////////////////////
- // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //
- // Plot Setting Variables--------------------------------------------------------------------------------------------------------------------------------------------------- //
- isFib = input.bool (defval = true, title = "Set Fibonacci ", group = "Plot Setting", inline = "Plot Setting")
- isFill = input.bool (defval = false, title = "Fill Fibonacci ", group = "Plot Setting", inline = "Plot Setting")
- showHistory = input.bool (defval = false, title = "Show History", group = "Plot Setting", inline = "Plot Setting")
- timezone = input.string (defval = "Asia/Seoul", title = "Timezone", group = "Indicator settings1", options = ["Etc/UTC", "Asia/Seoul", "Europe/London", "America/New_York"])
- labelSize = input.string (defval = "Normal", title = "Label Size", group = "Indicator settings1", options = ["Small", "Normal"])
- lineWidth = input.int (defval = 1, minval = 1, maxval = 10, title = "Line Width", group = "Indicator settings1")
- lineTransparency = input.int (defval = 0, minval = 0, maxval = 100, title = "Line Transparency", group = "Indicator settings2")
- backgroundTransparency = input.int (defval = 85, minval = 0, maxval = 100, title = "Background Transparency", group = "Indicator settings2")
- // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //
- ////////////////////////////
- //// Element Variables ////
- ////////////////////////////
- // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //
- // Plot Elements------------------------------------------------------------------------------------------------------------------------------------------------------------ //
- show_0 = input(true, "", inline = "Level0")
- value_0 = input(0, "", inline = "Level0")
- color_0 = input(#787b86, "", inline = "Level0")
- //width_0 = input(1, "", inline = "Level0")
- show_1 = input(true, "", inline = "Level0")
- value_1 = input(1, "", inline = "Level0")
- color_1 = input(#f44336, "", inline = "Level0")
- //width_1 = input(1, "", inline = "Level0")
- show_2 = input(true, "", inline = "Level1")
- value_2 = input(1.5, "", inline = "Level1")
- color_2 = input(#81c784, "", inline = "Level1")
- //width_2 = input(1, "", inline = "Level1")
- show_3 = input(true, "", inline = "Level1")
- value_3 = input(-0.5, "", inline = "Level1")
- color_3 = input(#4caf50, "", inline = "Level1")
- //width_3 = input(1, "", inline = "Level1")
- show_4 = input(true, "", inline = "Level2")
- value_4 = input(0.5, "", inline = "Level2")
- color_4 = input(#009688, "", inline = "Level2")
- //width_4 = input(1, "", inline = "Level2")
- show_5 = input(false, "", inline = "Level2")
- value_5 = input(-0.118, "", inline = "Level2")
- color_5 = input(#009688, "", inline = "Level2")
- //width_5 = input(1, "", inline = "Level2")
- show_6 = input(true, "", inline = "Level3")
- value_6 = input(0.264, "", inline = "Level3")
- color_6 = input(#64b5f6, "", inline = "Level3")
- //width_6 = input(1, "", inline = "Level3")
- show_7 = input(true, "", inline = "Level3")
- value_7 = input(0.882, "", inline = "Level3")
- color_7 = input(#787b86, "", inline = "Level3")
- //width_7 = input(1, "", inline = "Level3")
- show_8 = input(false, "", inline = "Level4")
- value_8 = input(1.118, "", inline = "Level4")
- color_8 = input(#81c784, "", inline = "Level4")
- //width_8 = input(1, "", inline = "Level4")
- show_9 = input(false, "", inline = "Level4")
- value_9 = input(0.736, "", inline = "Level4")
- color_9 = input(#f44336, "", inline = "Level4")
- //width_9 = input(1, "", inline = "Level5")
- show_10 = input(true, "", inline = "Level5")
- value_10 = input(1.286, "", inline = "Level5")
- color_10 = input(#2962ff, "", inline = "Level5")
- //width_10 = input(1, "", inline = "Level5")
- show_11 = input(false, "", inline = "Level5")
- value_11 = input(1.772, "", inline = "Level5")
- color_11 = input(#2962ff, "", inline = "Level5")
- //width_11 = input(1, "", inline = "Level5")
- show_12 = input(true, "", inline = "Level6")
- value_12 = input(-0.772, "", inline = "Level6")
- color_12 = input(#f44336, "", inline = "Level6")
- //width_12 = input(1, "", inline = "Level6")
- show_13 = input(false, "", inline = "Level6")
- value_13 = input(2.118, "", inline = "Level6")
- color_13 = input(#f44336, "", inline = "Level6")
- //width_13 = input(1, "", inline = "Level6")
- show_14 = input(true, "", inline = "Level7")
- value_14 = input(2.5, "", inline = "Level7")
- color_14 = input(#9c27b0, "", inline = "Level7")
- //width_14 = input(1, "", inline = "Level7")
- show_15 = input(false, "", inline = "Level7")
- value_15 = input(3.118, "", inline = "Level7")
- color_15 = input(#9c27b0, "", inline = "Level7")
- //width_15 = input(1, "", inline = "Level7")
- show_16 = input(true, "", inline = "Level8")
- value_16 = input(-1.118, "", inline = "Level8")
- color_16 = input(#e91e63, "", inline = "Level8")
- //width_16 = input(1, "", inline = "Level8")
- show_17 = input(false, "", inline = "Level8")
- value_17 = input(-2.118, "", inline = "Level8")
- color_17 = input(#81c784, "", inline = "Level8")
- //width_17 = input(1, "", inline = "Level8")
- show_18 = input(false, "", inline = "Level9")
- value_18 = input(-1.5, "", inline = "Level9")
- color_18 = input(#f44336, "", inline = "Level9")
- //width_18 = input(1, "", inline = "Level9")
- show_19 = input(false, "", inline = "Level9")
- value_19 = input(-1, "", inline = "Level9")
- color_19 = input(#81c784, "", inline = "Level9")
- //width_19 = input(1, "", inline = "Level9")
- show_20 = input(false, "", inline = "Level10")
- value_20 = input(0.5, "", inline = "Level10")
- color_20 = input(#009688, "", inline = "Level10")
- //width_20 = input(1, "", inline = "Level10")
- show_21 = input(false, "", inline = "Level10")
- value_21 = input(0.5, "", inline = "Level10")
- color_21 = input(#009688, "", inline = "Level10")
- //width_21 = input(1, "", inline = "Level10")
- // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //
- ////////////////////////////
- //// Global Variables ////
- ////////////////////////////
- //Input Data
- //Constance
- //Index Timestamp
- //Timeframe Variables(string -> int)
- int currentPeriod = switch timeframe.period
- "1" => 1
- "3" => 3
- "5" => 5
- "15" => 15
- "30" => 30
- "60" => 60
- "240" => 240
- "D" => 3600
- "W" => 10080
- //Unit Bar Timestamp
- int unit_bar_timestamp = time[0]-time[1]
- //USA_Market_Time
- int USA_Market_Open_Hour = 09
- int USA_Market_Open_Minute = 30
- int USA_Market_Close_Hour = 16
- int USA_Market_Close_Minute = 00
- //Today's Session Timestamp
- Session_start_timestamp = timestamp ("America/New_York" , year, month, dayofmonth-1, USA_Market_Open_Hour, USA_Market_Open_Minute, 00)
- Session_end_timestamp = timestamp ("America/New_York" , year, month, dayofmonth-1, USA_Market_Close_Hour, USA_Market_Close_Minute, 00)
- //Session Diff Timestamp
- Session_Diff_Index = (Session_end_timestamp - Session_start_timestamp)/unit_bar_timestamp
- //Variable
- //Current Timestamp
- current_timestamp = time
- ////////////////////////////
- //// Method ////
- ////////////////////////////
- //Method to draw line
- f_drawLineX(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width) =>
- var id = line.new(_x1, _y1, _x2, _y2, _xloc, _extend, _color, _style, _width)
- if _y1 > 0 and _y2 > 0
- line.set_xy1(id, _x1, _y1)
- line.set_xy2(id, _x2, _y2)
- line.set_color(id, color=color.new(_color,lineTransparency))
- else
- line.set_xy1(id, _x1, close)
- line.set_xy2(id, _x2, close)
- line.set_color(id, color=color.new(#00000000,lineTransparency))
- id
- //Method to draw label
- f_drawLabelX(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip) =>
- var id = label.new(_x, _y, _text, _xloc, _yloc, _color, _style, _textcolor, _size, _textalign, _tooltip)
- label.set_text(id, _text)
- label.set_tooltip(id, _tooltip)
- if _y > 0
- label.set_xy(id, _x, _y)
- label.set_textcolor(id, _textcolor)
- else
- label.set_xy(id, _x, close)
- label.set_textcolor(id, #00000000)
- //Method to find the highest price in session time
- findDayH(_session_start_timestamp) =>
- Session_Start_Index = current_timestamp - _session_start_timestamp
- dayHigh = high[Session_Start_Index/unit_bar_timestamp]
- for i = 0 to Session_Diff_Index
- index = Session_Start_Index - i * unit_bar_timestamp
- if dayHigh < high[index/unit_bar_timestamp]
- dayHigh := high[index/unit_bar_timestamp]
- dayHigh
- //Method to find the lowest price in session time
- findDayL(_session_start_timestamp) =>
- Session_Start_Index = current_timestamp - _session_start_timestamp
- dayLow = low[Session_Start_Index/unit_bar_timestamp]
- for i = 0 to Session_Diff_Index
- index = Session_Start_Index - i * unit_bar_timestamp
- if dayLow > low[index/unit_bar_timestamp]
- dayLow := low[index/unit_bar_timestamp]
- dayLow
- //Plot Method
- f_processLevelX(_session_start_timestamp, _show, _value, _color, _width, _lineIdOther) =>
- if isFib
- Session_Start_Timestamp = _session_start_timestamp
- Bar_Start_Timestamp = _session_start_timestamp
- Bar_End_Timestamp = int(Bar_Start_Timestamp + (16 - 9.5 + 24) * 60 * 60 * 1000) // 09:30 - 16:00(Tomorrow) Difference Between Two Timestamp
- Session_Start_Index = current_timestamp - Session_Start_Timestamp
- dayH = findDayH(Session_Start_Timestamp)
- dayL = findDayL(Session_Start_Timestamp)
- dayDiff = math.abs(dayH - dayL)
- price = dayDiff * _value + dayL
- if _show
- bar = bar_index[Session_Start_Index/unit_bar_timestamp]
- style = label.style_label_right
- size = labelSize == 'Small' ? size.small : size.normal
- lineId = f_drawLineX(Bar_Start_Timestamp, price, Bar_End_Timestamp, price, xloc.bar_time, extend.none, _color, line.style_solid, _width)
- if not showHistory
- f_drawLabelX(bar, price, str.tostring(_value) + "(" + str.tostring(price, format.mintick) + ")", xloc.bar_index, yloc.price, #00000000, style, _color, size, text.align_right, str.tostring(price, format.mintick))
- if isFill
- linefill.new(lineId, _lineIdOther, color = color.new(_color, backgroundTransparency))
- lineId
- else
- _lineIdOther
- ////////////////////////////
- //// Plot ////
- ////////////////////////////
- //Plot
- plotFibonacci(_session_start_timestamp) =>
- if currentPeriod <= 30
- lineId_0 = f_processLevelX(_session_start_timestamp, show_0, value_0, color_0, lineWidth, line(na))
- lineId_1 = f_processLevelX(_session_start_timestamp, show_1, value_1, color_1, lineWidth, lineId_0)
- lineId_2 = f_processLevelX(_session_start_timestamp, show_2, value_2, color_2, lineWidth, lineId_1)
- lineId_3 = f_processLevelX(_session_start_timestamp, show_3, value_3, color_3, lineWidth, lineId_2)
- lineId_4 = f_processLevelX(_session_start_timestamp, show_4, value_4, color_4, lineWidth, lineId_3)
- lineId_5 = f_processLevelX(_session_start_timestamp, show_5, value_5, color_5, lineWidth, lineId_4)
- lineId_6 = f_processLevelX(_session_start_timestamp, show_6, value_6, color_6, lineWidth, lineId_5)
- lineId_7 = f_processLevelX(_session_start_timestamp, show_7, value_7, color_7, lineWidth, lineId_6)
- lineId_8 = f_processLevelX(_session_start_timestamp, show_8, value_8, color_8, lineWidth, lineId_7)
- lineId_9 = f_processLevelX(_session_start_timestamp, show_9, value_9, color_9, lineWidth, lineId_8)
- lineId_10 = f_processLevelX(_session_start_timestamp, show_10, value_10, color_10, lineWidth, lineId_9)
- lineId_11 = f_processLevelX(_session_start_timestamp, show_11, value_11, color_11, lineWidth, lineId_10)
- lineId_12 = f_processLevelX(_session_start_timestamp, show_12, value_12, color_12, lineWidth, lineId_11)
- lineId_13 = f_processLevelX(_session_start_timestamp, show_13, value_13, color_13, lineWidth, lineId_12)
- lineId_14 = f_processLevelX(_session_start_timestamp, show_14, value_14, color_14, lineWidth, lineId_13)
- lineId_15 = f_processLevelX(_session_start_timestamp, show_15, value_15, color_15, lineWidth, lineId_14)
- lineId_16 = f_processLevelX(_session_start_timestamp, show_16, value_16, color_16, lineWidth, lineId_15)
- lineId_17 = f_processLevelX(_session_start_timestamp, show_17, value_17, color_17, lineWidth, lineId_16)
- lineId_18 = f_processLevelX(_session_start_timestamp, show_18, value_18, color_18, lineWidth, lineId_17)
- lineId_19 = f_processLevelX(_session_start_timestamp, show_19, value_19, color_19, lineWidth, lineId_18)
- lineId_20 = f_processLevelX(_session_start_timestamp, show_20, value_20, color_20, lineWidth, lineId_19)
- lineId_21 = f_processLevelX(_session_start_timestamp, show_21, value_21, color_21, lineWidth, lineId_20)
- plotFibonacci(Session_start_timestamp)
- if showHistory
- int unit_day_timestamp = 60 * 60 * 24 * 1000
- Session_start_timestamp -= unit_day_timestamp
- plotFibonacci(Session_start_timestamp)
- Session_start_timestamp -= unit_day_timestamp
- plotFibonacci(Session_start_timestamp)
- Session_start_timestamp -= unit_day_timestamp
- plotFibonacci(Session_start_timestamp)
- Session_start_timestamp -= unit_day_timestamp
- plotFibonacci(Session_start_timestamp)
Advertisement
Comments
-
- download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement