Professional Documents
Culture Documents
VMS Gann Angles With Volatility Ver.1
VMS Gann Angles With Volatility Ver.1
0 at
https://mozilla.org/MPL/2.0/
// © madhavbbs
//@version=4
study(title="VMS Gann Angles With Volatility Ver.1", shorttitle="VMS Gann Ver.1",
overlay=true, format=format.price, precision=2)
///// RISK CHECKER
risk_checker_input = input(title="I know I have to do my own research and that I'm
trading at my own risk. I'm only trading with money I'm willing to lose or gain.",
type=input.bool, defval=false)
risk_checked = risk_checker_input==true
risk_unchecked = risk_checker_input==false
risk_checker = risk_unchecked
plotshape(risk_checker, title="Risk Checker", style=shape.labeldown, text="Accept
risks in settings menu to start indicator !" ,textcolor=color.white,
color=color.red, location=location.abovebar, size=size.huge, transp=0, show_last=1)
offset_val = input(title="Label Offset", type=input.integer, defval=50)
showlabels = input(title="Show Labels", type=input.bool, defval=true)
// We only populate the table on the last bar; it's more efficient.
if barstate.islast
// This `varip` variable will preserve its value across realtime updates.
varip bool _changeText = true
// Toggle this value on each update.
_changeText := not _changeText
// If there's a "Text 2" string in inputs and it's time to flip, change the
text.
string _txt = str.length(i_text2) != 0 and _changeText ? i_text2 : i_text1
// Populate our table cell.
table.cell(watermark, 0, 0, _txt, i_width, i_height, i_c_text, text_size =
i_textSize, bgcolor = i_c_bg)
//2
///////////////////////////////////////////////////////////////////////////
switch_v1=input(false,"Switch to version 1.0",tooltip="You are currently on version
2.0 of this indicator , check this box in order to switch to version 1.0 of the
indicator")
var table perfTable = table.new(position.top_right, 4,4 , border_width = 3)
LIGHTTRANSP = 90
AVGTRANSP = 80
HEAVYTRANSP = 90
///////////////////////////////////////////////////////////////////////////////////
///////////
//code to count all candels from the start of the day
session_bar_counter = bar_index - valuewhen(change(time("D")) != 0, bar_index, 0)
disable_current=input(title="On/Off Currnet bar Volume", type=input.bool,
defval=true)
change_vol_percentage=input(title="% ", type=input.bool,
defval=true,tooltip="change % to actual volume")
if(array.size(pos_bv_arr)>(session_bar_counter+1))
array.pop(pos_bv_arr)
//condition to display the buying and selling volumes and store the sumed volume
if not if_bar_greater_than_day and barstate.islast
if close <= open
sum_sv := volume
for i = 0 to session_bar_counter
if(array.get(pos_bv_arr,i)==0)
sum_sv := sum_sv + volume[session_bar_counter-i]
//sum_sv:=0
if not if_bar_greater_than_day and barstate.islast
if close >= open
sum_bv := volume
for i = 0 to session_bar_counter
if(array.get(pos_bv_arr,i)!=0)
sum_bv := sum_bv + volume[session_bar_counter-i]
//sum_bv:=0
///variable to store percentage value of the buying and selling volumes and store
the sumed volume
per_or_not_sv=change_vol_percentage?sum_sv/(sum_sv+sum_bv)*100:sum_sv
per_or_not_bv=change_vol_percentage?sum_bv/(sum_sv+sum_bv)*100:sum_bv
//if time frame is not greater than day then show the days buying and selling
volumes and percentage value enabled
if(barstate.islast and not if_bar_greater_than_day and change_vol_percentage and
switch_v1)
f_print_sv(tostring(round((per_or_not_sv)* 10) / 10)+'%')
f_print_bv(tostring(round((per_or_not_bv)* 10) / 10)+'%')
///if time frame greater than Day than only current bar volume is shown
var label vol=na
if(barstate.islast and open<close and if_bar_greater_than_day and switch_v1)
vol:=label.new(bar_index, na,text=tostring(volume)+'\n '+"current Bar Volume",
color=color.lime,style=label.style_labeldown, yloc=yloc.abovebar)
label.delete(vol[1])
///code to disable current bar volume is from time frame less than "D"
var label vol_current=na
if(barstate.islast and open<close and not if_bar_greater_than_day and
disable_current and switch_v1)
vol_current:=label.new(bar_index, na,text=tostring(volume)+'\n '+"current Bar
Volume", color=color.lime,style=label.style_labeldown, yloc=yloc.abovebar)
if(barstate.islast and open<close and not if_bar_greater_than_day and
disable_current and not switch_v1)
f_fillCell_without_per(perfTable, 0, 3, round((volume)), "current Bar vol")
label.delete(vol_current[1])
//3
var table perfTable1 = table.new(position.top_left, 3, 2, border_width = 3)
LIGHTTRANSP1 = 90
AVGTRANSP1 = 80
HEAVYTRANSP1 = 70
f_performance(_barsBack) =>
_performance = security(syminfo.tickerid, "1D", f_rateOfreturn(close,
close[_barsBack]))
_performance
if barstate.islast
f_fillCell1(perfTable1, 0, 0, f_performance(5), "1W")
f_fillCell1(perfTable1, 1, 0, f_performance(21), "1M")
f_fillCell1(perfTable1, 2, 0, f_performance(63), "3M")
f_fillCell1(perfTable1, 0, 1, f_performance(126), "6M")
f_fillCell1(perfTable1, 1, 1, f_rateOfreturn(close, lastYearClose), "YTD")
f_fillCell1(perfTable1, 2, 1, f_performance(251), "1Y")
//4
////////////////////////////////////////////////////////////////////////////////
// A. Oscillators //
////////////////////////////////////////////////////////////////////////////////
//RSI Signal
A1_red =
rsi_Sig<30
?1:0
A1_blue =
rsi_Sig>70
?1:0
//CCI Signal
A3_red =
cci_Sig<-100
?1:0
A3_blue =
cci_Sig>100
?1:0
//ADX Signal
A4_red =
di_sigLow>di_sigHigh
and ADX_Sig>25
?1:0
A4_blue =
di_sigHigh>di_sigLow
and ADX_Sig>25
?1:0
//AO Signal
A5_red =
ao<0
?1:0
A5_blue =
ao>0
?1:0
//momentum Signal
A6_red =
mom<0
?1:0
A6_blue =
mom>0
?1:0
//MACD Signal
A7_red =
hist < hist[1]
?1:0
A7_blue =
hist > hist[1]
?1:0
// %R Signal
A9_red =
out < rband0
?1:0
A9_blue =
out > rband1
?1:0
// UO Signal
A11_red =
uoout < 30
?1:0
A11_blue =
uoout > 70
?1:0
//Sum Signal A
A_red = A1_red + A2_red + A3_red + A4_red + A5_red + A6_red + A7_red + A8_red +
A9_red + A10_red + A11_red
A_blue = A1_blue + A2_blue + A3_blue + A4_blue + A5_blue + A6_blue + A7_blue +
A8_blue + A9_blue + A10_blue + A11_blue
////////////////////////////////////////////////////////////////////////////////
// B. Moving Averages //
////////////////////////////////////////////////////////////////////////////////
//Sum Signal B
B_red = B1_red + B2_red + B3_red + B4_red + B5_red + B6_red + B7_red + B8_red +
B9_red + B10_red + B11_red + B12_red + B13_red + B14_red + B15_red + B16_red +
B17_red
B_blue = B1_blue + B2_blue + B3_blue + B4_blue + B5_blue + B6_blue + B7_blue +
B8_blue + B9_blue + B10_blue + B11_blue + B12_blue + B13_blue + B14_blue + B15_blue
+ B16_blue + B17_blue
////////////////////////////////////////////////////////////////////////////////
// C. Pivot //
////////////////////////////////////////////////////////////////////////////////
///////////////
// FUNCTIONS //
///////////////
////////////
// INPUTS //
////////////
//pp_res = 'D'
pp_res = res
/////////////////////
// Get HLC from HT //
// Calc Open
open_cur = 0.0
open_cur := is_newbar1(pp_res) ? security(tick,res,open) : open_cur[1]
popen = 0.0
popen := is_newbar1(pp_res) ? open_cur[1] : popen[1]
// Calc High
high_cur = 0.0
high_cur := is_newbar1(pp_res) ? security(tick,res,high) : max(high_cur[1],
security(tick,res,high))
phigh = 0.0
phigh := is_newbar1(pp_res) ? high_cur[1] : phigh[1]
// Calc Low
low_cur = 0.0
low_cur := is_newbar1(pp_res) ? security(tick,res,low) : min(low_cur[1],
security(tick,res,low))
plow = 0.0
plow := is_newbar1(pp_res) ? low_cur[1] : plow[1]
// Calc source
psource = 0.0
psource := is_newbar1(pp_res) ? source[1] : psource[1]
////////////////////////////
// CALCULATE Pivot POINTS //
////////////////////////////
PP = 0.0
R1 = 0.0, R2 = 0.0, R3 = 0.0
S1 = 0.0, S2 = 0.0, S3 = 0.0
// Traditional
TR_PP = (phigh + plow + psource) / 3
TR_R1 = TR_PP + (TR_PP - plow)
TR_S1 = TR_PP - (phigh - TR_PP)
TR_R2 = TR_PP + (phigh - plow)
TR_S2 = TR_PP - (phigh - plow)
TR_R3 = phigh + 2 * (TR_PP - plow)
TR_S3 = plow - 2 * (phigh - TR_PP)
//Signal
C1_red =
(source<TR_S1 and not cross(source,TR_S2))
or
(source<TR_S2 and not cross(source,TR_S3))
or
(source<TR_S3 and not cross(security(tick,res,high),TR_S3))
?1:0
C1_blue =
(source>TR_R1 and not cross(source,TR_R2))
or
(source>TR_R2 and not cross(source,TR_R3))
or
(source>TR_R3 and not cross(security(tick,res,low),TR_R3))
?1:0
// Fibonacci
FIB_PP = (phigh + plow + psource) / 3
FIB_R1 = FIB_PP + (phigh - plow) * 0.382
FIB_S1 = FIB_PP - (phigh - plow) * 0.382
FIB_R2 = FIB_PP + (phigh - plow) * 0.618
FIB_S2 = FIB_PP - (phigh - plow) * 0.618
FIB_R3 = FIB_PP + (phigh - plow) * 1.000
FIB_S3 = FIB_PP - (phigh - plow) * 1.000
C2_red =
(source<FIB_S1 and not cross(source,FIB_S2))
or
(source<FIB_S2 and not cross(source,FIB_S3))
or
(source<FIB_S3 and not cross(security(tick,res,high),FIB_S3))
?1:0
C2_blue =
(source>FIB_R1 and not cross(source,FIB_R2))
or
(source>FIB_R2 and not cross(source,FIB_R3))
or
(source>FIB_R3 and not cross(security(tick,res,low),FIB_R3))
?1:0
// Woodie
WO_PP = (phigh + plow + 2 * popen) / 4
WO_R1 = WO_PP + (WO_PP - plow)
WO_S1 = WO_PP - (phigh - WO_PP)
WO_R2 = WO_PP + (phigh - plow)
WO_S2 = WO_PP - (phigh - plow)
WO_R3 = phigh + 2 * (WO_PP - plow)
WO_S3 = plow - 2 * (phigh - WO_PP)
C3_red =
(source<WO_S1 and not cross(source,WO_S2))
or
(source<WO_S2 and not cross(source,WO_S3))
or
(source<WO_S3 and not cross(security(tick,res,high),WO_S3))
?1:0
C3_blue =
(source>WO_R1 and not cross(source,WO_R2))
or
(source>WO_R2 and not cross(source,WO_R3))
or
(source>WO_R3 and not cross(security(tick,res,low),WO_R3))
?1:0
// Camarilla
CA_PP = (phigh + plow + psource) / 3
CA_R1 = psource + (phigh - plow) * 1.1/12
CA_S1 = psource - (phigh - plow) * 1.1/12
CA_R2 = psource + (phigh - plow) * 1.1/6
CA_S2 = psource - (phigh - plow) * 1.1/6
CA_R3 = psource + (phigh - plow) * 1.1/4
CA_S3 = psource - (phigh - plow) * 1.1/4
C4_red =
(source<CA_S1 and not cross(source,CA_S2))
or
(source<CA_S2 and not cross(source,CA_S3))
or
(source<CA_S3 and not cross(security(tick,res,high),CA_S3))
?1:0
C4_blue =
(source>CA_R1 and not cross(source,CA_R2))
or
(source>CA_R2 and not cross(source,CA_R3))
or
(source>CA_R3 and not cross(security(tick,res,low),CA_R3))
?1:0
//C Point
C_red = C1_red + C2_red + C3_red + C4_red
////////////////////////////////////////////////////////////////////////////////
//Market Level
sell =
Sum_red>Sum_blue
and sell_point>5
?22:na
Strong_sell =
A_red>A_blue
and B_red>B_blue
and C_red>C_blue
and sell_point>5
and not crossunder(sell_point,7.5)
?22:na
buy =
Sum_red<Sum_blue
and buy_point>5
?22:na
Strong_buy =
A_red<A_blue
and B_red<B_blue
and C_red<C_blue
and buy_point>5
and not crossunder(buy_point,7.5)
?22:na
neutral = not sell and not Strong_sell and not buy and not Strong_buy?22:na
////////////////////////////////////////////////////////////////////////////////
// Table //
////////////////////////////////////////////////////////////////////////////////
// Adjusts the text size and results in different overall size of the table
txtSizeInput = input(title="Text Size", defval="Normal", options=["Tiny", "Small",
"Normal", "Large", "Huge"], tooltip="Select the size of the text. It affects the
size of the whole table.")
var txtSize = txtSizeInput == "Tiny" ? size.tiny : txtSizeInput == "Small" ?
size.small : txtSizeInput == "Normal" ? size.normal : txtSizeInput == "Large" ?
size.large : txtSizeInput == "Huge" ? size.huge : na
// Background color for Pivots, Oscillators, MAs, and Summary
pivBgColor = input(title="Pivots Background Color", type=input.color,
defval=color.rgb(10, 10, 10, 25), tooltip="Background color for the Pivots
columns.")
oscBgColor = input(title="Oscillators Background Color", type=input.color,
defval=color.rgb(40, 40, 40, 25), tooltip="Background color for the Oscillators
columns.")
maBgColor = input(title="Moving Averages Background Color", type=input.color,
defval=color.rgb(10, 10, 10, 25), tooltip="Background color for the Moving Averages
columns.")
sumBgColor = input(title="Summary Background Color", type=input.color,
defval=color.rgb(40, 40, 40, 25), tooltip="Background color for the Summary
columns.")
// Final suggestion
if barstate.isrealtime
if sell and not Strong_sell
for i=0 to 12
table.cell(TA_Display, i, 0, text_color=color.white, text_size=txtSize,
bgcolor=sBgColor)
table.cell_set_text(TA_Display, 6, 0, "VMS SELL")
if Strong_sell
for i=0 to 12
table.cell(TA_Display, i, 0, text_color=color.white, text_size=txtSize,
bgcolor=ssBgColor)
table.cell_set_text(TA_Display, 6, 0, "VMS STRONG SELL")
if buy and not Strong_buy
for i=0 to 12
table.cell(TA_Display, i, 0, text_color=color.white, text_size=txtSize,
bgcolor=bBgColor)
table.cell_set_text(TA_Display, 6, 0, "VMS BUY")
if Strong_buy
for i=0 to 12
table.cell(TA_Display, i, 0, text_color=color.white, text_size=txtSize,
bgcolor=sbBgColor)
table.cell_set_text(TA_Display, 6, 0, "VMS STRONG BUY")
if neutral
for i=0 to 12
table.cell(TA_Display, i, 0, text_color=color.white, text_size=txtSize,
bgcolor=nBgColor)
table.cell_set_text(TA_Display, 6, 0, "VMS NEUTRAL")
// Pivots
if barstate.islast
table.cell(TA_Display, 0, 1, text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 1, 1, "Pivots", text_color=color.white,
text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 2, 1, text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 0, 2, tostring(C_red), text_color=color.red,
text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 1, 2, tostring(4-(C_red+C_blue)), text_color=color.gray,
text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 2, 2, tostring(C_blue), text_color=color.green,
text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 0, 3, "Sell", text_color=color.red, text_size=txtSize,
bgcolor=pivBgColor)
table.cell(TA_Display, 1, 3, "Neutral", text_color=color.gray,
text_size=txtSize, bgcolor=pivBgColor)
table.cell(TA_Display, 2, 3, "Buy", text_color=color.green, text_size=txtSize,
bgcolor=pivBgColor)
// Oscillators
if barstate.islast
table.cell(TA_Display, 3, 1, text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 4, 1, "Oscillators", text_color=color.white,
text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 5, 1, text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 3, 2, tostring(A_red), text_color=color.red,
text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 4, 2, tostring(11-(A_red+A_blue)),
text_color=color.gray, text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 5, 2, tostring(A_blue), text_color=color.green,
text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 3, 3, "Sell", text_color=color.red, text_size=txtSize,
bgcolor=oscBgColor)
table.cell(TA_Display, 4, 3, "Neutral", text_color=color.gray,
text_size=txtSize, bgcolor=oscBgColor)
table.cell(TA_Display, 5, 3, "Buy", text_color=color.green, text_size=txtSize,
bgcolor=oscBgColor)
// Moving Averages
if barstate.islast
table.cell(TA_Display, 7, 1, text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 8, 1, "MAs", text_color=color.white, text_size=txtSize,
bgcolor=maBgColor)
table.cell(TA_Display, 9, 1, text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 7, 2, tostring(B_red), text_color=color.red,
text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 8, 2, tostring(17-(B_red+B_blue)),
text_color=color.gray, text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 9, 2, tostring(B_blue), text_color=color.green,
text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 7, 3, "Sell", text_color=color.red, text_size=txtSize,
bgcolor=maBgColor)
table.cell(TA_Display, 8, 3, "Neutral", text_color=color.gray,
text_size=txtSize, bgcolor=maBgColor)
table.cell(TA_Display, 9, 3, "Buy", text_color=color.green, text_size=txtSize,
bgcolor=maBgColor)
// Summary
if barstate.islast
table.cell(TA_Display, 10, 1, text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 11, 1, "Summary", text_color=color.white,
text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 12, 1, text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 10, 2, tostring(Sum_red), text_color=color.red,
text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 11, 2, +tostring(32-(Sum_red+Sum_blue)),
text_color=color.gray, text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 12, 2, tostring(Sum_blue), text_color=color.green,
text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 10, 3, "Sell", text_color=color.red, text_size=txtSize,
bgcolor=sumBgColor)
table.cell(TA_Display, 11, 3, "Neutral", text_color=color.gray,
text_size=txtSize, bgcolor=sumBgColor)
table.cell(TA_Display, 12, 3, "Buy", text_color=color.green, text_size=txtSize,
bgcolor=sumBgColor)
// Pseudohistogram
if barstate.isrealtime
if sell_point > buy_point
table.cell(TA_Display, 6, 1, tostring(sell_point*10) + "%",
text_color=color.white, text_size=txtSize, bgcolor=negBgColor)
table.cell(TA_Display, 6, 3, tostring(buy_point*10) + "%",
text_color=color.white, text_size=txtSize, bgcolor=posBgColor)
else
table.cell(TA_Display, 6, 1, tostring(buy_point*10) + "%",
text_color=color.white, text_size=txtSize, bgcolor=posBgColor)
table.cell(TA_Display, 6, 3, tostring(sell_point*10) + "%",
text_color=color.white, text_size=txtSize, bgcolor=negBgColor)
calculateLN() =>
tot = 0.0
tot := log(c1/c2) + log(c2/c3) + log(c3/c4) + log(c4/c5) + log(c5/c6) +
log(c6/c7) + log(c7/c8) + log(c8/c9) + log(c9/c10)
calculateLNSquare() =>
tot = 0.0
tot := pow(log(c1/c2),2) + pow(log(c2/c3),2) + pow(log(c3/c4),2) +
pow(log(c4/c5),2) + pow(log(c5/c6),2) + pow(log(c6/c7),2) + pow(log(c7/c8),2) +
pow(log(c8/c9),2) + pow(log(c9/c10),2)
calculatePivot() =>
(ph + pl + pc) / 3
degreeFactor(angle) =>
if angle == 1
3.75/180
else
if angle == 2
7.5/180
else
if angle == 3
15.00/180
else
if angle == 4
18.75/180
else
if angle == 5
26.25/180
else
if angle == 6
45.00/180
else
if angle == 7
63.75/180
else
if angle == 8
71.25/180
else
if angle == 9
75.00/180
else
if angle == 10
82.50/180
else
86.25/180
pivot = calculatePivot()
totLn := calculateLN()
totLnSqr := calculateLNSquare()
lnAvg := totLn / 9
lnSqrAvg := totLnSqr / 9
variance := lnSqrAvg - pow(lnAvg, 2)
dailyVolatility := sqrt(variance)
price := o > ph or o < pl ? o : (ph + pl)/2
priceRange := dailyVolatility * pc
//Cycle One
[buyAbove, majorResistane1, buytarget1, sellBelow, majorSupport1, sellTarget1] =
getCycleLevels(1, price, 0.0, priceRange)
//Cycle Tw0
[majorResistane2, buytarget2, majorSupport2, sellTarget2, dummy1, dummy2] =
getCycleLevels(2, buytarget1, sellTarget1, priceRange)
//Cycle Three
[majorResistane3, buytarget3, majorSupport3, sellTarget3, dummy3, dummy4] =
getCycleLevels(3, buytarget2, sellTarget2, priceRange)
//Cycle Four
[majorResistane4, buytarget4, majorSupport4, sellTarget4, dummy5, dummy6] =
getCycleLevels(4, buytarget3, sellTarget3, priceRange)
//Cycle Five
[majorResistane5, buytarget5, majorSupport5, sellTarget5, dummy7, dummy8] =
getCycleLevels(5, buytarget4, sellTarget4, priceRange)
//
src = close
useCurrentRes = input(true, title="Use Current Chart Resolution?")
resCustom = input(title="Use Different Timeframe? Uncheck Box Above",
type=input.resolution, defval="D")
len = input(20, title="Moving Average Length - LookBack Period")
//periodT3 = input(defval=7, title="Tilson T3 Period", minval=1)
factorT3 = input(defval=7, title="Tilson T3 Factor - *.10 - so 7 = .7 etc.",
minval=0)
atype = input(1, minval=1, maxval=8, title="1=SMA, 2=EMA, 3=WMA, 4=HullMA, 5=VWMA,
6=RMA, 7=TEMA, 8=Tilson T3")
spc = input(true, title="Show Price Crossing 1st Mov Avg - Highlight Bar?")
cc = input(true, title="Change Color Based On Direction?")
smoothe = input(2, minval=1, maxval=10, title="Color Smoothing - Setting 1 = No
Smoothing")