#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © seba34e
#indicator("Sigma Expected Movement [D/W/M]", overlay=true)
# Converted by Sam4Cok@Samer800 - 02/2024
input showTabel = yes;
input showLabel = yes;
input extendLeft = 10;
input extendRight = 2;
input symbol = "VIX";
input period = {default "DAY", "WEEK", "MONTH"}; # title="Period", options =
input FirstDeviation = 68; #, title = "First Deviation (%)")
input SecondDeviation = 90; #, title = "Second Deviation (%)")
input RoundToInteger = no; #(false, title = "Round to Integer", inline = "Round")
input Round = 5; #, title="", inline = "Round")
def na = Double.NaN;
def last = isNaN(close);
def n = BarNumber();
def bar = if !last then n else bar[1];
def right = n == highestAll(bar + extendRight);
def left = n == highestAll(bar - extendLeft);
def operableDays; # = 0
switch (period) {
case "WEEK" :
operableDays = 52;
case "MONTH" :
operableDays = 12;
default :
operableDays = 252;
}
def tickerid = close(Period = "Day")[1];
def vixID = close(Symbol = symbol);
#//Geting data
def previousClose = if !isNaN(tickerid) then tickerid else previousClose[1];
def vixClose = if !isNaN(vixID) then vixID else vixClose[1];
def raizCuadrada = Sqrt(operableDays);
def d = vixClose / raizCuadrada;
def ME = previousClose * (d / 100);
def pME_sup = previousClose + ME;
def pME_inf = previousClose - ME;
def ME_inv = previousClose;
def pRangoUp1 = ME_inv + ((pME_sup - ME_inv) * (FirstDeviation / 100));
def pRangoDn1 = ME_inv + ((ME_inv - pME_sup) * (FirstDeviation / 100));
def pRangoUp2 = ME_inv + ((pME_sup - ME_inv) * (SecondDeviation / 100));
def pRangoDn2 = ME_inv + ((ME_inv - pME_sup) * (SecondDeviation / 100));
Script RoundIT {
input RoundToInteger = no;
input value = close;
input round = 5;
def yy1 = value % Round;
def me = if RoundToInteger then
if yy1 > round / 2 then value + (Round - yy1) else Value - yy1 else value;
plot out = me;
}
def ME_sup = RoundIT(RoundToInteger, pME_sup, round);
def ME_inf = RoundIT(RoundToInteger, pME_inf, round);
def RangoUp1 = RoundIT(RoundToInteger, pRangoUp1, round);
def RangoDn1 = RoundIT(RoundToInteger, pRangoDn1, round);
def RangoUp2 = RoundIT(RoundToInteger, pRangoUp2, round);
def RangoDn2 = RoundIT(RoundToInteger, pRangoDn2, round);
plot line_inf = if left then ME_inf else
if right then ME_inf[extendRight] else na;
plot line_sup = if right then ME_sup[extendRight] else
if left then ME_sup else na;
plot line_inf1 = if right then RangoDn1[extendRight] else
if left then RangoDn1 else na;
plot line_sup1 = if right then RangoUp1[extendRight] else
if left then RangoUp1 else na;
plot line_inf2 = if right then RangoDn2[extendRight] else
if left then RangoDn2 else na;
plot line_sup2 = if right then RangoUp2[extendRight] else
if left then RangoUp2 else na;
plot line_previousClose = if right then previousClose[extendRight] else
if left then previousClose else na;
line_inf1.SetStyle(Curve.SHORT_DASH);
line_sup1.SetStyle(Curve.SHORT_DASH);
line_inf2.SetStyle(Curve.MEDIUM_DASH);
line_sup2.SetStyle(Curve.MEDIUM_DASH);
line_inf.SetDefaultColor(Color.MAGENTA);
line_sup.SetDefaultColor(Color.MAGENTA);
line_inf1.SetDefaultColor(Color.YELLOW);
line_sup1.SetDefaultColor(Color.YELLOW);
line_inf2.SetDefaultColor(Color.CYAN);
line_sup2.SetDefaultColor(Color.CYAN);
line_inf.EnableApproximation();
line_sup.EnableApproximation();
line_inf1.EnableApproximation();
line_sup1.EnableApproximation();
line_inf2.EnableApproximation();
line_sup2.EnableApproximation();
line_previousClose.EnableApproximation();
#-- Labels
def meRound = Round(ME, 2);
def supRound = Round(ME_sup, 2);
def infRound = Round(ME_inf, 2);
def vixRound = Round(vixClose, 2);
def cloRound = Round(previousClose, 2);
AddLabel(showTabel, "Period:(" + period + ")", Color.WHITE);
AddLabel(showTabel, "EM:(±" + meRound + ")", Color.YELLOW);
AddLabel(showTabel, "Expected Movement Up:($" + supRound + ")", Color.GREEN);
AddLabel(showTabel, "Expected Movement DOWN:($" + infRound + ")", Color.RED);
AddLabel(showTabel, "VIX:($" + vixRound + ")", Color.WHITE);
AddLabel(showTabel, "Previous Close:($" + cloRound + ")", Color.WHITE);
AddChartBubble(showLabel and left, line_inf, Round(line_inf, 2), Color.MAGENTA, no);
AddChartBubble(showLabel and left, line_sup, Round(line_sup, 2), Color.MAGENTA);
AddChartBubble(showLabel and left, line_inf1, Round(line_inf1, 2), Color.YELLOW, no);
AddChartBubble(showLabel and left, line_sup1, Round(line_sup1, 2), Color.YELLOW);
AddChartBubble(showLabel and left, line_inf2, Round(line_inf2, 2), Color.CYAN, no);
AddChartBubble(showLabel and left, line_sup2, Round(line_sup2, 2), Color.CYAN);
AddChartBubble(showLabel and left, line_previousClose, Round(line_previousClose, 2), Color.GRAY);
#-- END Of CODE