wtf_dude
Well-known member
Alright, this hits all of the criteria from what I can tell but I also added a fall in bollinger band width to make sure volatility itself is contracting. Not a fan so far. Probably needs more tweaking and good luck getting it to scan (Without timing out).Awesome, thank you so much!!
Code:
# VCP indicator translated from AFL
# WTF_Dude 4.29.21
declare upper;
input longperiod = 128;
input base_Lower_Limit = 30;
input shortperiod = 5;
input shortdepthmax = 10;
####
def LongTop = Highest(high, longperiod);
def LongBottom = Lowest(low, longperiod);
def longdepth = (LongTop - LongBottom) / LongTop;
def LongDepthTarget = longdepth <= .3;
def highdist = GetMaxValueOffset(high, longperiod);
def lowdist = GetMinValueOffset(low, longperiod);
### Volume Target Criteria
def reglength = 20;
def volavg = simpleMovingAvg(volume,50);
def volreg = linearRegressionSlope(volavg,reglength);
def VolTarget = volreg <= 0;
###################
### Short term depth
def ShortTop = Highest(high, shortperiod);
def ShortBottom = Lowest(low, shortperiod);
def ShortDepth = (ShortTop - ShortBottom) / ShortTop;
def shortdepthtarget = ShortDepth < shortdepthmax / 100;
##### Bollinger Bandwidth Decreasing
input BBaverageType = AverageType.Simple;
def price = close;
def displace = 0;
def length = 20;
def Num_Dev_Dn = -2.0;
def Num_Dev_Up = 2.0;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, BBAverageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, BBaverageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, BBaverageType).MidLine;
def Bandwidth = (upperBand - lowerBand) / midLine * 100;
def BWavg = simplemovingavg(bandwidth,20);
def BWavgSlope = linearRegressionSlope(bwavg,20);
def BBbwSlopeTarget = BWavgSlope<0;
#### Nav Labels
addlabel(yes, "High Dist: " + highdist,color.light_Gray);
addlabel(yes, "Low Dist: " + lowdist,color.light_Gray);
addlabel(yes, "Depth: " + Longdepth,color.light_Gray);
addlabel(yes, "Depth%: " + aspercent(Longdepth),color.light_Gray);
addlabel(yes, "Short Depth: " + aspercent(ShortDepth), color.light_Gray);
addlabel(yes, "Volavgslope: " + volreg, color.light_gray);
addlabel(yes, "BBwidthSlope: " + BWavgSlope, color.light_Gray);
def finalcontract = close<=highest(close, shortperiod);
def upmove1 = close> longbottom and close>shortbottom;
def upmove2 = close>lowest(close,shortperiod);
#### Plotting type
plot VCP = LongDepthTarget and VolTarget and shortdepthtarget and BBbwSlopeTarget and finalcontract and upmove1 and upmove2;
#and lowafterhightarget and VolTarget and shortdepthtarget and BBbwSlopeTarget;
VCP.SetPaintingStrategy(PaintingStrategy.boolean_points);
VCP.SetDefaultColor(Color.cyan);
VCP.setlineWeight(1);
Last edited: