First thing I must mention is the code you provided is very poorly written. I am not criticizing. Merely pointing out to everyone that the code contains elements that everyone should avoid. Code like this is what leads to newbies writing code like this. It perpetuates poor code writing among those who are learning how to write code.
I won't waste any time correcting the code. But I will mention that it makes use of excessive abbreviations. Variable names such as k, src, pdm, mdm.... garbage. They mean absolutely nothing. Variable names should explain exactly what is being computed. Otherwise it is impossible to read the code and know what it's doing. The other huge mistake is not including spaces between operators.
This line itself says it all, pure garbage:
def iS = if isnan(is[1]) then k*d/s1 else ((1 – k)*(iS[1]) + k*d/s1);
Seriously...
I really hate to see code like this. If you had to write something like this in C++ it would never work. Because C++ actually forces you to write code properly
So you want a scan statement that returns a list of stocks for which the main plot is colored Cyan and another for when the main plot is color Dark Orange. The logic we need to construct this is contained on the last three lines. Well, one of the last three lines.
plot pVMA = vma(price,length);
pVMA.assignValueColor(if pvma>pvma[1] then color.CYAN else if pvma<pvma[1] then color.DARK_ORANGE else color.gray);
pvma.setlineWeight(3);
The first step in converting to scan is to change the plot to def and remove the last two lines. This is what remains:
def pVMA = vma(price, length);
Next we add two lines that you can use to run your scans. Only one if these can be used at any given time. So comment out the one you don't want to run before trying to save and run the scan:
plot scan = pVMA > pVMA[1];
OR....
plot scan = pVMA < pVMA[1];
That's it. Notice I added spaces between the operators and variables. The original contained no spaces. I also corrected the variable names to match what is used for the variable assignment. The end result is the same except added the spaces and correct capitalization makes the code much easier to read.