Hello Pete,
I hope all is well. I need help editing some code that I use on the daily chart that identifies a stock as a former runner based on the below criteria.
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;
input percentSpike = 35.0;
input countLimit = 5;
def percentRise = 100 * (high / open – 1);
def rawRelVol = (volume – Average(volume, length)) / StDev(volume, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def condition = percentRise >= percentSpike and volume > 4000000 and relVol > 2;
rec counter = if condition and BarNumber() >= 0 then counter[1] + 1 else counter[1];
AddLabel(yes, Concat(“History of Spiking: “, counter), if counter > countLimit then Color.GREEN else Color.WHITE);
However, I am having issues turning this label into a scan condition.
input length = 60;
input numDev = 2.0;
input allowNegativeValues = no;
input percentSpike = 35.0;
input countLimit = 5;
def percentRise = 100 * (high / open – 1);
def rawRelVol = (volume – Average(volume, length)) / StDev(volume, length);
plot RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def condition = percentRise >= percentSpike and volume > 4000000 and relVol > 2;
rec counter = if condition and BarNumber() >= 0 then counter[1] + 1 else counter[1];
plot scan = condition > 1;
Can you please help me out. All the best
Like this:
Like Loading...
"...any day in the past...". That is probably going to return every single stock from whatever list you are searching from. I suggest you think about that before proceeding with a solution that performs that way. Here is one way you can check if the condition was true for any bar in the most recent 10 bars:
plot scan = Highest(condition, 10) > 0;
Change the value of 10 to however many days back you want to search.
replace:
plot scan = Highest(condition, 10) > 0;
with this:
rec trackCondition = if condition then 1 else trackCondition[1];
plot scan = trackCondition;