The below code is for finding stocks that provides the VSA Green Arrow indications in
TOS Scan Hacker. This code must be entered as one of the criteria and as custom code. I also add criteria for price above 5 and volume above 300,000 shares for day. The nice thing about the code is that you can selectively use for monthly, weekly, daily, etc by changing the time period. This may affect the volume filter but I am not sure.
# Arguments
def volumeEMALength = 30;
def narrowSpreadFactor = 0.7;
def wideSpreadFactor = 1.5;
def aboveAvgVolfactor = 1.5;
#######
# Calculations
rec spread = high - low;
def median = (high + low ) / 2;
rec avgVolume = compoundValue(volumeEMALength, ExpAverage(volume,
volumeEMALength), Double.NaN);
# Calculate Volume
moving average and it's
standard deviation
rec sAvgVolume = compoundValue(volumeEMALength, Average(volume,
volumeEMALength), Double.NaN);
def sAvgVolumeSTD = stdev(sAvgVolume, volumeEMALength);
# check if the vloume has been decreasing in the past two days.
def isTwoDaysLowVol = (volume < volume[1] && volume[0] < volume[2]);
# Calculate
Range information
def avgSpread = WildersAverage(spread, volumeEMALength)[0];
rec isWideSpreadBar = (spread > (wideSpreadFactor * avgSpread));
rec isNarrowSpreadBar = (spread < (narrowSpreadFactor * avgSpread));
# Check if the close is in the Highs/Lows/Middle of the bar.
# C_RP 20100809
# original code - def x1 = if (close == low) then avgSpread else (spread /(close - low));
def x1 = if (high == low) then 2.0 else if (close == low) then 2.65 else (spread /
(close - low));
# C_RP try the line below with various divisors totalSum result in a minimum of 2.3 on a spread of 1
pip instead of using a fixed 2.3 as in the line above
# def x1 = if (high==low) then 2.0 else if (close == low) then (spread / 0.43 ) else (spread / (close - low));
# Price information
rec isUpBar = close > close[1];
rec isDownBar = close < close[1];
def isUpCloseBar = (x1 < 2);
def isDownCloseBar = (x1 > 2);
def isMidCloseBar = (x1 < 2.2 && x1 > 1.8);
def isVeryHighCloseBar = (x1 < 1.35);
# C_RP 20100809 added isVeryLowCloseBar
def isVeryLowCloseBar = (x1 >= 2.65);
# Trend Definitions
rec fiveDaysSma = compoundValue(5, Average(close, 5)[0], Double.NaN);
def LongTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
40)[0];
def ShortTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
5)[0];
def MiddleTermTrendSlope = LinearRegressionSlope(price = fiveDaysSma, length =
15)[0];
# stdn, stdn0, stdn1, stdn2
def strengthInDownTrend = (volume[0] > volume[1] && isDownBar[1] && isUpBar[0]
&& (isUpCloseBar or isMidCloseBar) && ShortTermTrendSlope < 0 &&
MiddleTermTrendSlope < 0);
def strengthInDownTrend1 = (volume[0] > (sAvgVolume[0] * aboveAvgVolfactor) &&
isDownBar[1] && isUpBar[0] && (isUpCloseBar or isMidCloseBar) &&
ShortTermTrendSlope < 0 && MiddleTermTrendSlope < 0 && LongTermTrendSlope < 0);
def strengthInDownTrend2 = (volume[1] < sAvgVolume[0] && isUpBar[0] &&
isVeryHighCloseBar && volume[0] > sAvgVolume[0] && ShortTermTrendSlope < 0);
rec bycond1 = (strengthInDownTrend or strengthInDownTrend1);
# bycond
def isStrengthConfirmationBar = (isUpBar[0] && bycond1[1]);
# bycond2 C_RP UpClose on higher volume with all slopes down
adds extra strength
def isStrengthConfirmationBar2 = (isUpBar[0] && isUpCloseBar[0] && volume[0] >
volume[1] && LongTermTrendSlope < 0 && bycond1[1]);
# Plot with green arrow
# green triangle up at bottom of the bar C_RP Green arrow up 4 * tickSize for strong strength_In_DownTrend
# plot isStrengthConfirmationBarPlot = if isStrengthConfirmationBar then (low - 5 * tickSize()) else if isStrengthConfirmationBar2 then (low - 9 * tickSize()) else Double.NAN;
plot isStrengthConfirmationBarPlot = (isStrengthConfirmationBar);
# green triangle up at bottom of the bar C_RP Green arrow up 7 * tickSize for strongest strength_In_DownTrend with isUpCloseBar
# plot isStrengthConfirmationBarPlot2 = if isStrengthConfirmationBar2 then (low - 9 * tickSize()) else Double.NAN;