0% found this document useful (0 votes)
742 views10 pages

Intradayking 2

Uploaded by

ttdraman2019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
742 views10 pages

Intradayking 2

Uploaded by

ttdraman2019
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

//@version=4

study(title="Supply and Demand Zones",shorttitle="Supply / Demand",overlay=true)

// User inputs
showTomorrowCPR = input(title="Show tomorrow's CPR", type=input.bool, defval=true)
showHistoricalCPR = input(title="Show historical CPR", type=input.bool,
defval=false)
showR3S3 = input(title="Show R3 & S3", type=input.bool, defval=false)
showPDHL = input(title="Show previous day's High & Low", type=input.bool,
defval=false)
showPDC = input(title="Show previous day's Close", type=input.bool, defval=false)

// Defaults
// CPR Colors
cprColor = color.purple
rColor = color.red
sColor = color.green
cColor = color.black

// Line style & Transparency


lStyle = plot.style_line
lTransp = 35

//Fill Transparency
fTransp = 95

// Global Variables & Flags


// TODO : Update the No of Holidays
noOfHolidays = 12

// Global Functions
// TODO : Update the list of Holiday here in format YYYY, MM, DD, 09, 15
// **09, 15 are session start hour & minutes
IsHoliday(_date) =>
iff(_date == timestamp(2020, 02, 21, 09, 15), true,
iff(_date == timestamp(2020, 03, 10, 09, 15), true,
iff(_date == timestamp(2020, 04, 02, 09, 15), true,
iff(_date == timestamp(2020, 04, 06, 09, 15), true,
iff(_date == timestamp(2020, 04, 10, 09, 15), true,
iff(_date == timestamp(2020, 04, 14, 09, 15), true,
iff(_date == timestamp(2020, 05, 01, 09, 15), true,
iff(_date == timestamp(2020, 05, 25, 09, 15), true,
iff(_date == timestamp(2020, 10, 02, 09, 15), true,
iff(_date == timestamp(2020, 11, 16, 09, 15), true,
iff(_date == timestamp(2020, 11, 30, 09, 15), true,
iff(_date == timestamp(2020, 12, 25, 09, 15), true,
false))))))))))))

// Note: Week of Sunday=1...Saturday=7


IsWeekend(_date) =>
dayofweek(_date) == 7 or dayofweek(_date) == 1
// Skip Weekend
SkipWeekend(_date) =>
_d = dayofweek(_date)
_mul = _d == 6 ? 3 : _d == 7 ? 2 : 1

_date + (_mul * 86400000)

// Get Next Working Day


GetNextWorkingDay(_date) =>
_dt = SkipWeekend(_date)

for i = 1 to noOfHolidays
if IsHoliday(_dt)
_dt := SkipWeekend(_dt)
continue
else
break

_dt

// Today's Session Start timestamp


y = year(timenow)
m = month(timenow)
d = dayofmonth(timenow)

// Start & End time for Today's CPR


start = timestamp(y, m, d, 09, 15)
end = start + 86400000

// Plot Today's CPR


shouldPlotToday = timenow > start

tom_start = start
tom_end = end

// Start & End time for Tomorrow's CPR


if shouldPlotToday
tom_start := GetNextWorkingDay(start)
tom_end := tom_start + 86400000

// Get series
getSeries(e, timeFrame) => security(syminfo.tickerid, "D", e,
lookahead=barmerge.lookahead_on)

// Calculate Today's CPR


//Get High, Low and Close
H = getSeries(high[1], 'D')
L = getSeries(low[1], 'D')
C = getSeries(close[1], 'D')

// Pivot Range
P = (H + L + C) / 3
TC = (H + L)/2
BC = (P - TC) + P

// Resistance Levels
R3 = H + 2*(P - L)
R2 = P + (H - L)
R1 = (P * 2) - L

// Support Levels
S1 = (P * 2) - H
S2 = P - (H - L)
S3 = L - 2*(H - P)

// Plot Today's CPR


if not(IsHoliday(start)) and not(IsWeekend(start)) and shouldPlotToday
if showR3S3
_r3 = line.new(start, R3, end, R3, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r3[1])
_r2 = line.new(start, R2, end, R2, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r2[1])
_r1 = line.new(start, R1, end, R1, xloc.bar_time, color=color.new(rColor,
lTransp))
line.delete(_r1[1])

_tc = line.new(start, TC, end, TC, xloc.bar_time, color=color.new(cprColor,


lTransp))
line.delete(_tc[1])
_p = line.new(start, P, end, P, xloc.bar_time, color=color.new(cprColor,
lTransp))
line.delete(_p[1])
_bc = line.new(start, BC, end, BC, xloc.bar_time, color=color.new(cprColor,
lTransp))
line.delete(_bc[1])

_s1 = line.new(start, S1, end, S1, xloc.bar_time, color=color.new(sColor,


lTransp))
line.delete(_s1[1])
_s2 = line.new(start, S2, end, S2, xloc.bar_time, color=color.new(sColor,
lTransp))
line.delete(_s2[1])
if showR3S3
_s3 = line.new(start, S3, end, S3, xloc.bar_time, color=color.new(sColor,
lTransp))
line.delete(_s3[1])
if showPDHL
_pdh = line.new(start, H, end, H, xloc.bar_time, color=color.new(rColor,
lTransp), style=line.style_dotted, width=2)
line.delete(_pdh[1])
_pdl = line.new(start, L, end, L, xloc.bar_time, color=color.new(sColor,
lTransp), style=line.style_dotted, width=2)
line.delete(_pdl[1])
if showPDC
_pdc = line.new(start, C, end, C, xloc.bar_time, color=color.new(cColor,
lTransp), style=line.style_dotted, width=2)
line.delete(_pdc[1])

// Plot Today's Labels


if not(IsHoliday(start)) and not(IsWeekend(start)) and shouldPlotToday
if showR3S3
l_r3 = label.new(start, R3, text="R3", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_r3[1])
l_r2 = label.new(start, R2, text="R2", xloc=xloc.bar_time, textcolor=rColor,
style=label.style_none)
label.delete(l_r2[1])
l_r1 = label.new(start, R1, text="R1", xloc=xloc.bar_time, textcolor=rColor,
style=label.style_none)
label.delete(l_r1[1])

l_tc = label.new(start, TC, text="TC", xloc=xloc.bar_time,


textcolor=cprColor, style=label.style_none)
label.delete(l_tc[1])
l_p = label.new(start, P, text="P", xloc=xloc.bar_time, textcolor=cprColor,
style=label.style_none)
label.delete(l_p[1])
l_bc = label.new(start, BC, text="BC", xloc=xloc.bar_time,
textcolor=cprColor, style=label.style_none)
label.delete(l_bc[1])

l_s1 = label.new(start, S1, text="S1", xloc=xloc.bar_time, textcolor=sColor,


style=label.style_none)
label.delete(l_s1[1])
l_s2 = label.new(start, S2, text="S2", xloc=xloc.bar_time, textcolor=sColor,
style=label.style_none)
label.delete(l_s2[1])
if showR3S3
l_s3 = label.new(start, S3, text="S3", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_s3[1])
if showPDHL
l_pdh = label.new(start, H, text="PD High", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_pdh[1])
l_pdl = label.new(start, L, text="PD Low", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_pdl[1])
if showPDC
l_pdc = label.new(start, C, text="PD Close", xloc=xloc.bar_time,
textcolor=cColor, style=label.style_none)
label.delete(l_pdc[1])

// Calculate Tomorrow's CPR


// Get High, Low and Close
tH = getSeries(high, 'D')
tL = getSeries(low, 'D')
tC = getSeries(close, 'D')

// Pivot Range
tP = (tH + tL + tC) / 3
tTC = (tH + tL)/2
tBC = (tP - tTC) + tP

// Resistance Levels
tR3 = tH + 2*(tP - tL)
tR2 = tP + (tH - tL)
tR1 = (tP * 2) - tL

// Support Levels
tS1 = (tP * 2) - tH
tS2 = tP - (tH - tL)
tS3 = tL - 2*(tH - tP)

// Plot Tomorrow's CPR


