BULLFIZZ
New member
 Platform

 Thinkorswim
Code:
#TITLE
#PRC_Volatility Cycle Breakout  indicator
#DESCRIPTION
#The Volatility Cycle Breakout indicator draws range boxes overlaid on the price chart.
#The upper and lower side of the boxes are made from recent Fractals.
#New boxes will be drawn only if the volatility is weak and
#if the new fractals discovered are far enough from the current upper and lower ones.
#
#The volatility cycle is extracted from Bollinger Bands (InpBandsPeriod=18 is the bands period).
#Fractals lookback periods can be adapted to catch new fractals far in the history
#or near of the current price (cp=10).
#
#The change variable is the percent variation needed to change the support and resistance
#levels of the boxes (0.1% seems to work fine for intraday timeframes on forex pairs for instance).
#
#This setting is important because it will reduce the noises of moving boxes each
#time new Fractals are discovered, specially when price is ranging. It results
#erfect range boxes on price to play mean reversion strategy when price is not moving enough
#to make real breakout.
#CREDITS
#https://www.prorealcode.com/prorealtimeindicators/volatilitybreakoutindicator/
#https://www.prorealcode.com/user/nicolas/
#CHANGELOG
#2019.11.03 @diazlaz Initial Port
declare upper;
#INPUTS
input InpBandsPeriod = 18; #Period
input Smooth = 2; #Smoothness
input cp = 10; #Fractals periods
input change = 0.1; #Percent change to modify the upper/lower channel
input showArrows = no; # price cross channels signals
#LOGIC
def StdDev = StDev(close, InpBandsPeriod);
def highindex = Highest(StdDev, InpBandsPeriod)[1];
def lowindex = Lowest(StdDev, InpBandsPeriod)[1];
def VolDer = (StdDev  highindex) / (highindex  lowindex);
def VolSmooth = Average(VolDer, Smooth);
def VolSmooth1 = if VolSmooth > 0 then 0 else
if VolSmooth < 1.0 then 1.0 else VolSmooth;
def LH = if high[cp] >= Highest(high, (2 * cp + 1)) then 1 else 0;
def LL = if low[cp] <= Lowest(low, (2 * cp + 1)) then 1 else 0;
def TOPy = if LH == 1 then high[cp] else TOPy[1];
def BOTy = if LL == 1 then low[cp] else BOTy[1];
def upperchannel = if VolSmooth1 == 1.0 then
if AbsValue(TOPy  CompoundValue(1, upperchannel[1], 0)) / close > change / 100
then TOPy else upperchannel[1]
else upperchannel[1];
def lowerchannel = if VolSmooth1 == 1.0 then
if AbsValue(BOTy  CompoundValue(1, lowerchannel[1], 0)) / close > change / 100
then BOTy else lowerchannel[1]
else lowerchannel[1];
#PLOTS
plot pUpperChannel = upperchannel;
pUpperChannel.SetLineWeight(2);
pUpperChannel.SetDefaultColor(CreateColor(100,150,100));
plot pLowerChannel = lowerchannel;
pLowerChannel.SetLineWeight(2);
pLowerChannel.SetDefaultColor(CreateColor(150,100,100));
#ARROWS
plot pUP = close crosses above lowerchannel;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.SetDefaultColor(Color.GREEN);
pUP.SetLineWeight(2);
pUP.SetHiding(!showArrows);
plot pDown = close crosses below upperchannel;
pDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDown.SetDefaultColor(Color.RED);
pDown.SetLineWeight(2);
pDown.SetHiding(!showArrows);
#FILLS
AddCloud(pUpperChannel, pLowerChannel,COLOR.GRAY,COLOR.GRAY, yes);
#END OF PRC_Volatility Cycle Breakout  indicator
Last edited by a moderator: