2023-03-08, 11:09
  #1
Nn som knner till och kan hjlpa med Pine Script? Det r fr en indikator i trading view (aktiehandel)

Vill bara kunna plotta ut en horisontell linje baserat p en viss tid frn grdagen. Normalt ritar man utifrn prisniv, men jag vill ha frn ett klockslag.
Citera
2023-03-08, 11:33
  #2
Medlem
MrSwedeGliderRunts avatar
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

indicator('Open Lines', overlay=true, max_bars_back=500)


var grp1 = 'Show - Hour - Minute - Label Text - Color'

TOOLTIP01 = "Enter your time zone's offset (+ or -). Eg. +5 / -3 / +9:30"
hoursOffsetInput = input.string('-4', "Timezone offset (GMT)", tooltip = TOOLTIP01)
TIMEZONE = "GMT"+hoursOffsetInput


sess1Show = input.bool(true, title='', inline='1', group=grp1)
sess1Hour = input.int(17, title='', minval=0, maxval=23, inline='1', group=grp1)
sess1Minute = input.int(0, title='', minval=0, maxval=60, inline='1', group=grp1)
sess1Text = input.string("Session Open ", title='', inline='1', group=grp1)
sess1Col = input.color(color.red, title='', inline="1", group=grp1)
inSession1 = hour == sess1Hour and minute == sess1Minute and second == 0

sess2Show = input.bool(false, title='', inline='2', group=grp1)
sess2Hour = input.int(0, title='', minval=0, maxval=23, inline='2', group=grp1)
sess2Minute = input.int(0, title='', minval=0, maxval=60, inline='2', group=grp1)
sess2Text = input.string("Day Open ", title='', inline='2', group=grp1)
sess2Col = input.color(color.green, title='', inline="2", group=grp1)
inSession2 = hour == sess2Hour and minute == sess2Minute and second == 0

sess3Show = input.bool(false, title='', inline='3', group=grp1)
sess3Hour = input.int(2, title='', minval=0, maxval=23, inline='3', group=grp1)
sess3Minute = input.int(0, title='', minval=0, maxval=60, inline='3', group=grp1)
sess3Text = input.string("London Open ", title='', inline='3', group=grp1)
sess3Col = input.color(color.blue, title='', inline="3", group=grp1)
inSession3 = hour == sess3Hour and minute == sess3Minute and second == 0


var grp2 = 'Other Settings'
MAX_LINES = input.int(10, title='Max Lines to show', minval=0, maxval=200, group=grp2)
extendHours = input.int(24, title='Extend lines for how many hours?', minval=1, maxval=24, group=grp2)
linesWidth = input.int(1, title='Lines Width', minval=1, maxval=4, group=grp2)
_labelSize = input.string("Tiny", title='Label Size', options=['Auto', 'Tiny', 'Small', 'Normal', 'Huge'], group=grp2)
labelSize = _labelSize == "auto" ? size.auto : _labelSize == "Tiny" ? size.tiny : _labelSize == "Small" ? size.small : _labelSize == "Normal" ? size.normal : size.huge


var line[] l1 = array.new_line(0)
var line[] l2 = array.new_line(0)
var line[] l3 = array.new_line(0)

var label[] la1 = array.new_label(0)
var label[] la2 = array.new_label(0)
var label[] la3 = array.new_label(0)

_extend = extendHours * 3600000

if inSession1 and not inSession1[1] and sess1Show
array.push(l1, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess1Col, width=linesWidth))
array.push(la1, label.new(time + _extend, open, sess1Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess1Col))

if inSession2 and not inSession2[1] and sess2Show
array.push(l2, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess2Col, width=linesWidth))
array.push(la2, label.new(time + _extend, open, sess2Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess2Col))

if inSession3 and not inSession3[1] and sess3Show
array.push(l3, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess3Col, width=linesWidth))
array.push(la3, label.new(time + _extend, open, sess3Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess3Col))


// Delete lines if more than max
if array.size(l1) > MAX_LINES
line.delete(array.shift(l1))
label.delete(array.shift(la1))
if array.size(l2) > MAX_LINES
line.delete(array.shift(l2))
label.delete(array.shift(la2))
if array.size(l3) > MAX_LINES
line.delete(array.shift(l3))
label.delete(array.shift(la3))
Citera
2023-03-08, 13:19
  #3
Citat:
Ursprungligen postat av MrSwedeGliderRunt
//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

indicator('Open Lines', overlay=true, max_bars_back=500)


var grp1 = 'Show - Hour - Minute - Label Text - Color'