if showTomorrowCPR
if showR3S3
_t_r3 = line.new(tom_start, tR3, tom_end, tR3, xloc.bar_time,
color=color.new(rColor, lTransp))
line.delete(_t_r3[1])
_t_r2 = line.new(tom_start, tR2, tom_end, tR2, xloc.bar_time,
color=color.new(rColor, lTransp))
line.delete(_t_r2[1])
_t_r1 = line.new(tom_start, tR1, tom_end, tR1, xloc.bar_time,
color=color.new(rColor, lTransp))
line.delete(_t_r1[1])

_t_tc = line.new(tom_start, tTC, tom_end, tTC, xloc.bar_time,


color=color.new(cprColor, lTransp))
line.delete(_t_tc[1])
_t_p = line.new(tom_start, tP, tom_end, tP, xloc.bar_time,
color=color.new(cprColor, lTransp))
line.delete(_t_p[1])
_t_bc = line.new(tom_start, tBC, tom_end, tBC, xloc.bar_time,
color=color.new(cprColor, lTransp))
line.delete(_t_bc[1])

_t_s1 = line.new(tom_start, tS1, tom_end, tS1, xloc.bar_time,


color=color.new(sColor, lTransp))
line.delete(_t_s1[1])
_t_s2 = line.new(tom_start, tS2, tom_end, tS2, xloc.bar_time,
color=color.new(sColor, lTransp))
line.delete(_t_s2[1])
if showR3S3
_t_s3 = line.new(tom_start, tS3, tom_end, tS3, xloc.bar_time,
color=color.new(sColor, lTransp))
line.delete(_t_s3[1])
if showPDHL
_pdth = line.new(tom_start, tH, tom_end, tH, xloc.bar_time,
color=color.new(rColor, lTransp), style=line.style_dotted, width=2)
line.delete(_pdth[1])
_pdtl = line.new(tom_start, tL, tom_end, tL, xloc.bar_time,
color=color.new(sColor, lTransp), style=line.style_dotted, width=2)
line.delete(_pdtl[1])
if showPDC
_pdtc = line.new(tom_start, tC, tom_end, tC, xloc.bar_time,
color=color.new(cColor, lTransp), style=line.style_dotted, width=2)
line.delete(_pdtc[1])

// Plot Tomorrow's Labels


if showTomorrowCPR
if showR3S3
l_t_r3 = label.new(tom_start, tR3, text="R3", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_t_r3[1])
l_t_r2 = label.new(tom_start, tR2, text="R2", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_t_r2[1])
l_t_r1 = label.new(tom_start, tR1, text="R1", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_t_r1[1])

l_t_tc = label.new(tom_start, tTC, text="TC", xloc=xloc.bar_time,


textcolor=cprColor, style=label.style_none)
label.delete(l_t_tc[1])
l_t_p = label.new(tom_start, tP, text="P", xloc=xloc.bar_time,
textcolor=cprColor, style=label.style_none)
label.delete(l_t_p[1])
l_t_bc = label.new(tom_start, tBC, text="BC", xloc=xloc.bar_time,
textcolor=cprColor, style=label.style_none)
label.delete(l_t_bc[1])

l_t_s1 = label.new(tom_start, tS1, text="S1", xloc=xloc.bar_time,


textcolor=sColor, style=label.style_none)
label.delete(l_t_s1[1])
l_t_s2 = label.new(tom_start, tS2, text="S2", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_t_s2[1])
if showR3S3
l_t_s3 = label.new(tom_start, tS3, text="S3", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_t_s3[1])
if showPDHL
l_pdth = label.new(tom_start, tH, text="PD High", xloc=xloc.bar_time,
textcolor=rColor, style=label.style_none)
label.delete(l_pdth[1])
l_pdtl = label.new(tom_start, tL, text="PD Low", xloc=xloc.bar_time,
textcolor=sColor, style=label.style_none)
label.delete(l_pdtl[1])
if showPDC
l_pdtc = label.new(tom_start, tC, text="PD Close", xloc=xloc.bar_time,
textcolor=cColor, style=label.style_none)
label.delete(l_pdtc[1])

//Plot Historical CPR


p_r3 = plot(showHistoricalCPR ? showR3S3 ? R3 : na : na, title=' R3', color=rColor,
transp=lTransp, style=lStyle)
p_r2 = plot(showHistoricalCPR ? R2 : na, title=' R2', color=rColor, transp=lTransp,
style=lStyle)
p_r1 = plot(showHistoricalCPR ? R1 : na, title=' R1', color=rColor, transp=lTransp,
style=lStyle)

