Ayúdenme a Cambiar un Código Por Favor

El espacio del Foro donde compartir indicadores y estrategias creados con el lenguaje de la plataforma TradingView.
Responder
JulioTipanluiza
Mensajes: 1
Registrado: 14 Jun 2024 23:58

Ayúdenme a Cambiar un Código Por Favor

Mensaje por JulioTipanluiza »

Les comento tengo un indicador el cual hay unas líneas que me muestran horarios específicos.
A continuación les pongo la imagen. (Son las líneas rojas que están entre las velas)
IMG_20240614_172248.jpg

En lo que pido que me ayuden es que las líneas rojas aparezcan por debajo las velas.
Como en este ejemplo.
IMG_20240614_172021.jpg

Acá les dejo el Código

Código: Seleccionar todo

//@version=5
indicator('LIT - Timings', overlay=true, max_bars_back=1000, max_labels_count=500, max_lines_count=500, max_boxes_count=500)

var GRP1 = "ASIAN RANGE"

showLines = input(title='Show Lines', defval=true, group=GRP1)
showBackground = input(title='Show Background', defval=true, group=GRP1)
showMiddleLine = input(title='Show Middle Line', defval=true, group=GRP1)
extendLines = input(title='Extend Line', defval=true, group=GRP1)
rangeTime = input.session(title='Session Time', defval='1700-0100', group=GRP1)
extendTime = input.session(title='Extend Until', defval='0100-0500', group=GRP1)
linesWidth = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP1)
boxLineColor = input(color.new(#9c27b0, 50), 'Box Line Color', group=GRP1)
middleLineColor = input(color.new(#9c27b0, 50), 'Middle Line Color', group=GRP1)
backgroundColor = input(color.new(#9c27b0, 90), 'Box Background Color', group=GRP1)



var GRP5 = "LONDON"

showLines4 = input(title='Show Lines', defval=true, group=GRP5)
showBackground4 = input(title='Show Background', defval=true, group=GRP5)
rangeTime4 = input.session(title='Session Time', defval='0300-0400', group=GRP5)
linesWidth4 = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP5)
boxLineColor4 = input(color.new(#00bcd4, 95), 'Box Line Color', group=GRP5)
backgroundColor4 = input(color.new(#00bcd4, 90), 'Box Background Color', group=GRP5)



var GRP6 = "NEWYORK"

showLines5 = input(title='Show Lines', defval=true, group=GRP6)
showBackground5 = input(title='Show Background', defval=true, group=GRP6)
rangeTime5 = input.session(title='Session Time', defval='0800-0900', group=GRP6)
linesWidth5 = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP6)
boxLineColor5 = input(color.new(#4caf50, 95), 'Box Line Color', group=GRP6)
backgroundColor5 = input(color.new(#4caf50, 90), 'Box Background Color', group=GRP6)



////////////////////////////////////////////

inSession = not na(time(timeframe.period, rangeTime))
inExtend = not na(time(timeframe.period, extendTime))


startTime = 0
startTime := inSession and not inSession[1] ? time : startTime[1]

//Box lines
var line lowHLine = na
var line topHLine = na
var line leftVLine = na
var line rightVLine = na
var line middleHLine = na
var box bgBox = na

var low_val = 0.0
var high_val = 0.0
if inSession and not inSession[1]
    low_val := low
    high_val := high
    high_val

// Plot lines
if inSession and timeframe.isintraday
    if inSession[1]
        line.delete(lowHLine)
        line.delete(topHLine)
        line.delete(leftVLine)
        line.delete(rightVLine)
        line.delete(middleHLine)
        box.delete(bgBox)

    if low < low_val
        low_val := low
        low_val
    if high > high_val
        high_val := high
        high_val

    //Create Box
    //x1, y1, x2, y2
    if showBackground
        bgBox := box.new(startTime, high_val, time, low_val, xloc=xloc.bar_time, bgcolor=backgroundColor, border_width=0)

    if showLines
        lowHLine := line.new(startTime, low_val, time, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        topHLine := line.new(startTime, high_val, time, high_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        leftVLine := line.new(startTime, high_val, startTime, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        rightVLine := line.new(time, high_val, time, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)

    //Create Middle line
    if showMiddleLine
        middleHLine := line.new(startTime, (high_val + low_val) / 2, time, (high_val + low_val) / 2, xloc=xloc.bar_time, color=middleLineColor, style=line.style_solid, width=linesWidth)

else
    if inExtend and extendLines and not inSession and timeframe.isintraday
        time1 = line.get_x1(lowHLine)
        time2 = line.get_x2(lowHLine)
        price = line.get_y1(lowHLine)
        line.delete(lowHLine)
        lowHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        
        time1 := line.get_x1(topHLine)
        time2 := line.get_x2(topHLine)
        price := line.get_y1(topHLine)
        line.delete(topHLine)
        topHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)

        time1 := line.get_x1(middleHLine)
        time2 := line.get_x2(middleHLine)
        price := line.get_y1(middleHLine)
        line.delete(middleHLine)
        middleHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=middleLineColor, style=line.style_solid, width=linesWidth)
        middleHLine


////////////////////////////////////////////


inSession4 = not na(time(timeframe.period, rangeTime4))

startTime4 = 0
startTime4 := inSession4 and not inSession4[1] ? time : startTime4[1]

//Box lines
var line lowHLine4 = na
var line topHLine4 = na
var line leftVLine4 = na
var line rightVLine4 = na
var line middleHLine4 = na
var box bgBox4 = na

var low_val4 = 0.0
var high_val4 = 0.0
if inSession4 and not inSession4[1]
    low_val4 := low
    high_val4 := high
    high_val4

// Plot lines
if inSession4 and timeframe.isintraday
    if inSession4[1]
        line.delete(lowHLine4)
        line.delete(topHLine4)
        line.delete(leftVLine4)
        line.delete(rightVLine4)
        line.delete(middleHLine4)
        box.delete(bgBox4)

    if low < low_val4
        low_val4 := low
        low_val4
    if high > high_val4
        high_val4 := high
        high_val4

    //Create Box
    //x1, y1, x2, y2
    if showBackground4
        bgBox4 := box.new(startTime4, high_val4, time, low_val4, xloc=xloc.bar_time, bgcolor=backgroundColor4, border_width=0)

    if showLines4
        lowHLine4 := line.new(startTime4, low_val4, time, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        topHLine4 := line.new(startTime4, high_val4, time, high_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        leftVLine4 := line.new(startTime4, high_val4, startTime4, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        rightVLine4 := line.new(time, high_val4, time, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)

////////////////////////////////////////////

inSession5 = not na(time(timeframe.period, rangeTime5))

startTime5 = 0
startTime5 := inSession5 and not inSession5[1] ? time : startTime5[1]

//Box lines
var line lowHLine5 = na
var line topHLine5 = na
var line leftVLine5 = na
var line rightVLine5 = na
var line middleHLine5 = na
var box bgBox5 = na

var low_val5 = 0.0
var high_val5 = 0.0
if inSession5 and not inSession5[1]
    low_val5 := low
    high_val5 := high
    high_val5

// Plot lines
if inSession5 and timeframe.isintraday
    if inSession5[1]
        line.delete(lowHLine5)
        line.delete(topHLine5)
        line.delete(leftVLine5)
        line.delete(rightVLine5)
        line.delete(middleHLine5)
        box.delete(bgBox5)

    if low < low_val5
        low_val5 := low
        low_val5
    if high > high_val5
        high_val5 := high
        high_val5

    //Create Box
    //x1, y1, x2, y2
    if showBackground5
        bgBox5 := box.new(startTime5, high_val5, time, low_val5, xloc=xloc.bar_time, bgcolor=backgroundColor5, border_width=0)

    if showLines5
        lowHLine5 := line.new(startTime5, low_val5, time, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        topHLine5 := line.new(startTime5, high_val5, time, high_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        leftVLine5 := line.new(startTime5, high_val5, startTime5, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        rightVLine5 := line.new(time, high_val5, time, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)

///////////////////////////////////////////////


//ZONA A CAMBIAR

ffRange = input.session(title='Time: ', defval='0200-0201', inline='a', group='FF')
ffcolor = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="FF")
ffStyle = input.string(title="-", defval=line.style_solid, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="FF")


mmm1Range = input.session(title='Time: ', defval='0430-0431', inline='a', group='MMM1')
mmm1color = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="MMM1")
mmm1Style = input.string(title="-", defval=line.style_solid, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="MMM1")


mmm2Range = input.session(title='Time: ', defval='0630-0631', inline='a', group='MMM2')
mmm2color = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="MMM2")
mmm2Style = input.string(title="-", defval=line.style_solid, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="MMM2")


lcRange = input.session(title='Time: ', defval='1100-1101', inline='a', group='LC')
lccolor = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="LC")
lcStyle = input.string(title="-", defval=line.style_solid, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="LC")


//Plot lines
in_session_ff = time(timeframe.period, ffRange)
sessionffActive = in_session_ff and timeframe.multiplier <= 240
var line ff = na
if sessionffActive and sessionffActive[1] == false
    ff := line.new(bar_index,high+0.001,bar_index,low-0.001,color=ffcolor, style=ffStyle)

in_session_mmm1 = time(timeframe.period, mmm1Range)
sessionmmm1Active = in_session_mmm1 and timeframe.multiplier <= 240
var line mmm1 = na
if sessionmmm1Active and sessionmmm1Active[1] == false
    mmm1 := line.new(bar_index,high+0.001,bar_index,low-0.001,color=mmm1color, style=mmm1Style)

in_session_mmm2 = time(timeframe.period, mmm2Range)
sessionmmm2Active = in_session_mmm2 and timeframe.multiplier <= 240
var line mmm2 = na
if sessionmmm2Active and sessionmmm2Active[1] == false
    mmm2 := line.new(bar_index,high+0.001,bar_index,low-0.001,color=mmm2color, style=mmm2Style)

in_session_lc = time(timeframe.period, lcRange)
sessionlcActive = in_session_lc and timeframe.multiplier <= 240
var line lc = na
if sessionlcActive and sessionlcActive[1] == false
    lc := line.new(bar_index,high+0.001,bar_index,low-0.001,color=lccolor, style=lcStyle)

//////////////////////////////////////////////////////////////////////



// Inputs

var GRP10 = "Daily Open"
daily = input.string(title='View', defval='Daily Open', group=GRP10)
_offset = input.int(0, title='Offset', minval=0, maxval=2)
o_color = input.color(color.new(#000000, 0), "Open Color", inline="1", group = GRP10)

// FUNCTIONS
t = time

isNewbar = not na(t) and (na(t[1]) or t > t[1])

tfInMinutes(simple string tf = "") =>
    float chartTf =
      timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
    float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)

inTimeframe(_t) => tfInMinutes(_t) > tfInMinutes(timeframe.period)


// Range
reso(exp, res) => request.security(syminfo.tickerid, res, exp, lookahead=barmerge.lookahead_on)

getData(_t, _var) =>
    o = reso(open[_offset], _t)
    show = _var != "Off" and inTimeframe(_t)
    _time = time(_t)
    newbar = na(_time[1]) or _time > _time[1]
    oc = _var == 'Daily Open'
    [o,   newbar,  oc]

// ---------- Daily ----------
[d_o, d_newbar, d_oc] = getData("D", daily)

if d_newbar 
    if d_oc
        line.new(x1=time, y1=d_o, x2=time_close("D"), y2=d_o, xloc=xloc.bar_time, style=line.style_dotted, color=o_color)

La zona donde pienso que se debe empezar es desde ahí
IMG_20240614_172906.jpg
PORFAVOR ESPERO UNA AYUDITA YA QUE YO SE MUY POCO SOBRE ESTOS TEMAS.
DE ANTE MANO MUCHAS GRACIAS.
gu5tavo71
Mensajes: 33
Registrado: 12 Sep 2022 00:15
Contactar:

Re: Ayúdenme a Cambiar un Código Por Favor

Mensaje por gu5tavo71 »

Hola

La linea se traza desde el high + 1% hasta el low - 1%

Código: Seleccionar todo

if sessionffActive and sessionffActive[1] == false
    ff := line.new(bar_index,high+0.001,bar_index,low-0.001,color=ffcolor, style=ffStyle)
Para que quede igual a tu imagen, debe trazarse desde el el low - 1% hasta 0

Código: Seleccionar todo

if sessionffActive and sessionffActive[1] == false
    ff := line.new(bar_index,low-0.001,bar_index,0,color=ffcolor, style=ffStyle)
El codigo completo quedaría así:

Código: Seleccionar todo

// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © gu5tavo71 (Gustavo Cardelle) https://gu5tavo71.carrd.co/

//@version=5
indicator('LIT - Timings', overlay=true, max_bars_back=1000, max_labels_count=500, max_lines_count=500, max_boxes_count=500)

// Post: https://www.x-trader.net/foro/viewtopic.php?t=21917
// Original code: Unknown
// Actual version: @gu5tavo71 for JulioTipanluiza for X-Trader Community
// Disclaimer: I am not a financial advisor. For purpose educate only. Use at your own risk.
// This script is provided “as is” and without any express or implied warranties


var GRP1 = "ASIAN RANGE"

showLines = input(title='Show Lines', defval=true, group=GRP1)
showBackground = input(title='Show Background', defval=true, group=GRP1)
showMiddleLine = input(title='Show Middle Line', defval=true, group=GRP1)
extendLines = input(title='Extend Line', defval=true, group=GRP1)
rangeTime = input.session(title='Session Time', defval='1700-0100', group=GRP1)
extendTime = input.session(title='Extend Until', defval='0100-0500', group=GRP1)
linesWidth = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP1)
boxLineColor = input(color.new(#9c27b0, 50), 'Box Line Color', group=GRP1)
middleLineColor = input(color.new(#9c27b0, 50), 'Middle Line Color', group=GRP1)
backgroundColor = input(color.new(#9c27b0, 90), 'Box Background Color', group=GRP1)



var GRP5 = "LONDON"

showLines4 = input(title='Show Lines', defval=true, group=GRP5)
showBackground4 = input(title='Show Background', defval=true, group=GRP5)
rangeTime4 = input.session(title='Session Time', defval='0300-0400', group=GRP5)
linesWidth4 = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP5)
boxLineColor4 = input(color.new(#00bcd4, 95), 'Box Line Color', group=GRP5)
backgroundColor4 = input(color.new(#00bcd4, 90), 'Box Background Color', group=GRP5)



var GRP6 = "NEWYORK"

showLines5 = input(title='Show Lines', defval=true, group=GRP6)
showBackground5 = input(title='Show Background', defval=true, group=GRP6)
rangeTime5 = input.session(title='Session Time', defval='0800-0900', group=GRP6)
linesWidth5 = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP6)
boxLineColor5 = input(color.new(#4caf50, 95), 'Box Line Color', group=GRP6)
backgroundColor5 = input(color.new(#4caf50, 90), 'Box Background Color', group=GRP6)



////////////////////////////////////////////

inSession = not na(time(timeframe.period, rangeTime))
inExtend = not na(time(timeframe.period, extendTime))


startTime = 0
startTime := inSession and not inSession[1] ? time : startTime[1]

//Box lines
var line lowHLine = na
var line topHLine = na
var line leftVLine = na
var line rightVLine = na
var line middleHLine = na
var box bgBox = na

var low_val = 0.0
var high_val = 0.0
if inSession and not inSession[1]
    low_val := low
    high_val := high
    high_val

// Plot lines
if inSession and timeframe.isintraday
    if inSession[1]
        line.delete(lowHLine)
        line.delete(topHLine)
        line.delete(leftVLine)
        line.delete(rightVLine)
        line.delete(middleHLine)
        box.delete(bgBox)

    if low < low_val
        low_val := low
        low_val
    if high > high_val
        high_val := high
        high_val

    //Create Box
    //x1, y1, x2, y2
    if showBackground
        bgBox := box.new(startTime, high_val, time, low_val, xloc=xloc.bar_time, bgcolor=backgroundColor, border_width=0)

    if showLines
        lowHLine := line.new(startTime, low_val, time, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        topHLine := line.new(startTime, high_val, time, high_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        leftVLine := line.new(startTime, high_val, startTime, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        rightVLine := line.new(time, high_val, time, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)

    //Create Middle line
    if showMiddleLine
        middleHLine := line.new(startTime, (high_val + low_val) / 2, time, (high_val + low_val) / 2, xloc=xloc.bar_time, color=middleLineColor, style=line.style_solid, width=linesWidth)

else
    if inExtend and extendLines and not inSession and timeframe.isintraday
        time1 = line.get_x1(lowHLine)
        time2 = line.get_x2(lowHLine)
        price = line.get_y1(lowHLine)
        line.delete(lowHLine)
        lowHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)
        
        time1 := line.get_x1(topHLine)
        time2 := line.get_x2(topHLine)
        price := line.get_y1(topHLine)
        line.delete(topHLine)
        topHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=linesWidth)

        time1 := line.get_x1(middleHLine)
        time2 := line.get_x2(middleHLine)
        price := line.get_y1(middleHLine)
        line.delete(middleHLine)
        middleHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=middleLineColor, style=line.style_solid, width=linesWidth)
        middleHLine


////////////////////////////////////////////


inSession4 = not na(time(timeframe.period, rangeTime4))

startTime4 = 0
startTime4 := inSession4 and not inSession4[1] ? time : startTime4[1]

//Box lines
var line lowHLine4 = na
var line topHLine4 = na
var line leftVLine4 = na
var line rightVLine4 = na
var line middleHLine4 = na
var box bgBox4 = na

var low_val4 = 0.0
var high_val4 = 0.0
if inSession4 and not inSession4[1]
    low_val4 := low
    high_val4 := high
    high_val4

// Plot lines
if inSession4 and timeframe.isintraday
    if inSession4[1]
        line.delete(lowHLine4)
        line.delete(topHLine4)
        line.delete(leftVLine4)
        line.delete(rightVLine4)
        line.delete(middleHLine4)
        box.delete(bgBox4)

    if low < low_val4
        low_val4 := low
        low_val4
    if high > high_val4
        high_val4 := high
        high_val4

    //Create Box
    //x1, y1, x2, y2
    if showBackground4
        bgBox4 := box.new(startTime4, high_val4, time, low_val4, xloc=xloc.bar_time, bgcolor=backgroundColor4, border_width=0)

    if showLines4
        lowHLine4 := line.new(startTime4, low_val4, time, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        topHLine4 := line.new(startTime4, high_val4, time, high_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        leftVLine4 := line.new(startTime4, high_val4, startTime4, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)
        rightVLine4 := line.new(time, high_val4, time, low_val4, xloc=xloc.bar_time, color=boxLineColor4, style=line.style_solid, width=linesWidth4)

////////////////////////////////////////////

inSession5 = not na(time(timeframe.period, rangeTime5))

startTime5 = 0
startTime5 := inSession5 and not inSession5[1] ? time : startTime5[1]

//Box lines
var line lowHLine5 = na
var line topHLine5 = na
var line leftVLine5 = na
var line rightVLine5 = na
var line middleHLine5 = na
var box bgBox5 = na

var low_val5 = 0.0
var high_val5 = 0.0
if inSession5 and not inSession5[1]
    low_val5 := low
    high_val5 := high
    high_val5

// Plot lines
if inSession5 and timeframe.isintraday
    if inSession5[1]
        line.delete(lowHLine5)
        line.delete(topHLine5)
        line.delete(leftVLine5)
        line.delete(rightVLine5)
        line.delete(middleHLine5)
        box.delete(bgBox5)

    if low < low_val5
        low_val5 := low
        low_val5
    if high > high_val5
        high_val5 := high
        high_val5

    //Create Box
    //x1, y1, x2, y2
    if showBackground5
        bgBox5 := box.new(startTime5, high_val5, time, low_val5, xloc=xloc.bar_time, bgcolor=backgroundColor5, border_width=0)

    if showLines5
        lowHLine5 := line.new(startTime5, low_val5, time, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        topHLine5 := line.new(startTime5, high_val5, time, high_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        leftVLine5 := line.new(startTime5, high_val5, startTime5, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)
        rightVLine5 := line.new(time, high_val5, time, low_val5, xloc=xloc.bar_time, color=boxLineColor5, style=line.style_solid, width=linesWidth5)

///////////////////////////////////////////////


//ZONA A CAMBIAR

ffRange = input.session(title='Time: ', defval='0200-0201', inline='a', group='FF')
ffcolor = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="FF")
ffStyle = input.string(title="-", defval=line.style_dotted, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="FF")


mmm1Range = input.session(title='Time: ', defval='0430-0431', inline='a', group='MMM1')
mmm1color = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="MMM1")
mmm1Style = input.string(title="-", defval=line.style_dotted, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="MMM1")


mmm2Range = input.session(title='Time: ', defval='0630-0631', inline='a', group='MMM2')
mmm2color = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="MMM2")
mmm2Style = input.string(title="-", defval=line.style_dotted, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="MMM2")


lcRange = input.session(title='Time: ', defval='1100-1101', inline='a', group='LC')
lccolor = input.color(color.new(color.black,20),title="Color:",inline="s_1",group="LC")
lcStyle = input.string(title="-", defval=line.style_dotted, options=[line.style_dotted, line.style_dashed, line.style_solid],inline="s_1",group="LC")


//Plot lines
in_session_ff = time(timeframe.period, ffRange)
sessionffActive = in_session_ff and timeframe.multiplier <= 240
var line ff = na
if sessionffActive and sessionffActive[1] == false
    ff := line.new(bar_index,low-0.001,bar_index,0,color=ffcolor, style=ffStyle)

in_session_mmm1 = time(timeframe.period, mmm1Range)
sessionmmm1Active = in_session_mmm1 and timeframe.multiplier <= 240
var line mmm1 = na
if sessionmmm1Active and sessionmmm1Active[1] == false
    mmm1 := line.new(bar_index,low-0.001,bar_index,0,color=mmm1color, style=mmm1Style)

in_session_mmm2 = time(timeframe.period, mmm2Range)
sessionmmm2Active = in_session_mmm2 and timeframe.multiplier <= 240
var line mmm2 = na
if sessionmmm2Active and sessionmmm2Active[1] == false
    mmm2 := line.new(bar_index,low-0.001,bar_index,0,color=mmm2color, style=mmm2Style)

in_session_lc = time(timeframe.period, lcRange)
sessionlcActive = in_session_lc and timeframe.multiplier <= 240
var line lc = na
if sessionlcActive and sessionlcActive[1] == false
    lc := line.new(bar_index,low-0.001,bar_index,0,color=lccolor, style=lcStyle)

//////////////////////////////////////////////////////////////////////



// Inputs

var GRP10 = "Daily Open"
daily = input.string(title='View', defval='Daily Open', group=GRP10)
_offset = input.int(0, title='Offset', minval=0, maxval=2)
o_color = input.color(color.new(#000000, 0), "Open Color", inline="1", group = GRP10)

// FUNCTIONS
t = time

isNewbar = not na(t) and (na(t[1]) or t > t[1])

tfInMinutes(simple string tf = "") =>
    float chartTf =
      timeframe.multiplier * (
      timeframe.isseconds ? 1. / 60             :
      timeframe.isminutes ? 1.                  :
      timeframe.isdaily   ? 60. * 24            :
      timeframe.isweekly  ? 60. * 24 * 7        :
      timeframe.ismonthly ? 60. * 24 * 30.4375  : na)
    float result = tf == "" ? chartTf : request.security(syminfo.tickerid, tf, chartTf)

inTimeframe(_t) => tfInMinutes(_t) > tfInMinutes(timeframe.period)


// Range
reso(exp, res) => request.security(syminfo.tickerid, res, exp, lookahead=barmerge.lookahead_on)

getData(_t, _var) =>
    o = reso(open[_offset], _t)
    show = _var != "Off" and inTimeframe(_t)
    _time = time(_t)
    newbar = na(_time[1]) or _time > _time[1]
    oc = _var == 'Daily Open'
    [o,   newbar,  oc]

// ---------- Daily ----------
[d_o, d_newbar, d_oc] = getData("D", daily)

if d_newbar 
    if d_oc
        line.new(x1=time, y1=d_o, x2=time_close("D"), y2=d_o, xloc=xloc.bar_time, style=line.style_dotted, color=o_color)
@gu5tavo71
Senior PineScript Developer
TradingView | Twitter | Freelancer | Telegram
Responder

Volver a “Pine Script”