Your variable named "condition
" is a true/false variable. The numeric equivalent to true/false on Thinkorswim is 1/0. So either a 1 or a zero. 1 if true and 0 if false. You are testing if the value is greater than 1. This variable will never be greater than 1.
Update. In response to a question about my solution I am providing the full code modified to run as a scan
Yes, only one plot is accepted in any scan. So you simply change the plot statements to def. Then you add your plot scan statement. And this will not work either:
plot scan = condition < 0;
The variable named condition
is a true/false variable. In Thinkorswim, True is numerically equal to 1 and False is numerically equal to zero. Therefore, the variable named condition
can NEVER be less than zero. I know I already explained this in the original answer I provided above. However the comment added after my answer indicated that message was not understood.
Here is the code for the scan:
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);
def RelVol = if allowNegativeValues then rawRelVol else Max(0, rawRelVol);
def condition = percentRise >= percentSpike and volume > 4000000 and relVol > 2;
plot scan = condition;
Notice the plot scan statement does not contain any test for equal to, greater than or less than. This is because condition is a true/false variable. Which is the only data type that you can use for a scan. Writing it the way I did is equivalent to this: plot scan = condition == 1;
"...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;