p_cprTC = plot(showHistoricalCPR ? TC : na, title=' TC', color=cprColor,


transp=lTransp, style=lStyle)
p_cprP = plot(showHistoricalCPR ? P : na, title=' P', color=cprColor,
transp=lTransp, style=lStyle)
p_cprBC = plot(showHistoricalCPR ? BC : na, title=' BC', color=cprColor,
transp=lTransp, style=lStyle)

s1 = plot(showHistoricalCPR ? S1 : na, title=' S1', color=sColor, transp=lTransp,


style=lStyle)
s2 = plot(showHistoricalCPR ? S2 : na, title=' S2', color=sColor, transp=lTransp,
style=lStyle)
s3 = plot(showHistoricalCPR ? showR3S3 ? S3 : na : na, title=' S3', color=sColor,
transp=lTransp, style=lStyle)

fill(p_cprTC, p_cprBC, color=color.purple, transp=fTransp)


//supertrend
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool,
defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=true)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr,
linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute,
style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy",
location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green,
textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr,
linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins",
location=location.absolute, style=shape.circle, size=size.tiny, color=color.red,
transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell",
location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red,
textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) :
color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) :
color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend
has changed direction!")

//***********
// Costants
//***********
def_enable_ma_1 = true
def_enable_ma_2 = true
def_enable_ma_3 = true
def_enable_ma_4 = true
def_ema_1 = "EMA"
def_ema_2 = "SMA"
def_ema_3 = "SMA"
def_ema_4 = "SMA"

def_length_1 = 50
def_length_2 = 9
def_length_3 = 30
def_length_4 = 100

def_offset_1 = 0
def_offset_2 = 0
def_offset_3 = 0
def_offset_4 = 0

def_offset_alma_1 = 0.85
def_offset_alma_2 = 0.85
def_offset_alma_3 = 0.85
def_offset_alma_4 = 0.85

def_sigma_alma_1 = 6.0
def_sigma_alma_2 = 6.0
def_sigma_alma_3 = 6.0
def_sigma_alma_4 = 6.0

color_ma_1 = #FBC02D // yellow


color_ma_2 = #0000FF // blue
color_ma_3 = #388E3C // green
color_ma_4 = #7B1FA2 // fuchsia

//***********
// Functions
//***********
// Calculate the TEMA (Triple Exponential Moving Average)
tema(src, length) =>
xEMA1 = ema(src,length)
xEMA2 = ema(xEMA1,length)
xEMA3 = ema(xEMA2,length)
3*xEMA1-3*xEMA2+xEMA3