TOOLTIP01 = "Enter your time zone's offset (+ or -). Eg. +5 / -3 / +9:30"
hoursOffsetInput = input.string('-4', "Timezone offset (GMT)", tooltip = TOOLTIP01)
TIMEZONE = "GMT"+hoursOffsetInput


sess1Show = input.bool(true, title='', inline='1', group=grp1)
sess1Hour = input.int(17, title='', minval=0, maxval=23, inline='1', group=grp1)
sess1Minute = input.int(0, title='', minval=0, maxval=60, inline='1', group=grp1)
sess1Text = input.string("Session Open ", title='', inline='1', group=grp1)
sess1Col = input.color(color.red, title='', inline="1", group=grp1)
inSession1 = hour == sess1Hour and minute == sess1Minute and second == 0

sess2Show = input.bool(false, title='', inline='2', group=grp1)
sess2Hour = input.int(0, title='', minval=0, maxval=23, inline='2', group=grp1)
sess2Minute = input.int(0, title='', minval=0, maxval=60, inline='2', group=grp1)
sess2Text = input.string("Day Open ", title='', inline='2', group=grp1)
sess2Col = input.color(color.green, title='', inline="2", group=grp1)
inSession2 = hour == sess2Hour and minute == sess2Minute and second == 0

sess3Show = input.bool(false, title='', inline='3', group=grp1)
sess3Hour = input.int(2, title='', minval=0, maxval=23, inline='3', group=grp1)
sess3Minute = input.int(0, title='', minval=0, maxval=60, inline='3', group=grp1)
sess3Text = input.string("London Open ", title='', inline='3', group=grp1)
sess3Col = input.color(color.blue, title='', inline="3", group=grp1)
inSession3 = hour == sess3Hour and minute == sess3Minute and second == 0


var grp2 = 'Other Settings'
MAX_LINES = input.int(10, title='Max Lines to show', minval=0, maxval=200, group=grp2)
extendHours = input.int(24, title='Extend lines for how many hours?', minval=1, maxval=24, group=grp2)
linesWidth = input.int(1, title='Lines Width', minval=1, maxval=4, group=grp2)
_labelSize = input.string("Tiny", title='Label Size', options=['Auto', 'Tiny', 'Small', 'Normal', 'Huge'], group=grp2)
labelSize = _labelSize == "auto" ? size.auto : _labelSize == "Tiny" ? size.tiny : _labelSize == "Small" ? size.small : _labelSize == "Normal" ? size.normal : size.huge


var line[] l1 = array.new_line(0)
var line[] l2 = array.new_line(0)
var line[] l3 = array.new_line(0)

var label[] la1 = array.new_label(0)
var label[] la2 = array.new_label(0)
var label[] la3 = array.new_label(0)

_extend = extendHours * 3600000

if inSession1 and not inSession1[1] and sess1Show
array.push(l1, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess1Col, width=linesWidth))
array.push(la1, label.new(time + _extend, open, sess1Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess1Col))

if inSession2 and not inSession2[1] and sess2Show
array.push(l2, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess2Col, width=linesWidth))
array.push(la2, label.new(time + _extend, open, sess2Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess2Col))

if inSession3 and not inSession3[1] and sess3Show
array.push(l3, line.new(time, open, time + _extend, open, xloc=xloc.bar_time, color=sess3Col, width=linesWidth))
array.push(la3, label.new(time + _extend, open, sess3Text, xloc=xloc.bar_time, style=label.style_none, size=labelSize, textcolor=sess3Col))


// Delete lines if more than max
if array.size(l1) > MAX_LINES
line.delete(array.shift(l1))
label.delete(array.shift(la1))
if array.size(l2) > MAX_LINES
line.delete(array.shift(l2))
label.delete(array.shift(la2))
if array.size(l3) > MAX_LINES
line.delete(array.shift(l3))
label.delete(array.shift(la3))
Ok, tack

Det ska jag testa att lgga in
Citera
2023-03-08, 16:18
  #4
Funkade inte.

Och fanns ingenstans att skriva in tidpunkten varifrn prislinjen skulle ritas
Citera
2023-03-08, 18:38
  #5
Moderator
vhes avatar
Anvnd kodtaggar nr ni postar kod.

/Moderator
Citera

Skapa ett konto eller logga in för att kommentera

Du måste vara medlem för att kunna kommentera

Skapa ett konto

Det är enkelt att registrera ett nytt konto

Bli medlem

Logga in

Har du redan ett konto? Logga in här

Logga in