Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### Expected Move Labels ###
- # This script will add expected move labels, #
- # in dollars, to charts. IT IS INTENDED TO BE#
- # USED ONLY ON CHARTS WITH DAILY BARS. The #
- # math will not work one charts with other #
- # settings. #
- ### Settings for coloring ###
- input customWindow = 50;
- input violationMetricHigh = high;
- input violationMetricLow = low;
- input centerPoint = close;
- def dayCountBacktest = 3;
- def weekCountBacktest = 5;
- def monthCountBacktest = 22;
- def customWindowBacktest = customWindow - (RoundDown(customWindow / 7, 0) * 2);
- def customWindowDanger = RoundUp(customWindowBacktest * 0.32, 0);
- def customWindowWarning = RoundDown(customWindowBacktest * 0.16, 0);
- def dayCountDanger = RoundUp(dayCountBacktest * 0.32, 0);
- def dayCountWarning = RoundDown(dayCountBacktest * 0.16, 0);
- def weekCountDanger = RoundUp(weekCountBacktest * 0.32, 0);
- def weekCountWarning = RoundDown(weekCountBacktest * 0.16, 0);
- def monthCountDanger = RoundUp(monthCountBacktest * 0.32, 0);
- def monthCountWarning = RoundDown(monthCountBacktest * 0.16, 0);
- script ExMove {
- input center = 0;
- input window = 1;
- def IVBase = imp_volatility();
- plot ExMove = center * IVBase * Sqrt(window / 365);
- }
- ### Calculate the expected move ###
- def ExMoveOneDay = ExMove(centerPoint, 1);
- def ExMoveOneWeek = ExMove(centerPoint, 7);
- def ExMoveOneMonth = ExMove(centerPoint, 30);
- def ExMoveCustom = ExMove(centerPoint, customWindow);
- ### Determine violations ###
- def dayBacktestCenter = (Average(close, dayCountBacktest) + Average(close, RoundUp(dayCountBacktest/2, 0)) + Average(close, RoundUp(dayCountBacktest/4, 0)))/3;
- def dayCount = fold i = 1 to dayCountBacktest with countA = 0
- do
- if violationMetricHigh[i] > (dayBacktestCenter + ExMoveOneDay) or violationMetricLow[i] < (dayBacktestCenter - ExMoveOneDay) then
- countA + 1
- else
- countA;
- def weekBacktestCenter = (Average(close, weekCountBacktest) + Average(close, RoundUp(weekCountBacktest/2, 0)) + Average(close, RoundUp(weekCountBacktest/4, 0)))/3;
- def weekCount = fold n = 1 to weekCountBacktest with countB = 0
- do
- if violationMetricHigh[n] > (weekBacktestCenter + ExMoveOneWeek) or violationMetricLow[n] < (weekBacktestCenter - ExMoveOneWeek) then
- countB + 1
- else
- countB;
- def monthBacktestCenter = (Average(close, monthCountBacktest) + Average(close, RoundUp(monthCountBacktest/2, 0)) + Average(close, RoundUp(monthCountBacktest/4, 0)))/3;
- def monthCount = fold m = 1 to monthCountBacktest with countC = 0
- do
- if violationMetricHigh[m] > (monthBacktestCenter + ExMoveOneMonth) or violationMetricLow[m] < (monthBacktestCenter - ExMoveOneMonth) then
- countC + 1
- else
- countC;
- def customBacktestCenter = (Average(close, customWindowBacktest) + Average(close, RoundUp(customWindowBacktest/2, 0)) + Average(close, RoundUp(customWindowBacktest/4, 0)))/3;
- def customCount = fold o = 1 to customWindowBacktest with countD = 0
- do
- if violationMetricHigh[o] > (customBacktestCenter + ExMoveCustom) or violationMetricLow[o] < (customBacktestCenter - ExMoveCustom) then
- countD + 1
- else
- countD;
- ### Add labels to chart ###
- AddLabel(yes, "Range at 68% confidence", Color.WHITE);
- AddLabel(yes, "1 Day: +/-" + AsDollars(ExMoveOneDay) + "(" + dayCount + "/" + dayCountBacktest + ")", if dayCount >= dayCountDanger then Color.RED else if dayCount < dayCountDanger and dayCount > dayCountWarning then Color.YELLOW else Color.GREEN);
- AddLabel(yes, "1 Week: +/-" + AsDollars(ExMoveOneWeek) + "(" + weekCount + "/" + weekCountBacktest + ")", if weekCount >= weekCountDanger then Color.RED else if weekCount > weekCountWarning and weekCount < weekCountDanger then Color.YELLOW else Color.GREEN);
- AddLabel(yes, "1 Month: +/-" + AsDollars(ExMoveOneMonth) + "(" + monthCount + "/" + monthCountBacktest + ")", if monthCount >= monthCountDanger then Color.RED else if monthCount > monthCountWarning and monthCount < monthCountDanger then Color.YELLOW else Color.GREEN);
- AddLabel(yes, customWindow + " Days: +/-" + AsDollars(ExMoveCustom) + "(" + customCount + "/" + customWindowBacktest + ")", if customCount >= customWindowDanger then Color.RED else if customCount > customWindowWarning and customCount < customWindowDanger then Color.YELLOW else Color.GREEN);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement