Hi,
I have a simple script that I used elsewhere to find a spike in price/volume. I would like to use it here but need some assistance.
There are two parts, first one for a spike in price, second part for a spike in volume. Both are identical in form.
The final condition for the scan is to have true results for both the price and volume condition.
The pseudocode is below. The ''def'' keyword is used to define a variable or a constant, and also a condition.
c is the current price of the stock (not a 'closed' price - despite the name). c[1] is the closing value (price) of the last completed bar. c[2] is the closing value of the bar before c[1]. Same thing with volume v, v[1], v[2], v[3] etc.
The stdev(closeLog, 11) calculates the standard deviation of 11 values of closeLog. So (if my understanding is correct) first value will be log(c[1] / c[2]), second value will be log(c[2] / c[3]), etc up to the final 11th value, which will be log(c[11] / c[12]).
Any suggestions or help converting to a format suitable for the advanced scanner would be appreciated.
----------------------------------------------------------
def length = 11;
def c = close;
def closeLog = log(c[1] / c[2]);
def SDevClose = stdev(closeLog, length) * sqrt(length / (length-1));
def m = SDevClose * c[1];
def pricespike = (c - c[1]) / m > 3;
def v = volume;
def volumeLog = log(v[1] / v[2]);
def SDevVol = stdev(volumeLog, length) * sqrt(length / (length-1));
def n = SDevVol * v[1];
def volumespike = (v - v[1]) / n > 3;
scan = pricespike and volumespike;
-------------------------------------------------------------