# cabe1332
# Scan study script to find stocks on sideways accumulation to acceleration phase.
# start code
input price = close;
input length = 10;
def tmp1 = if price > price[1] then price - price[1] else 0;
def tmp2 = if price[1] > price then price[1] - price else 0;
def d2 = sum(tmp1, length);
def d4 = sum(tmp2, length);
def cond = d2 + d4 == 0;
def ad3 = if cond then 0 else (d2 - d4) / (d2 + d4) * 100;
def coeff = 2 / (length + 1) * AbsValue(ad3) / 100;
def asd = compoundValue("visible data" = coeff * price + (if IsNaN(asd[1]) then 0 else asd[1]) * (1 - coeff), "historical data" = price);
def VMA = asd;
def vma8 = sum(volume * close,8) / sum(volume,8);
def vma21 = sum(volume * close,21) / sum(volume,21);
def vma34 = sum(volume * close,34) / sum(volume,34);
def bullish = if vma8 > vma21 and vma21 > vma34 then 1 else 0;
def bearish = if vma8 < vma21 and vma21 < vma34 then 1 else 0;
def distribution = if !bullish and !bearish then 1 else 0;
# bullish
plot accumulationtoacceleration = if (bullish and close>=VMA) and (!bullish[1]) then 1 else 0;
# bearish
#def distributiontoacceleration = if (bearish and close <= VMA) and (!bearish[1]) then 1 else 0;
# end code