code
code
code
strategy(title="updated",overlay=true,shorttitle = 'ABX')
/////////////////////////////////////////////////////////////////////////
////////ATR
// making adx
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
trur = rma(tr, 14)
smoothPlusDM = fixnan(100 * rma(plusDM, 14) / trur)
smoothMinusDM = fixnan(100 * rma(minusDM, 14) / trur)
// vwap
wap = vwap((close+high+low)/3)
xATR = atr(21)
nLoss = 3 * xATR
xATRTrailingStop = float(na)
xATRTrailingStop := iff(close > nz(xATRTrailingStop[1], 0) and close[1] >
nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] <
nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
pos = int(na)
pos := iff(close[1] < nz(xATRTrailingStop[1], 0) and close >
nz(xATRTrailingStop[1], 0), 1, iff(close[1] > nz(xATRTrailingStop[1], 0)
and close < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))
//Trading
// Buy only if the buy signal is triggered and we are not already long
LONG = not isLong and pos == 1
// Sell only if the sell signal is triggered and we are not already short
SHORT = not isShort and pos == -1
if LONG
isLong := true
isShort := false
isShort
if SHORT
isLong := false
isShort := true
isShort
confirmLONG = LONG==true
confirmSHORT = SHORT==true
var signal = 0
if confirmLONG == true
signal := 1
else if confirmSHORT==true
signal := -1
else if EOSS < close[1]
signal := 0
else
signal = signal[1]
var signal2 = 0
if confirmLONG == true
signal2 := 1
else if confirmSHORT==true
signal2 := -1
else if SEOSS > close[1]
signal2 := 0
else
signal2 = signal2[1]
if close > EOSS and signal == 1 and (smoothPlusDM > 25) and close > wap
label.new(bar_index, (low[1]+high[1])/2, "BUY",yloc = yloc.belowbar,
style = label.style_label_up, textcolor = color.white, size =
size.normal,color=color.green)
sl1 = "T1: " + tostring(t1)
sl2 = "T2: " + tostring(t2)
sl3 = "T3: " + tostring(t3)
sl4 = "T4: " + tostring(t4)
sll = "SL: " + tostring(sl)
ml1=label.new(bar_index+4, t1,sl1,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml2=label.new(bar_index+4, t2,sl2,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml3=label.new(bar_index+4, t3,sl3,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml4=label.new(bar_index+4, t4,sl4,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml5=label.new(bar_index+4, sl,sll,yloc=yloc.price, textcolor =
color.red,style = label.style_none,size = size.normal)
label.delete(ml1[1])
label.delete(ml2[1])
label.delete(ml3[1])
label.delete(ml4[1])
label.delete(ml5[1])
l=line.new(bar_index-
10,t1,bar_index+100,t1,color=color.green,style=line.style_solid)
line.delete(l[1])
l2=line.new(bar_index-
10,t2,bar_index+100,t2,color=color.green,style=line.style_solid)
line.delete(l2[1])
l3=line.new(bar_index-
10,t3,bar_index+100,t3,color=color.green,style=line.style_solid)
line.delete(l3[1])
l4=line.new(bar_index-
10,t4,bar_index+100,t4,color=color.green,style=line.style_solid)
line.delete(l4[1])
l5=line.new(bar_index-
10,sl,bar_index+100,sl,color=color.red,style=line.style_solid)
line.delete(l5[1])
EP = SEOSS>close and (smoothMinusDM > 25) and close < wap ? close : na
STL = SEOSS>close and (smoothMinusDM > 25) and close < wap ? SBOSS: na
stop = STL
ta1 = EP-(STL-EP)
ta2 = EP-(STL-EP)*1.5
ta3 = EP-(STL-EP)*2
ta4 = EP-(STL-EP)*2.5
if SEOSS>close and signal2 ==-1 and (smoothMinusDM > 25) and close <
wap
label.new(bar_index, (low[1]+high[1])/2, "SELL",yloc = yloc.abovebar,
style = label.style_label_down, textcolor = color.white, size =
size.normal,color=color.red)
TP1 = "T1: " + tostring(ta1)
TP2 = "T2: " + tostring(ta2)
TP3 = "T3: " + tostring(ta3)
TP4 = "T4: " + tostring(ta4)
SLP = "SL: " + tostring(stop)
ml6=label.new(bar_index+4, ta1,TP1,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml7=label.new(bar_index+4, ta2,TP2,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml8=label.new(bar_index+4, ta3,TP3,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml9=label.new(bar_index+4, ta4,TP4,yloc=yloc.price, textcolor =
color.green,style = label.style_none,size = size.normal)
ml10=label.new(bar_index+4, stop,SLP,yloc=yloc.price, textcolor =
color.red,style = label.style_none,size = size.normal)
label.delete(ml6[1])
label.delete(ml7[1])
label.delete(ml8[1])
label.delete(ml9[1])
label.delete(ml10[1])
lq=line.new(bar_index-
10,ta1,bar_index+100,ta1,color=color.green,style=line.style_solid)
line.delete(lq[1])
l2q=line.new(bar_index-
10,ta2,bar_index+100,ta2,color=color.green,style=line.style_solid)
line.delete(l2q[1])
l3q=line.new(bar_index-
10,ta3,bar_index+100,ta3,color=color.green,style=line.style_solid)
line.delete(l3q[1])
l4q=line.new(bar_index-
10,ta4,bar_index+100,ta4,color=color.green,style=line.style_solid)
line.delete(l4q[1])
l5q=line.new(bar_index-
10,stop,bar_index+100,stop,color=color.red,style=line.style_solid)
line.delete(l5q[1])
//
/////////////////////////////////////////////////////////////////////////
///////VWMA
sma_volume = sma(volume, 20)
barcolor(sma_volume <volume and open < close ? color.blue : na )
plot(sma_volume, title="Volume SMA")
barcolor(sma_volume < volume and open > close ? color.yellow : na )
plot(sma_volume, title="Volume SMA")
//if condition1==true
// label.new(bar_index, low, yloc=yloc.belowbar,
style=label.style_diamond,size=size.tiny,color=color.black)
if confirmLONG==true or confirmSHORT==true
label.new(bar_index, low, yloc=yloc.belowbar,
style=label.style_diamond,size=size.tiny)
// table
//@version=4
var table Tq = table.new(position.top_right,7,20)
//2 nd row
table.cell(Tq, 0, 1, tostring("Script"),bgcolor = color.gray,text_size =
size.tiny)
table.cell(Tq, 1, 1, tostring("LTP"),bgcolor = color.gray,text_size =
size.tiny)
table.cell(Tq, 2, 1, tostring("% change"),bgcolor = color.gray,text_size
= size.tiny)
table.cell(Tq, 3, 1, tostring("Trend"),bgcolor = color.gray,text_size =
size.tiny)
table.cell(Tq, 4, 1, tostring("Price Action"),bgcolor =
color.gray,text_size = size.tiny)
table.cell(Tq, 5, 1, tostring("Zone"),bgcolor = color.gray,text_size =
size.tiny)
table.cell(Tq, 6, 1, tostring("Momentum"),bgcolor = color.gray,text_size
= size.tiny)
/////////////// for 1
tap(x, y,z) =>
nifty_LL = nifty_close
nifty_LTP = nifty_LL
nifty_perc = round((nifty_LL[0]-nifty_LL[1])*100/nifty_LL[1],2)
nifty_rsi = rsi(nifty_close,21)
// data + wap
nifty_wap = vwap(nifty_close)
// adx
nifty_H = security(x, "5", high)
nifty_L = security(x, "5", low)
// supertrend
Source = input(hl2, title="Source")
trN = max(nifty_H[0] - nifty_L[0], abs(nifty_H[0] - nifty_close[0]),
abs(nifty_L - nifty_close[1]))
atrN = ema(trN, 21)
up=Source-(3*atrN)
upN= nz(up[1],up)
up := nifty_close[1] > upN ? max(up,upN) : up
dn=Source+(3*atrN)
dnN = nz(dn[1], dn)
dn := nifty_close[1] < dnN ? min(dn, dnN) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and nifty_close[0] > dnN ? 1 : trend == 1 and
nifty_close[0] < upN ? -1 : trend
/////////////////S1
table.cell(Tq, 0, z, tostring(y),bgcolor = color.rgb(229, 231,
238),width = 10, height = 3,text_size = size.tiny)
table.cell(Tq, 1, z, tostring(nifty_LTP),bgcolor =color.rgb(217, 224,
247), width = 5, height = 3,text_size = size.tiny)
table.cell(Tq, 2, z, tostring(nifty_perc),bgcolor =color.rgb(217,
224, 247), width = 5, height = 3,text_size = size.tiny)
// rsi
if nifty_rsi[0] > 60
table.cell(Tq, 5, z, tostring('bullish'),bgcolor =color.rgb(11,
245, 89),text_size = size.tiny)
else if nifty_rsi[0] < 40
table.cell(Tq, 5, z, tostring('bearish'),bgcolor =color.rgb(221,
72, 72),text_size = size.tiny)
else
table.cell(Tq, 5, z, tostring('neutral'),bgcolor =color.rgb(68,
6, 240, 77),text_size = size.tiny)
// vwap
if nifty_close[0]>nifty_wap[0]
table.cell(Tq, 4, z, tostring('bullish'),bgcolor =color.rgb(11,
245, 89),text_size = size.tiny)
else
table.cell(Tq, 4, z, tostring('bearish'),bgcolor =color.rgb(221,
72, 72),text_size = size.tiny)
// adx
if DN>25
table.cell(Tq, 6, z, tostring('bullish'),bgcolor =color.rgb(11,
245, 89),text_size = size.tiny)
else if DM<-25
table.cell(Tq, 6, z, tostring('bearish'),bgcolor =color.rgb(221,
72, 72),text_size = size.tiny)
else
table.cell(Tq, 6, z, tostring('neutral'),bgcolor =color.rgb(68,
6, 240, 77),text_size = size.tiny)
// supertrend
if trend==1
table.cell(Tq, 3, z, tostring('bullish'),bgcolor =color.rgb(11,
245, 89),text_size = size.tiny)
else if trend==-1
table.cell(Tq, 3, z, tostring('bearish'),bgcolor =color.rgb(221,
72, 72),text_size = size.tiny)
tap("TVC:DJI","DJI",2)
tap("NSE:NIFTY","NIFTY 50",3)
tap("NSE:BANKNIFTY","BANKNIFTY",5)
tap("NSE:HDFCBANK","HDFC BANK",6)
tap("NSE:ICICIBANK","ICICI BANK",7)
tap("NSE:KOTAKBANK","KOTAK BANK",8)
tap("NSE:SBIN","SBIN",9)
tap("NSE:AXISBANK","AXIS BANK",10)
tap("NSE:INDUSINDBK","INDUSIND BANK",11)
tap("NSE:BANKBARODA","BANK OF BARODA",12)
tap("NSE:FEDERALBNK","FEDERAL BANK",13)
tap("NSE:IDFC","IDFC FIRST",14)
tap("NSE:PNB","PNB",15)