//***********
// Change the optional parameters
//***********
enable_ma_1 = input(defval=def_enable_ma_1, type=input.bool, title="Enable 1st
MA?")
enable_ma_2 = input(defval=def_enable_ma_2, type=input.bool, title="Enable 2nd
MA?")
enable_ma_3 = input(defval=def_enable_ma_3, type=input.bool, title="Enable 3rd
MA?")
enable_ma_4 = input(defval=def_enable_ma_4, type=input.bool, title="Enable 4rd
MA?")

// Moving Average n.1


ema_1 = input(defval=def_ema_1, type=input.string, options=["EMA", "SMA",
"VWMA", "TEMA", "ALMA"], title="--> 1st MA is")
len_1 = input(defval=def_length_1, minval=1, title="Length 1st MA")
src_1 = input(defval=close, type=input.source, title="Source 1st MA")
offset_1 = input(defval=def_offset_1, minval=-500, maxval=500, type=input.integer,
title="Offset (plot) 1st MA")
// ALMA parameters
offset_alma_1 = input(defval=def_offset_alma_1, type=input.float, title="Offset
ALMA")
sigma_alma_1 = input(defval=def_sigma_alma_1, type=input.float, title="Sigma
ALMA")

// Moving Average n.2


ema_2 = input(defval=def_ema_2, type=input.string, options=["EMA", "SMA",
"VWMA", "TEMA", "ALMA"], title="--> 2nd MA is")
len_2 = input(defval=def_length_2, minval=1, title="Length 2nd MA")
src_2 = input(defval=close, type=input.source, title="Source 2nd MA")
offset_2 = input(defval=def_offset_2, minval=-500, maxval=500, type=input.integer,
title="Offset (plot) 2nd MA")
// ALMA parameters
offset_alma_2 = input(defval=def_offset_alma_2, type=input.float, title="Offset
ALMA")
sigma_alma_2 = input(defval=def_sigma_alma_2, type=input.float, title="Sigma
ALMA")

// Moving Average n.3


ema_3 = input(defval=def_ema_3, type=input.string, options=["EMA", "SMA",
"VWMA", "TEMA", "ALMA"], title="--> 3rd MA is")
len_3 = input(defval=def_length_3, minval=1, title="Length 3rd MA")
src_3 = input(defval=close, type=input.source, title="Source 3rd MA")
offset_3 = input(defval=def_offset_3, minval=-500, maxval=500, type=input.integer,
title="Offset (plot) 3rd MA")
// ALMA parameters
offset_alma_3 = input(defval=def_offset_alma_3, type=input.float, title="Offset
ALMA")
sigma_alma_3 = input(defval=def_sigma_alma_3, type=input.float, title="Sigma
ALMA")

// Moving Average n.4


ema_4 = input(defval=def_ema_4, type=input.string, options=["EMA", "SMA",
"VWMA", "TEMA", "ALMA"], title="--> 4rd MA is")
len_4 = input(defval=def_length_4, minval=1, title="Length 4rd MA")
src_4 = input(defval=close, type=input.source, title="Source 4rd MA")
offset_4 = input(defval=def_offset_4, minval=-500, maxval=500, type=input.integer,
title="Offset (plot) 4rd MA")
// ALMA parameters
offset_alma_4 = input(defval=def_offset_alma_4, type=input.float, title="Offset
ALMA")
sigma_alma_4 = input(defval=def_sigma_alma_4, type=input.float, title="Sigma
ALMA")

//***********
// Calculate the moving averages
//***********
moving_average_1 = security(syminfo.tickerid, "", iff(ema_1=="EMA",
ema(src_1,len_1), iff(ema_1=="SMA", sma(src_1,len_1), iff(ema_1=="VWMA",
vwma(src_1,len_1), iff(ema_1=="TEMA", tema(src_1,len_1),
alma(src_1,len_1,offset_alma_1,sigma_alma_1) )))))
moving_average_2 = security(syminfo.tickerid, "", iff(ema_2=="EMA",
ema(src_2,len_2), iff(ema_2=="SMA", sma(src_2,len_2), iff(ema_2=="VWMA",
vwma(src_2,len_2), iff(ema_2=="TEMA", tema(src_2,len_2),
alma(src_2,len_2,offset_alma_2,sigma_alma_2) )))))
moving_average_3 = security(syminfo.tickerid, "", iff(ema_3=="EMA",
ema(src_3,len_3), iff(ema_3=="SMA", sma(src_3,len_3), iff(ema_3=="VWMA",
vwma(src_3,len_3), iff(ema_3=="TEMA", tema(src_3,len_3),
alma(src_3,len_3,offset_alma_3,sigma_alma_3) )))))
moving_average_4 = security(syminfo.tickerid, "", iff(ema_4=="EMA",
ema(src_4,len_4), iff(ema_4=="SMA", sma(src_4,len_4), iff(ema_4=="VWMA",
vwma(src_4,len_4), iff(ema_4=="TEMA", tema(src_4,len_4),
alma(src_4,len_4,offset_alma_4,sigma_alma_4) )))))

//***********
// Show the moving averages
//***********
plot(enable_ma_1 ? moving_average_1 : na, color=color_ma_1, title="1st MA",
offset=offset_1)
plot(enable_ma_2 ? moving_average_2 : na, color=color_ma_2, title="2nd MA",
offset=offset_2)
plot(enable_ma_3 ? moving_average_3 : na, color=color_ma_3, title="3rd MA",
offset=offset_3)
plot(enable_ma_4 ? moving_average_4 : na, color=color_ma_4, title="4rd MA",
offset=offset_4)

You might also like