Vidya Indicator Scan


Category:
0
0

Hello Sir,

I want to say thank you for all you do. I really love this Vidya indicator and I’m trying to build the scan but it always returns no results.  I want to get the scan results of the vidya1 crosses above the vidya2.

My script for the scan.

Ray_Vidya2().”pVidya1″ crosses above Ray_Vidya2().”pVidya2″ within 10 bars

Attachments:
Marked as spam
Posted by (Questions: 5, Answers: 4)
Asked on May 23, 2020 3:53 pm
212 views
0
Private answer

You really want to avoid trying to reference the name of a custom study. To many things can prevent that from work correctly. There are some tools on Thinkorswim for which this will not work at all. So for mission critical solutions it's always best to use the entire code rather than reference the name of a study, even if the study is one of the built-in studies.

I reduced your code down to the bare essentials required to produce a scan and this is what is left:

input price = close;
input period = 20;
input alpha1 = 0.2;
input alpha2 = 0.04;
def stdDev = StDev(price, period);
def avStdDev = Average(stdDev, period);
def ratio = stdDev/avStdDev;
rec vidya1 = (alpha1 * ratio * price) + ((1 - (alpha1 * ratio)) * vidya1[1]);
rec vidya2 = (alpha2 * ratio * price) + ((1 - (alpha2 * ratio)) * vidya2[1]);
#use this to scan for crossing above
plot scan = Crosses(vidya1, vidya2, CrossingDirection.ABOVE);
# use this to scan for crossing below
#plot scan = Crosses(vidya1, vidya2, CrossingDirection.BELOW);

Now I also see that in your suggested scan code you included a condition that checks if the crossover signal was true within the last ten bars. I can provide a couple of additional scan statements that will cover that too:

#use this to scan for crossing above
plot scan = Crosses(vidya1, vidya2, CrossingDirection.ABOVE) within 10 bars;
# use this to scan for crossing below
#plot scan = Crosses(vidya1, vidya2, CrossingDirection.BELOW) within 10 bars;

Those four lines of code can be used in place of the last four lines of code in the solution I provided above.

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on May 23, 2020 4:46 pm
0
I'm really sorry for creating an another thread and I will try to delete it if possible. Thank you Pete for looking at the Vidya scan. I was getting the Scan results by using your code but when I look at the chart for the stocks from the results, the vidya1 is not crossing over vidya2. I’m not a coder and your help is much appreciated.
( at May 23, 2020 6:59 pm)
0
Private answer

This is an update to my previous answer. I am only adding a new answer to this question so that I can provide screenshots to support the explanation below.

Your chart needs to have more than 3 months of data to fully compute these lines. On the daily time frame the scan is using approximately 2 years of data:

https://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters

When I load 1 year of data on the chart the values appear to be fully computed. When I load 6 months of data it also fully computes the values (see screenshot below). It seems that something less than 6 months of historical data is where this fails to properly compute. Want to know what is happening here and why the amount of data loaded on your chart is impacting the computation of these lines?

https://www.hahn-tech.com/moving-averages-exponential-problems/

Your code is computing the standard deviation for 20 periods. It then takes that average and folds it inside a moving average. It then divides that standard deviation by the average. The end result is code for which Thinkorswim is unable to prefetch sufficient historical data to fully compute the values.

One way you may provide a more robust computation is to use a CompoundValue() statement to initialize each line at the value of the close for the first bar on the chart. This should help to reduce the number of historical bars required to fully compute these values. In plain English? The code is poorly written. See the second screenshot below for the graphical explanation.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on May 23, 2020 7:08 pm
0
Sorry, I have already spent twice the amount of time on this that I permit for free solutions in the Q&A forum. Wish I could do more.
( at May 23, 2020 10:47 pm)
0
Thank you and really appreciate it.
( at May 24, 2020 6:57 am)