Scan condition for former runner


Category:
0
0

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

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on August 26, 2019 9:17 pm
174 views
0
Private answer

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;

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on August 27, 2019 7:22 am
0
so I changed it to plot scan = condition < 0; but I am still having an error saving "Exactly one plot expected" Can you show me send me how you would write the code so I can compare and contrast my error for this logic . Best
( at August 27, 2019 8:23 am)
0
Ok, I have updated my answer to explain things in more detail.
( at August 27, 2019 12:18 pm)
0
U ROCK !!!!
( at August 27, 2019 2:51 pm)
0
Hello Pete, so from testing I think we forgot one condition. The stock must be a "Previous runner" The code right now brings up a stock that triggered these conditions on the current day. What should happen is that The code should find any day in the past on the daily chart that triggered these conditions . Best
( at August 29, 2019 12:46 pm)
0

"...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.

( at August 29, 2019 2:11 pm)
0
what does the function ”Highest” mean? The reason i ask, because i have found a flaw that the scan will only pick up stocks that have a minimum number of candles on the daily chart to calculate. For example if i set plot scan = Highest(condition, 300) > 0; It wont pick up any symbols that have not traded more than 300 dailey candles. Case example being MTC. This ticker is a previous runner but doesn’t get picked up because it hasn’t traded for 300 total days yet. Can we set up the code in a way where isnt a minimum number of trading these it needs to have on daily chart?
( at August 29, 2019 3:15 pm)
0

replace:

plot scan = Highest(condition, 10) > 0;

with this:

rec trackCondition = if condition then 1 else trackCondition[1];
plot scan = trackCondition;

( at August 29, 2019 8:25 pm)
0
very nice, testing it. Works sweet so far
( at August 30, 2019 11:12 am)
0
The function named "Highest()" looks backward a specified number of bars and returns the highest value found, for the data series you enter in the first parameter. More details here: http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Tech-Analysis/Highest.html
( at August 30, 2019 2:20 pm)