You are on page 1of 10

//@version=5

indicator(title="Ichimoku By El Oráculo Josefina", shorttitle="Ichimoku By El


Oráculo Josefina", overlay = true, max_bars_back=500, max_lines_count = 500,
max_boxes_count = 500)
conversionPeriods = input.int(9, minval=1, title="Conversion Line Length")
basePeriods = input.int(26, minval=1, title="Base Line Length")
laggingSpan2Periods = input.int(52, minval=1, title="Leading Span B Length")
displacement = input.int(26, minval=1, title="Lagging Span")
donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
conversionLine = donchian(conversionPeriods)
baseLine = donchian(basePeriods)
leadLine1 = math.avg(conversionLine, baseLine)
leadLine2 = donchian(laggingSpan2Periods)
plot(conversionLine, color=#cdf321, title="Conversion Line")
plot(baseLine, color=color.white, title="Base Line")
plot(close, offset = -displacement + 1, color=color.aqua, title="Lagging
Span")
p1 = plot(leadLine1, offset = displacement - 1, color=color.new(#cdf321,30),
title="Leading Span A")
p2 = plot(leadLine2, offset = displacement - 1,
color=color.new(color.red,30),
title="Leading Span B")
plot(leadLine1 > leadLine2 ? leadLine1 : leadLine2, offset = displacement -
1, title = "Kumo Cloud Upper Line", display = display.none)
plot(leadLine1 < leadLine2 ? leadLine1 : leadLine2, offset = displacement -
1, title = "Kumo Cloud Lower Line", display = display.none)
fill(p1, p2, color = leadLine1 > leadLine2 ? color.new(#cdf321,80) :
color.new(color.red,80))

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

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

// -Datos
═════════════════════════════════════════════════════════════════════════════
═════════ //

//
-----------------------------------------------------------------------------
----------------- //
// Definiciones
-----------------------------------------------------------------------------
----- //

// Promedio móvil de volumen: Base


----------------------------------------------------------------- //
i_vSMA = ta.sma(nz(volume), input.int(89, 'Longitud promedio móvil de
volumen', group='Configuración general'))

// -Calculos
═════════════════════════════════════════════════════════════════════════════
═══ //

//
-----------------------------------------------------------------------------
----------------- //
// Definicion
-----------------------------------------------------------------------------
----- //

nzVolume2 = nz(volume)
risingVol = nzVolume2 >= nzVolume2[1]

bullCandle2 = close > open


bearCandle2 = close < open

risingPrice2 = close > close[1]


fallingProce2 = close < close[1]

lwstPrice2 = ta.lowest (low , 3)


hstPrice2 = ta.highest(high, 3)

x21 = timenow + 7 * math.round(ta.change(time))

//
-----------------------------------------------------------------------------
----------------- //
// Perfil de volumen (precio por
volumen)------------------------------------------------------------ //

f_drawLabelX2(_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_xy(id, _x, _y)
label.set_text(id, _text)
label.set_tooltip(id, _tooltip)
label.set_textcolor(id, _textcolor)

f_drawLineX2(_x11, _y1, _x21, _y2, _xloc, _extend, _color, _style, _width) =>
var id = line.new(_x11, _y1, _x21, _y2, _xloc, _extend, _color, _style,
_width)
line.set_xy1(id, _x11, _y1)
line.set_xy2(id, _x21, _y2)
line.set_color(id, _color)
grupo_Perfil_de_volumen = ' Perfil de volumen (precio por volumen)'
Informacion_Perfil_de_volumen = 'Perfil de (también conocido como precio por
volumen) es un estudio gráfico que muestra la actividad comercial durante un
período de tiempo específico en niveles de precios específicos.'

volumeProfile2 = input.bool(true, ' Perfil de volumen ', group


=grupo_Perfil_de_volumen, tooltip = Informacion_Perfil_de_volumen)
isValueArea2 = input.float(68, " %Valor Area Volumen", minval = 0,
maxval = 100 , group = grupo_Perfil_de_volumen) / 100
pointOfControl2 = input.bool(true, 'POC'
, inline='VA' , group = grupo_Perfil_de_volumen)
pocColor2 = input.color(color.new(#cdf321,30), ''
, inline='VA' , group = grupo_Perfil_de_volumen)
priceLevels = input.bool(true, 'Show de niveles Perfil de Volumen '
, inline='BBe', group = grupo_Perfil_de_volumen)
profileLevels2 = input.int(100, 'Número de filas', minval = 10, maxval =
170 , step = 10 , group = grupo_Perfil_de_volumen)
horizontalOffset = input.int(2, 'Desplazamiento horizontal ', minval = 0 ,
maxval = 100 , group = grupo_Perfil_de_volumen)
vpLookbackRange = 'Visible Range'
lookbackLength = 360
labelColor = input.color(color.new(color.white, 0), ''
, inline='BBe', group = grupo_Perfil_de_volumen)

priceHighest2FR = ta.highest(high, lookbackLength)


priceLowest2FR = ta.lowest (low , lookbackLength)

var startBarIndexX = 0
if time == chart.left_visible_bar_time
startBarIndexX := bar_index

if vpLookbackRange == 'Visible Range'


lookbackLength := last_bar_index - startBarIndexX

if vpLookbackRange == 'Visible Range'


lookbackLength := last_bar_index - startBarIndexX

f_getHighLow2() =>
var htf_h = 0., var htf_l = 0.

if vpLookbackRange == 'Visible Range'


if time == chart.left_visible_bar_time
htf_l := low
htf_h := high
else if time > chart.left_visible_bar_time
htf_l := math.min(low , htf_l)
htf_h := math.max(high, htf_h)
else
htf_h := priceHighest2FR
htf_l := priceLowest2FR

[htf_h, htf_l]

[priceHighest2, priceLowest2] = f_getHighLow2()


priceStep2 = (priceHighest2 - priceLowest2) / profileLevels2
barPriceLow22 = low
barPriceHigh2 = high
var levelAbovePoc2 = 0
var levelBelowPoc2 = 0
var pocLevel2 = 0

volumeStorage = array.new_float(profileLevels2 + 1, 0.)


volumeStorageB = array.new_float(profileLevels2 + 1, 0.)
var a_profile = array.new_box()

if barstate.islast and nzVolume2


if array.size(a_profile) > 0
for i = 1 to array.size(a_profile)
box.delete(array.shift(a_profile))

for barIndex = 0 to lookbackLength - 1


level = 0
for priceLevel = priceLowest2 to priceHighest2 by priceStep2
if barPriceHigh2[barIndex] >= priceLevel and
barPriceLow22[barIndex] < priceLevel + priceStep2
array.set(volumeStorage, level, array.get(volumeStorage,
level) + nzVolume2[barIndex] * ((barPriceHigh2[barIndex] -
barPriceLow22[barIndex]) == 0 ? 1 : priceStep2 / (barPriceHigh2[barIndex] -
barPriceLow22[barIndex])) )

if bullCandle2[barIndex]
array.set(volumeStorageB, level,
array.get(volumeStorageB, level) + nzVolume2[barIndex] *
((barPriceHigh2[barIndex] - barPriceLow22[barIndex]) == 0 ? 1 : priceStep2 /
(barPriceHigh2[barIndex] - barPriceLow22[barIndex])) )
level += 1

pocLevel2 := array.indexof(volumeStorage, array.max(volumeStorage))


totalVolumeTraded = array.sum(volumeStorage) * isValueArea2
valueArea = array.get(volumeStorage, pocLevel2)

while valueArea < totalVolumeTraded


if levelBelowPoc2 == 0 and levelAbovePoc2 == profileLevels2 - 1
break

volumeAbovePoc = 0.
if levelAbovePoc2 < profileLevels2 - 1
volumeAbovePoc := array.get(volumeStorage, levelAbovePoc2 + 1)

volumeBelowPoc = 0.
if levelBelowPoc2 > 0
volumeBelowPoc := array.get(volumeStorage, levelBelowPoc2 - 1)

if volumeAbovePoc >= volumeBelowPoc


valueArea += volumeAbovePoc
levelAbovePoc2 += 1
else
valueArea += volumeBelowPoc
levelBelowPoc2 -= 1

ratemo6a = 100*(priceLowest2 + (pocLevel2 + 0.50) * priceStep2)


/close
ratemo6 = 100-ratemo6a

ratemo6b = 100*(priceLowest2 + (levelBelowPoc2 + 0.00)* priceStep2)


/close
ratemo61 = 100-ratemo6b

ratemo6b2 = 100*(priceLowest2 + (levelAbovePoc2 +1.00)* priceStep2)


/close
ratemo612 = (100-ratemo6b2)

f_drawLineX2(bar_index - lookbackLength + 1, priceLowest2 + (pocLevel2


+ 0.50) * priceStep2, volumeProfile2 ? bar_index + horizontalOffset + 5 :
bar_index + 7, priceLowest2 + (pocLevel2 + 0.50) * priceStep2,
xloc.bar_index, extend.none, pointOfControl2 ? pocColor2 : #00000000,
line.style_solid, 4)

if priceLevels

f_drawLabelX2(volumeProfile2 ? bar_index + horizontalOffset + 20 :


bar_index + 15, priceLowest2 + (pocLevel2 + 0.50) *
priceStep2,"Josefina"+ " " + str.tostring(priceLowest2 + (pocLevel2
+ 0.50) * priceStep2, format.mintick), xloc.bar_index, yloc.price,
pointOfControl2 ? color.new(labelColor, 100) : #00000000,
label.style_label_right, pointOfControl2 ? #cdf321 : #00000000, size.normal,
text.align_left, 'Point Of Control Price')

f_drawLabelX2(volumeProfile2 ? bar_index + horizontalOffset + 28 :


bar_index + 15, priceLowest2 + (pocLevel2 + 0.50) *
priceStep2,str.tostring(ratemo6,format.mintick) +"%", xloc.bar_index,
yloc.price, pointOfControl2 ? color.new(labelColor, 100) : #00000000,
label.style_label_right, pointOfControl2 ? #cdf321 : #00000000, size.normal,
text.align_left, 'Point Of Control Price')

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

devTooltip = "Deviation is a multiplier that affects how much the price


should deviate from the previous pivot in order for the bar to become a new
pivot."
depthTooltip = "The minimum number of bars that will be taken into account
when calculating the indicator."
// pivots threshold
threshold_multiplier = input.float(title="Deviation", defval=3, minval=0,
tooltip=devTooltip)
depth = input.int(title="Depth", defval=10, minval=2, tooltip=depthTooltip)
reverse = input(false, "Reverse")
var extendLeft = input(false, "Extend Left | Extend Right", inline =
"Extend Lines")
var extendRight = input(false, "", inline = "Extend Lines")
var extending = extend.none
if extendLeft and extendRight
extending := extend.both
if extendLeft and not extendRight
extending := extend.left
if not extendLeft and extendRight
extending := extend.right
prices = input(true, "Show Prices")
levels = input(true, "Show Levels", inline = "Levels")
levelsFormat = input.string("Values", "", options = ["Values", "Percent"],
inline = "Levels")
labelsPosition = input.string("Left", "Labels Position", options = ["Left",
"Right"])
var int backgroundTransparency = input.int(85, "Background Transparency",
minval = 0, maxval = 100)

import TradingView/ZigZag/7 as zigzag

update()=>
var settings = zigzag.Settings.new(threshold_multiplier, depth,
color(na), false, false, false, false, "Absolute", true)
var zigzag.ZigZag zigZag = zigzag.newInstance(settings)
var zigzag.Pivot lastP = na
var float startPrice = na
var float height = na
settings.devThreshold := ta.atr(10) / close * 100 * threshold_multiplier
if zigZag.update()
lastP := zigZag.lastPivot()
if not na(lastP)
var line lineLast = na
if na(lineLast)
lineLast := line.new(lastP.start, lastP.end,
xloc=xloc.bar_time, color=color.gray, width=1, style=line.style_dashed)
else
line.set_first_point(lineLast, lastP.start)
line.set_second_point(lineLast, lastP.end)

startPrice := reverse ? lastP.start.price : lastP.end.price


endPrice = reverse ? lastP.end.price : lastP.start.price
height := (startPrice > endPrice ? -1 : 1) * math.abs(startPrice
- endPrice)
[lastP, startPrice, height]

[lastP, startPrice, height] = update()

_draw_line(price, col) =>


var id = line.new(lastP.start.time, lastP.start.price, time, price,
xloc=xloc.bar_time, color=col, width=1, extend=extending)
line.set_xy1(id, lastP.start.time, price)
line.set_xy2(id, lastP.end.time, price)
id

var table logo = table.new(position.bottom_right, 1, 1)


if barstate.islast

table.cell(logo, 0, 0, 'Ichimoku By El Oráculo Josefina',


text_size=size.normal, text_color=color.white)
_draw_label(price, txt, txtColor) =>
x = labelsPosition == "Left" ? lastP.start.time : not extendRight ?
lastP.end.time : time
labelStyle = labelsPosition == "Left" ? label.style_label_right :
label.style_label_left
align = labelsPosition == "Left" ? text.align_right : text.align_left
labelsAlignStrLeft = txt + '\n \n'
labelsAlignStrRight = ' ' + txt + '\n
\n'
labelsAlignStr = labelsPosition == "Left" ? labelsAlignStrLeft :
labelsAlignStrRight
var id = label.new(x=x, y=price, xloc=xloc.bar_time, text=labelsAlignStr,
textcolor=txtColor, style=labelStyle, textalign=align, color=#00000000)
label.set_xy(id, x, price)
label.set_text(id, labelsAlignStr)
label.set_textcolor(id, txtColor)

_wrap(txt) =>
"(" + str.tostring(txt, format.mintick) + ")"

_label_txt(level, price) =>


l = levelsFormat == "Values" ? str.tostring(level) : str.tostring(level *
100) + "%"
(levels ? l : "") + (prices ? _wrap(price) : "")
_crossing_level(series float sr, series float r) =>
(r > sr and r < sr[1]) or (r < sr and r > sr[1])

processLevel(bool show, float value, color colorL, line lineIdOther) =>


float m = value
r = startPrice + height * m
crossed = _crossing_level(close, r)
if show and not na(lastP)
lineId = _draw_line(r, colorL)
_draw_label(r, _label_txt(m, r), colorL)
if crossed
alert("Autofib: " + syminfo.ticker + " crossing level " +
str.tostring(value))
if not na(lineIdOther)
linefill.new(lineId, lineIdOther, color = color.new(colorL,
backgroundTransparency))
lineId
else
lineIdOther

show_0 = input(true, "", inline = "Level0")


value_0 = input(0, "", inline = "Level0")
color_0 = input(#787b86, "", inline = "Level0")

show_0_236 = input(true, "", inline = "Level0")


value_0_236 = input(0.236, "", inline = "Level0")
color_0_236 = input(#f44336, "", inline = "Level0")

show_0_382 = input(true, "", inline = "Level1")


value_0_382 = input(0.382, "", inline = "Level1")
color_0_382 = input(#81c784, "", inline = "Level1")

show_0_5 = input(true, "", inline = "Level1")


value_0_5 = input(0.5, "", inline = "Level1")
color_0_5 = input(#4caf50, "", inline = "Level1")

show_0_618 = input(true, "", inline = "Level2")


value_0_618 = input(0.618, "", inline = "Level2")
color_0_618 = input(#009688, "", inline = "Level2")

show_0_65 = input(false, "", inline = "Level2")


value_0_65 = input(0.65, "", inline = "Level2")
color_0_65 = input(#009688, "", inline = "Level2")

show_0_786 = input(true, "", inline = "Level3")


value_0_786 = input(0.786, "", inline = "Level3")
color_0_786 = input(#64b5f6, "", inline = "Level3")

show_1 = input(true, "", inline = "Level3")


value_1 = input(1, "", inline = "Level3")
color_1 = input(#787b86, "", inline = "Level3")

show_1_272 = input(false, "", inline = "Level4")


value_1_272 = input(1.272, "", inline = "Level4")
color_1_272 = input(#81c784, "", inline = "Level4")

show_1_414 = input(false, "", inline = "Level4")


value_1_414 = input(1.414, "", inline = "Level4")
color_1_414 = input(#f44336, "", inline = "Level4")

show_1_618 = input(false, "", inline = "Level5")


value_1_618 = input(1.618, "", inline = "Level5")
color_1_618 = input(#2962ff, "", inline = "Level5")

show_1_65 = input(false, "", inline = "Level5")


value_1_65 = input(1.65, "", inline = "Level5")
color_1_65 = input(#2962ff, "", inline = "Level5")

show_2_618 = input(false, "", inline = "Level6")


value_2_618 = input(2.618, "", inline = "Level6")
color_2_618 = input(#f44336, "", inline = "Level6")

show_2_65 = input(false, "", inline = "Level6")


value_2_65 = input(2.65, "", inline = "Level6")
color_2_65 = input(#f44336, "", inline = "Level6")

show_3_618 = input(false, "", inline = "Level7")


value_3_618 = input(3.618, "", inline = "Level7")
color_3_618 = input(#9c27b0, "", inline = "Level7")

show_3_65 = input(false, "", inline = "Level7")


value_3_65 = input(3.65, "", inline = "Level7")
color_3_65 = input(#9c27b0, "", inline = "Level7")

show_4_236 = input(false, "", inline = "Level8")


value_4_236 = input(4.236, "", inline = "Level8")
color_4_236 = input(#e91e63, "", inline = "Level8")

show_4_618 = input(false, "", inline = "Level8")


value_4_618 = input(4.618, "", inline = "Level8")
color_4_618 = input(#81c784, "", inline = "Level8")

show_neg_0_236 = input(false, "", inline = "Level9")


value_neg_0_236 = input(-0.236, "", inline = "Level9")
color_neg_0_236 = input(#f44336, "", inline = "Level9")

show_neg_0_382 = input(false, "", inline = "Level9")


value_neg_0_382 = input(-0.382, "", inline = "Level9")
color_neg_0_382 = input(#81c784, "", inline = "Level9")

show_neg_0_618 = input(false, "", inline = "Level10")


value_neg_0_618 = input(-0.618, "", inline = "Level10")
color_neg_0_618 = input(#009688, "", inline = "Level10")

show_neg_0_65 = input(false, "", inline = "Level10")


value_neg_0_65 = input(-0.65, "", inline = "Level10")
color_neg_0_65 = input(#009688, "", inline = "Level10")

lineId0 = processLevel(show_neg_0_65, value_neg_0_65, color_neg_0_65,


line(na))
lineId1 = processLevel(show_neg_0_618, value_neg_0_618, color_neg_0_618,
lineId0)
lineId2 = processLevel(show_neg_0_382, value_neg_0_382, color_neg_0_382,
lineId1)
lineId3 = processLevel(show_neg_0_236, value_neg_0_236, color_neg_0_236,
lineId2)
lineId4 = processLevel(show_0, value_0, color_0, lineId3)
lineId5 = processLevel(show_0_236, value_0_236, color_0_236, lineId4)
lineId6 = processLevel(show_0_382, value_0_382, color_0_382, lineId5)
lineId7 = processLevel(show_0_5, value_0_5, color_0_5, lineId6)
lineId8 = processLevel(show_0_618, value_0_618, color_0_618, lineId7)
lineId9 = processLevel(show_0_65, value_0_65, color_0_65, lineId8)
lineId10 = processLevel(show_0_786, value_0_786, color_0_786, lineId9)
lineId11 = processLevel(show_1, value_1, color_1, lineId10)
lineId12 = processLevel(show_1_272, value_1_272, color_1_272, lineId11)
lineId13 = processLevel(show_1_414, value_1_414, color_1_414, lineId12)
lineId14 = processLevel(show_1_618, value_1_618, color_1_618, lineId13)
lineId15 = processLevel(show_1_65, value_1_65, color_1_65, lineId14)
lineId16 = processLevel(show_2_618, value_2_618, color_2_618, lineId15)
lineId17 = processLevel(show_2_65, value_2_65, color_2_65, lineId16)
lineId18 = processLevel(show_3_618, value_3_618, color_3_618, lineId17)
lineId19 = processLevel(show_3_65, value_3_65, color_3_65, lineId18)
lineId20 = processLevel(show_4_236, value_4_236, color_4_236, lineId19)
lineId21 = processLevel(show_4_618, value_4_618, color_4_618, lineId20)

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

/////////////////////////////////////////////////// emAS

EMA20 = ta.ema(close,20)
EMA50 = ta.ema(close,50)
EMA100 = ta.ema(close,100)
EMA200 = ta.ema(close,200)

plot(EMA20, color = color.red, linewidth=2)


plot(EMA50, color = color.blue, linewidth=2)
plot(EMA100, color = color.orange, linewidth=2)
plot(EMA200, color = color.green, linewidth=2)

You might also like