Gold & Nifty Indicator
Gold & Nifty Indicator
if show_TPSL_SHORT
// Variables para las líneas horizontales
var line4 = line.new(x1=bar_index, y1=valorCelda4, x2=bar_index[1],
y2=valorCelda4, color=color.red, width=1, extend = extend.left)
var line5 = line.new(x1=bar_index, y1=valorCelda5, x2=bar_index[1],
y2=valorCelda5, color=color.green, width=1, extend = extend.left)
var labelSL_SHORT = label.new(x=na, y=na, text="SL", color=color.red,
textcolor=color.white,style=label.style_label_down)
var labelTP_SHORT = label.new(x=na, y=na, text="TP", color=color.green,
textcolor=color.white,style=label.style_label_up)
//====================colour bar=====================//
mysignal = ta.ema(close, 12) - ta.ema(close, 26)
barcolor(mysignal[0] > mysignal[1] ? color.green : color.red)
label.new(min_x1,min,'??',color=miss_pl_css,style=label.style_label_up,size=size.sm
all,
tooltip=str.tostring(min,'#.####'))
zigzag :=
line.new(px1,py1,min_x1,min,color=miss_ph_css,style=line.style_dashed)
px1 := min_x1,py1 := min
line.set_x2(ghost_level[1],px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
else if ph2 < max
label.new(max_x1,max,'??',color=miss_ph_css,style=label.style_label_down,size=size.
small,
tooltip=str.tostring(max,'#.####'))
label.new(follow_min_x1,follow_min,'??',color=miss_pl_css,style=label.style_label_u
p,size=size.small,
tooltip=str.tostring(min,'#.####'))
zigzag :=
line.new(px1,py1,max_x1,max,color=miss_pl_css,style=line.style_dashed)
px1 := max_x1,py1 := max
line.set_x2(ghost_level[1],px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
zigzag :=
line.new(px1,py1,follow_min_x1,follow_min,color=miss_ph_css,style=line.style_dashed
)
px1 := follow_min_x1,py1 := follow_min
line.set_x2(ghost_level,px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
if show_reg
label.new(n-
length2,ph2,'?',textcolor=label_css,color=reg_ph_css,style=label.style_label_down,s
ize=size.small,
tooltip=str.tostring(ph2,'#.####'))
zigzag := line.new(px1,py1,n-length2,ph2,color=miss_pl_css,style=ph2 < max
or os[1] == 1 ? line.style_dashed : line.style_solid)
py1 := ph2,px1 := n-length2,os := 1,max := ph2,min := ph2
if pl2
if show_miss
if os[1] == 0
label.new(max_x1,max,'??',color=miss_ph_css,style=label.style_label_down,size=size.
small,
tooltip=str.tostring(max,'#.####'))
zigzag :=
line.new(px1,py1,max_x1,max,color=miss_pl_css,style=line.style_dashed)
px1 := max_x1,py1 := max
line.set_x2(ghost_level[1],px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
else if pl2 > min
label.new(follow_max_x1,follow_max,'??',color=miss_ph_css,style=label.style_label_d
own,size=size.small,
tooltip=str.tostring(max,'#.####'))
label.new(min_x1,min,'??',color=miss_pl_css,style=label.style_label_up,size=size.sm
all,
tooltip=str.tostring(min,'#.####'))
zigzag :=
line.new(px1,py1,min_x1,min,color=miss_ph_css,style=line.style_dashed)
px1 := min_x1,py1 := min
line.set_x2(ghost_level[1],px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_pl_css,50),width=2)
zigzag :=
line.new(px1,py1,follow_max_x1,follow_max,color=miss_pl_css,style=line.style_dashed
)
px1 := follow_max_x1,py1 := follow_max
line.set_x2(ghost_level,px1)
ghost_level :=
line.new(px1,py1,px1,py1,color=color.new(reg_ph_css,50),width=2)
if show_reg
label.new(n-
length2,pl2,'?',textcolor=label_css,color=reg_pl_css,style=label.style_label_up,siz
e=size.small,
tooltip=str.tostring(pl2,'#.####'))
zigzag := line.new(px1,py1,n-length2,pl2,color=miss_ph_css,style=pl2 > min
or os[1] == 0 ? line.style_dashed : line.style_solid)
py1 := pl2,px1 := n-length2,os := 0,max := pl2,min := pl2
var label lbl = na
if barstate.islast
x = 0,y = 0.
prices = array.new_float(0)
prices_x = array.new_int(0)
for i = 0 to n-px1-1
array.push(prices,os==1?low[i]:high[i])
array.push(prices_x,n-i)
label.delete(lbl[1])
if os == 1
y := array.min(prices)
x := array.get(prices_x,array.indexof(prices,y))
if show_miss
lbl :=
label.new(x,y,'??',color=miss_pl_css,style=label.style_label_up,size=size.small,
tooltip=str.tostring(y,'#.####'))
else
y := array.max(prices)
x := array.get(prices_x,array.indexof(prices,y))
if show_miss
lbl :=
label.new(x,y,'??',color=miss_ph_css,style=label.style_label_down,size=size.small,
tooltip=str.tostring(y,'#.####'))
if show_miss
line.delete(line.new(px1,py1,x,y,color=os == 1 ? miss_ph_css :
miss_pl_css,style=line.style_dashed)[1])
line.delete(line.new(x,y,n,y,color = color.new(os == 1 ? miss_ph_css :
miss_pl_css,50),width=2)[1])
//-----------------------------------------------------------------------------}
// áreas de oferta y demanda
//------------------------------------------------------------------------------
per = input.float(10., 'Threshold %', minval = 0, maxval = 100)
div = input.int(50, 'Resolution' , minval = 2, maxval = 500)
tf = input.timeframe('', 'Intrabar TF')
//Colors
showSupply = input(true ,'Supply ', inline = 'supply', group = 'SUPPLY AND
DEMAND')
supplyCss = input(#2157f3, '' , inline = 'supply', group = 'SUPPLY AND
DEMAND')
supplyArea = input(true ,'Area' , inline = 'supply', group = 'SUPPLY AND
DEMAND')
supplyAvg = input(true ,'Average' , inline = 'supply', group = 'SUPPLY AND
DEMAND')
supplyWavg = input(true ,'Weighted' , inline = 'supply', group = 'SUPPLY AND
DEMAND')
showEqui = input(true ,'Equilibrium' , inline = 'equi' , group = 'SUPPLY AND
DEMAND')
equiCss = input(color.gray, '' , inline = 'equi' , group = 'SUPPLY AND
DEMAND')
equiAvg = input(true ,'Average' , inline = 'equi' , group = 'SUPPLY AND
DEMAND')
equiWavg = input(true ,'Weighted' , inline = 'equi' , group = 'SUPPLY AND
DEMAND')
showDemand = input(true ,'Demand ' , inline = 'demand', group = 'SUPPLY AND
DEMAND')
demandCss = input(#ff5d00, '' , inline = 'demand', group = 'SUPPLY AND
DEMAND')
demandArea = input(true ,'Area' , inline = 'demand', group = 'SUPPLY AND
DEMAND')
demandAvg = input(true ,'Average' , inline = 'demand', group = 'SUPPLY AND
DEMAND')
demandWavg = input(true ,'Weighted' , inline = 'demand', group = 'SUPPLY AND
DEMAND')
//UDT's
type bin
float lvl
float prev
float sum
float prev_sum
float csum
float avg
bool isreached
type area
box bx
line avg
line wavg
//Functions
get_hlv()=> [high, low, volume]
method set_area(area id, x1, top, btm, avg, wavg, showArea, showAvg, showWavg)=>
if showArea
id.bx.set_lefttop(x1, top)
id.bx.set_rightbottom(n, btm)
if showAvg
id.avg.set_xy1(x1, avg)
id.avg.set_xy2(n, avg)
if showWavg
id.wavg.set_xy1(x1, wavg)
id.wavg.set_xy2(n, wavg)
//Main variables
var x1 = 0
var csum = 0.
//Intrabar data
[h, l, v] = request.security_lower_tf(syminfo.tickerid, tf, get_hlv())
//Init on left bar
if time == chart.left_visible_bar_time
max := high
min := low
csum := volume
x1 := n
else //Accumulate
max := math.max(high, max)
min := math.min(low, min)
csum += volume
//Set zones
var supply_area = area.new(
box.new(na, na, na, na, na, bgcolor = color.new(supplyCss, 90),text = "::: Supply
:::",text_color=color.white)
, line.new(na, na, na, na, color = supplyCss)
, line.new(na, na, na, na, color = supplyCss, style = line.style_dashed))
var demand_area = area.new(
box.new(na, na, na, na, na, bgcolor = color.new(demandCss, 90),text = "::: Demand
:::",text_color=color.white)
, line.new(na, na, na, na, color = demandCss)
, line.new(na, na, na, na, color = demandCss, style = line.style_dashed))
var equi = line.new(na, na, na, na, color = equiCss)
var wequi = line.new(na, na, na, na, color = equiCss, style = line.style_dashed)
var float supply_wavg = na
var float demand_wavg = na
if time == chart.right_visible_bar_time
r = (max - min) / div
supply = bin.new(max, max, 0, 0, 0, 0, false)
demand = bin.new(min, min, 0, 0, 0, 0, false)
//Loop trough intervals
for i = 0 to div-1
supply.lvl -= r
demand.lvl += r
//Accumulated volume column
if not supply.isreached and showSupply and supplyArea
box.new(x1, supply.prev, x1 + int(supply.sum / csum * (n - x1)),
supply.lvl, na
, bgcolor = color.new(supplyCss, 50))
if not demand.isreached and showDemand and demandArea
box.new(x1, demand.lvl, x1 + int(demand.sum / csum * (n - x1)),
demand.prev, na
, bgcolor = color.new(demandCss, 50))
//Loop trough bars
for j = 0 to (n - x1)-1
//Loop trough intrabars
for k = 0 to (v[j]).size()-1
//Accumulate if within upper internal
supply.sum += (h[j]).get(k) > supply.lvl and (h[j]).get(k) <
supply.prev ? (v[j]).get(k) : 0
supply.avg += supply.lvl * (supply.sum - supply.prev_sum)
supply.csum += supply.sum - supply.prev_sum
supply.prev_sum := supply.sum
//Accumulate if within lower interval
demand.sum += (l[j]).get(k) < demand.lvl and (l[j]).get(k) >
demand.prev ? (v[j]).get(k) : 0
demand.avg += demand.lvl * (demand.sum - demand.prev_sum)
demand.csum += demand.sum - demand.prev_sum
demand.prev_sum := demand.sum
//Test if supply accumulated volume exceed threshold and set box
if supply.sum / csum * 100 > per and not supply.isreached
avg = math.avg(max, supply.lvl)
supply_wavg := supply.avg / supply.csum
//Set Box/Level coordinates
if showSupply
supply_area.set_area(x1, max, supply.lvl, avg, supply_wavg,
supplyArea, supplyAvg, supplyWavg)
supply.isreached := true
//Test if demand accumulated volume exceed threshold and set box
if demand.sum / csum * 100 > per and not demand.isreached and
showDemand
avg = math.avg(min, demand.lvl)
demand_wavg := demand.avg / demand.csum
//Set Box/Level coordinates
if showDemand
demand_area.set_area(x1, demand.lvl, min, avg, demand_wavg,
demandArea, demandAvg, demandWavg)
demand.isreached := true
if supply.isreached and demand.isreached
break
if supply.isreached and demand.isreached and showEqui
//Set equilibrium
if equiAvg
avg = math.avg(max, min)
equi.set_xy1(x1, avg)
equi.set_xy2(n, avg)
//Set weighted equilibrium
if equiWavg
wavg = math.avg(supply_wavg, demand_wavg)
wequi.set_xy1(x1, wavg)
wequi.set_xy2(n, wavg)
break
supply.prev := supply.lvl
demand.prev := demand.lvl
//============================= SCALPING PULLBACK TOOL
=================================================//
HiLoLen = 34
fastEMAlength = 12
mediumEMAlength = 200
slowEMAlength = 600
ShowFastEMA = input(true, title="Show FastEMA", group = "SCALPING PULLBACK
TOOL")
ShowFractals = input(true, title="Show Fractals", group = "SCALPING PULLBACK
TOOL")
ShowBuySell = input(true, title="Show Buy/Sell Alert Arrows", group = "SCALPING
PULLBACK TOOL")
filterBW = false
ShowBarColor = true
Lookback = 3
DelayArrow = false
Delay = DelayArrow ? 1 : 0
ShowTrendBGcolor= true
UseHAcandles = true
haClose = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, close) : close
haOpen = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, open) : open
haHigh = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, high) : high
haLow = UseHAcandles ? request.security(ticker.heikinashi(syminfo.tickerid),
timeframe.period, low) : low
isRegularFractal(mode) =>
ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1]
and
high[1] > high[0] : mode == -1 ?
low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] <
low[0] :
false
ret
isBWFractal(mode) =>
ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >=
high[1] and
high[2] > high[0] : mode == -1 ?
low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] <
low[0] :
false
ret
fastEMA = ta.ema(haClose, fastEMAlength)
mediumEMA = ta.ema(haClose, mediumEMAlength)
slowEMA = ta.ema(haClose, slowEMAlength)
pacC = ta.ema(haClose, HiLoLen)
pacL = ta.ema(haLow, HiLoLen)
pacU = ta.ema(haHigh, HiLoLen)
TrendDirection = fastEMA > mediumEMA and pacL > mediumEMA ? 1 : fastEMA < mediumEMA
and pacU < mediumEMA ? -1 : 0
filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
valuewhen_H0 = ta.valuewhen(filteredtopf == true, high[2], 0)
valuewhen_H1 = ta.valuewhen(filteredtopf == true, high[2], 1)
valuewhen_H2 = ta.valuewhen(filteredtopf == true, high[2], 2)
higherhigh = filteredtopf == false ? false :
valuewhen_H1 < valuewhen_H0 and valuewhen_H2 < valuewhen_H0
lowerhigh = filteredtopf == false ? false :
valuewhen_H1 > valuewhen_H0 and valuewhen_H2 > valuewhen_H0
valuewhen_L0 = ta.valuewhen(filteredbotf == true, low[2], 0)
valuewhen_L1 = ta.valuewhen(filteredbotf == true, low[2], 1)
valuewhen_L2 = ta.valuewhen(filteredbotf == true, low[2], 2)
higherlow = filteredbotf == false ? false :
valuewhen_L1 < valuewhen_L0 and valuewhen_L2 < valuewhen_L0
lowerlow = filteredbotf == false ? false :
valuewhen_L1 > valuewhen_L0 and valuewhen_L2 > valuewhen_L0
TradeDirection = 0
TradeDirection := nz(TradeDirection[1])
pacExitU = haOpen < pacU and haClose > pacU and
ta.barssince(haClose<pacC)<=Lookback
pacExitL = haOpen > pacL and haClose < pacL and
ta.barssince(haClose>pacC)<=Lookback
Buy = TrendDirection == 1 and pacExitU
Sell = TrendDirection == -1 and pacExitL
TradeDirection := TradeDirection == 1 and haClose<pacC ? 0 :
TradeDirection == -1 and haClose>pacC ? 0 :
TradeDirection == 0 and Buy ? 1 :
TradeDirection == 0 and Sell ? -1 : TradeDirection
// Show buy/sell arrows and Draw the EMA ribbon and fractals
plot(ShowFastEMA ? fastEMA : na, color=color.yellow, linewidth=1, transp=20,
title="fastEMA")
plotshape(ShowFractals ? filteredtopf : na, title='Filtered Top Fractals',
style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
plotshape(ShowFractals ? filteredbotf : na, title='Filtered Bottom Fractals',
style=shape.triangleup, location=location.belowbar, color=color.lime, offset=-2)
plotarrow(ShowBuySell and nz(TradeDirection[1+Delay]) == 0 and
TradeDirection[Delay] != 0 ? TradeDirection[Delay] : na, offset=-Delay,
colorup=color.green, colordown=color.red, transp=20, minheight=20, maxheight=50,
title="Buy/Sell Arrow")
//------------------------------------------------------------------------------
// Settings
//-----------------------------------------------------------------------------{
lmTT = 'Presents liquidations on the price chart by measuring the highest leverage
value of longs and shorts that have been potentially liquidated on the last chart
bar.\n\n' +
'Liquidations meter allows traders to\n -gauge the momentum of the bar,\n
-identify the strength of the bulls and bears, and\n -identify probable
reversal/exhaustion points\n\n' +
'Here with liquidations, we refer to the process of forcibly closing a
trader\'s position in the market'
lmSH = input.bool(true, 'Liquidations Meter', group = 'Liquidations Meter',
tooltip = lmTT)
refPS = input.string("open", "Base Price", options = ["open", "close", "oc2",
"hl2", "ooc3", "occ3", "hlc3", "ohlc4", "hlcc4"], group = 'Liquidations Meter')
clTT = 'The liquidation price calculator is useful for leverage trading traders
who want to know how much risk they can take for each trade.\n\n' +
'This tool uses a formula to calculate the liquidation price based on the
entry price + leverage ratio.\n\n' +
'Other factors such as leveraged fees, position size, and other interest
payments have been excluded since they are variables that don’t directly affect the
level of liquidation of a leveraged position.\n\n' +
'This calculator also assumes that traders are using an isolated margin
for one single position and does not take into consideration the additional margin
they might have in their account.'
clSH = input.bool(true, 'Liquidation Price Calculator', group = clGR, tooltip =
clTT)
epTT = 'Defines the entry price.\nIf the entry price is set to 0, then the
selected \'Base Price\' value is assumed as entry price\n\n' +
'Tip: Before entering a trade, setting base price to \'close\' and entry
price to remain at 0 will allow the traders to easily evaluate the risk and reward
situation of any given setup'
clEP = input.float(0., 'Entry Price', group = clGR, tooltip = epTT)
lrTT = 'Leverage allows traders to borrow funds in order to enter a position
larger than their own funds permit\n\n' +
'the higher the leverage ratio the higher the risk.\n\nIt is important to
be aware that when the leverage ratio is increased, the liquidation price moves
closer to the entry price, meaning a higher risk trader\'s position will have'
clLR = input.float(10., 'Leverage', minval = 0, group = clGR, tooltip = lrTT)
dbTT = 'The bar statistics option enables measuring and presenting trading
activity, volatility, and probable liquidations for the last chart bar'
dbSH = input.bool(true, 'Show Bar Statistics', group = 'Dashboard', tooltip =
dbTT)
//-----------------------------------------------------------------------------}
// User Defined Types
//-----------------------------------------------------------------------------{
type bar
float o = open
float h = high
float l = low
float c = close
float v = volume
int i = bar_index
//-----------------------------------------------------------------------------}
// Variables
//-----------------------------------------------------------------------------{
bar b = bar.new()
vST = ''
//-----------------------------------------------------------------------------}
// Functions/methods
//-----------------------------------------------------------------------------{
f_gSZ(_s) =>
switch _s
'Tiny' => size.tiny
'Small' => size.small
=> size.normal
f_gSRC(_s) =>
switch _s
"open" => open
"close" => close
"oc2" => math.avg(open, close)
"hl2" => hl2
"ooc3" => math.avg(open, open , close)
"occ3" => math.avg(open, close, close)
"hlc3" => hlc3
"ohlc4" => ohlc4
"hlcc4" => hlcc4
//-----------------------------------------------------------------------------}
// Calculations
//-----------------------------------------------------------------------------{
nzV = nz(b.v)
lSZ = f_gSZ(lcLS)
refP = f_gSRC(refPS)
if aLQ.size() > 0
for i = 1 to aLQ.size()
box.delete(aLQ.shift())
off = lpSH ? 7 : 0
for i = 1 to 7
if (refP - b.l) > 0 and refP / (refP - b.l) < lev.get(i - 1)
aLQ.push(box.new(b.i + lcOF + off, refP * (1 - 1. / lev.get(i - 1)),
b.i + lcOF + off + 2, refP * (1 - 1. / lev.get(i)), border_color = color(na),
bgcolor = color.new(color.teal, trans.get(i)), text =
str.tostring(lev.get(i)) + 'x', text_color = chart.fg_color, text_valign =
text.align_bottom))
tSZ = f_gSZ(lcDS)
if barstate.islast
if dbSH
table.cell(calc, 0, 0, "BAR STATISTICS\n", text_color = color.white,
text_size = tSZ, bgcolor = #2962FF)
table.merge_cells(calc, 0, 0, 2, 0)
if nzV > 0
table.cell(calc, 0, 1, "Activity", text_color = color.white, text_size
= tSZ, text_halign = text.align_left)
table.merge_cells(calc, 0, 1, 1, 1)
table.cell(calc, 2, 1, vDB, text_color = color.white, text_size = tSZ)
if clSH
table.cell(calc, 0, 4, "CALCULATOR\n", text_color = color.white, text_size
= tSZ, bgcolor = #2962FF)
table.merge_cells(calc, 0, 4, 2, 4)
tip = 'Liquidation price is the distance from trader\'s entry price to the
price where trader\'s leveraged position gets liquidated due to a loss.\n\n' +
'If a trader wants to enter a $1.000 trade with ' +
str.tostring(clLR) + 'x leverage, then $' + str.tostring(1000/clLR, '#.##') +
' is the initial margin (the amount of money coming from the traders
pocket) and the remaining $' + str.tostring(1000 - 1000/clLR, '#.##') + ' are
borrowed funds\n\n' +
'When a trader\'s account falls below the required margin level,
exchanges or brokerage platforms cannot allow a trader to lose borrowed funds and
therefore the trader\'s positions will be forcibly closed as soon as position
losses reach the initial margin.\n\n' +
'The liquidation prices presented below are approximate values of
both long and short liquidation prices. It is important to note that the exchanges
will taken into consideration the trader\'s open positions when calculating the
liquidation price. Unrealized PNL and maintenance margin of the trader\'s open
position will affect the calculation of liquidation price'
if lpSH
if aCL.size() > 0
for i = 1 to aCL.size()
box.delete(aCL.shift())
//-----------------------------------------------------------------------------}