// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © jjandamio //************** RunLog **************************** //Detectado un error en el graficado de los niveles L1 y S1 ya que no consideraba bien el mayor entre ClosePA y OpenPA //Cambio de las reglas de George para volatilidades por encima de 35, pasamos de 65 a 70 puntos. //20220402 Detectado y corregido error en la etiqueta de GAP //20220414 Añadimos el nº de puntos del half gap //20220519 el horario de verano se cambia el último domingo de marzo y el de invierno el último documento de octubre //20230104 por el momento este cambio se lo he realizado al andamio de invierno, una vez testeado, trasladar el codigo al andamio de verano. // a) Se ha modificado el código de las etiquetas de los GAPs para que sólo muestre la última etiqueta // b) Se ha modificado el plot de las zonas para que incluya los puntos de entrada en los casos en los que existan GAPs. //@version=5 indicator("Andamio Verano", overlay=true) // Zona horaria Overnight y Almuerzo t1 = time(timeframe.period, "2203-0800,1300-1430", "GMT+1") // en horario de verano cambiar a GMT+2 y en horario de invierno cambiar a GMT+1 // Valor VDAX-new (trandingview sólo da un valor al día, utilizamos del VIX del S&P500) VDAX = request.security("DV1X", "D", close, barmerge.gaps_off, barmerge.lookahead_on) //Índice de Volatilidad del DAX, horario limitado VIXSP = request.security("VIX", "1", close, barmerge.gaps_off, barmerge.lookahead_on) //Índice de Volatilidad del S&P500, al minuto "SÓLO COTIZA DE 15:30 A 22:14" VIXDOW = request.security("VXD", "1", close, barmerge.gaps_off, barmerge.lookahead_on) //Índice de Volatilidad del Dow, al minuto "SÓLO COTIZA DE 15:30 A 22:14" VSTOXX = request.security("FVS1!", "1", close, barmerge.gaps_off, barmerge.lookahead_on) //Índice de Volatilidad del Stoxx50, al minuto "SÓLO COTIZA DE 08:00 A 22:00" max_vola = math.max(VDAX,0)//VIXSP,VIXDOW,VSTOXX) bgcolor(t1 ? max_vola > 30 ? color.new(color.red, 90) : color.new(color.blue, 90) : na) //añado un sombreado rojo claro para aquella volatilidades > 30 donde los GAPs no deben operarse DAX_CIERRE = request.security("XETR:DAX", "1", close) //Índice DAX // volatilidad <= 20 -----> 40 puntos // volatilidad entre 20-25 -----> 50 puntos // volatilidad entre 25-30 -----> 55 puntos // Según la versión 2022 en el intervalo 30-35 se asume lo que antes hacía en el >35 // volatilidad entre 30-35 -----> 70 puntos para cortos y 140 la primera zona de largos // (versión 2021) volatilidad entre 30-35 -----> 65 puntos // (versión 2021) volatilidad > 35 -----> 70 puntos para cortos y 140 la primera zona de largos // (versión Sep-2022) volatilidad > 35 -----> 65 puntos para cortos y 100 la primera zona de largos zona=0 //la variable zona, sirve para crear las segundas zonas, es decir, cuánto le añadimos a la primera zona. zonaLargos=0 if max_vola <= 20 zona := 40 zonaLargos := 40 else if max_vola <= 25 zona := 50 zonaLargos := 50 else if max_vola <= 30 zona := 55 zonaLargos := 55 else if max_vola <= 35 zona := 65 zonaLargos := 100 else if max_vola > 35 zona := 70 zonaLargos := 140 // graficado de líneas horizontales // en horario de verano cambiar a GMT+2 y en horario de invierno cambiar a GMT+1 linezonetime = time("1", "0800-1430","GMT+1") linezonetime_extended = time("1", "0800-2159","GMT+1") //CloseValueTime = time("1", "2145-2200","GMT+2") OpenValueTime = time("1", "0800-0801","GMT+1") DAXValueTime = time("1", "1736-0859","GMT+1") //define la línea de cierre // ————— Converts current chart timeframe into a float minutes value. f_resInMinutes() => _resInMinutes = 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) f_resInMinutes() // en horario de verano cambiar a GMT+2 y en horario de invierno cambiar a GMT+1 var CloseValueTime = 0.0 if f_resInMinutes() < 2 CloseValueTime := time_close(timeframe.period, "2159-2200","GMT+1") else if f_resInMinutes() < 4 CloseValueTime := time_close(timeframe.period, "2157-2158","GMT+1") else if f_resInMinutes() < 6 CloseValueTime := time_close(timeframe.period, "2155-2156","GMT+1") else if f_resInMinutes() < 16 CloseValueTime := time_close(timeframe.period, "2145-2146","GMT+1") else if f_resInMinutes() < 31 CloseValueTime := time_close(timeframe.period, "2130-2131","GMT+1") else if f_resInMinutes() < 46 CloseValueTime := time_close(timeframe.period, "2115-2116","GMT+1") else if f_resInMinutes() < 61 CloseValueTime := time_close(timeframe.period, "2100-2101","GMT+1") // define la línea de cierre del día anterior (verde) var ClosePA = 0.0 if CloseValueTime if not CloseValueTime[1] ClosePA := close // define la línea de apertura (roja) var OpenPA = 0.0 if OpenValueTime if not OpenValueTime[1] OpenPA := open // define el valor del DAX (índice) del día anterior para establecer las zonas los días que exista GAP Doble o Wide var CloseDAX = 0.0 if DAXValueTime if not DAXValueTime[1] CloseDAX := DAX_CIERRE //formación de GAPs // Si el max_vola > 30 los GAPs no se negocian y las zonas se generan a partir de la posición de apertura. GAP_WIDE = false GAP_DOBLE = false GAP_MONSTER = false var label id = na label.delete(id[1]) if max_vola > 30 GAP_WIDE := false GAP_DOBLE := false GAP_MONSTER := false else if math.abs(OpenPA - ClosePA) > 300 GAP_MONSTER := true if barstate.islast and linezonetime id := label.new(bar_index, y=high+200, text="GAP MONSTER\n Volatilidad " + str.tostring(max_vola) + "\n Half GAP "+ str.tostring( math.abs(OpenPA-ClosePA)/2 + math.min(OpenPA,ClosePA) ) + "\n Nº Puntos "+ str.tostring( math.abs(OpenPA-ClosePA)/2), style=label.style_label_down, yloc=yloc.price, color=color.purple, textcolor=color.white, size=size.small) else if ((((CloseDAX < ClosePA) and (ClosePA < OpenPA)) or ((CloseDAX > ClosePA) and (ClosePA > OpenPA))) and math.abs(CloseDAX - ClosePA) >= 10 and math.abs(OpenPA - CloseDAX) >= 70) and not GAP_MONSTER GAP_DOBLE := true if barstate.islast and linezonetime id := label.new(bar_index, y=high+200, text="GAP Doble\n Volatilidad " + str.tostring(max_vola) + "\n Half GAP "+ str.tostring( math.abs(OpenPA-ClosePA)/2 + math.min(OpenPA,ClosePA) ) + "\n Nº Puntos "+ str.tostring( math.abs(OpenPA-ClosePA)/2), style=label.style_label_down, yloc=yloc.price, color=color.purple, textcolor=color.white, size=size.small) else if not GAP_DOBLE and max_vola < 20 and not GAP_MONSTER and (math.abs(OpenPA - ClosePA) >= 40) // and not GAP_MONSTER GAP_WIDE := true if barstate.islast and linezonetime id := label.new(bar_index, y=high+200, text="GAP\n Inverso\n Volatilidad "+ str.tostring(max_vola) + "\n Half GAP "+ str.tostring( math.abs(OpenPA-ClosePA)/2 + math.min(OpenPA,ClosePA) ) + "\n Nº Puntos "+ str.tostring( math.abs(OpenPA-ClosePA)/2), style=label.style_label_down, yloc=yloc.price, color=color.purple, textcolor=color.white, size=size.small) else if not GAP_DOBLE and max_vola >= 20 and not GAP_MONSTER and (math.abs(OpenPA - ClosePA) >= 70) // and not GAP_MONSTER label.delete(id[1]) GAP_WIDE := true if barstate.islast and linezonetime id := label.new(bar_index, y=high+200, text="GAP\n Inverso\n Volatilidad "+ str.tostring(max_vola) + "\n Half GAP "+ str.tostring( math.abs(OpenPA-ClosePA)/2 + math.min(OpenPA,ClosePA) ) + "\n Nº Puntos "+ str.tostring( math.abs(OpenPA-ClosePA)/2), style=label.style_label_down, yloc=yloc.price, color=color.purple, textcolor=color.white, size=size.small) var L1 =0.0 var L2 =0.0 var LStop =0.0 var S1 =0.0 var S2 =0.0 var SStop =0.0 if linezonetime if not linezonetime[1] if max_vola > 30 L1 := OpenPA - zonaLargos //Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := OpenPA + zona //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 else if GAP_DOBLE and (OpenPA > ClosePA) L1 := ClosePA - zonaLargos//Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := OpenPA //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 else if GAP_DOBLE and (OpenPA < ClosePA) L1 := OpenPA//Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := ClosePA + zona //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 else if GAP_WIDE and (OpenPA > ClosePA) L1 := ClosePA//Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := OpenPA + zona //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 else if GAP_WIDE and (OpenPA < ClosePA) L1 := OpenPA - zonaLargos//Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := ClosePA //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 else if not GAP_DOBLE and not GAP_WIDE and max_vola <= 30 L1 := math.min(OpenPA, ClosePA) - zonaLargos //Intervalo L2 := L1 - zona //Intervalo LStop := L2 - 35 S1 := math.max(OpenPA, ClosePA) + zona //Intervalo S2 := S1 + zona //Intervalo SStop := S2 + 35 plot(linezonetime_extended ? OpenPA : na, title="Open at time", color=color.new(color.red, 50), linewidth=1, style=plot.style_linebr, offset=1) plot(linezonetime_extended ? ClosePA : na, title="Close at time", color=color.new(color.teal, 50), linewidth=1, style=plot.style_linebr, offset=1) plot(linezonetime ? L1 : na, title="L1", color=color.blue, linewidth=2, style=plot.style_linebr) plot(linezonetime ? L2 : na, title="L2", color=color.fuchsia, linewidth=2, style=plot.style_linebr) plot(linezonetime ? LStop : na, title="L Stop", color=color.black, linewidth=1, style=plot.style_linebr) plot(linezonetime ? S1 : na, title="L1", color=color.blue, linewidth=2, style=plot.style_linebr) plot(linezonetime ? S2 : na, title="L2", color=color.fuchsia, linewidth=2, style=plot.style_linebr) plot(linezonetime ? SStop : na, title="L Stop", color=color.black, linewidth=1, style=plot.style_linebr) plot(DAXValueTime ? CloseDAX : na, title="Previous DAX Close", color=color.new(color.yellow, 10), linewidth=2, style=plot.style_linebr)