Stock Screener not functioning for customValues studies

JoshS

Active member
Joined
Jul 26, 2021
Posts
43
Likes
15
Hello!

I'm wondering if anyone else is running into issues with the stock screener and using custom studies that use multiple timeframes (using calculateValues to populate their values)
I can see the resulting values looking correct in the study, but when I run the screener it is as if the returning values are random/fail. Further, its as if the debug output I have is being skipped or never called for the study. Without being able to share the study, I'm mostly wondering if others have run into problems like this with the Screener.

Simple custom studies have no issue, but as soon as I start screener for an advanced study that cares about more than one timeframe (ex: checking daily and weekly) it does't work.

example: running my custom study on apple returns a value of 50.0-- but checking if that value is greater than zero doesn't pass. I can see the study result for the latest bar and it's clearly above my threshold. It seems that whether it runs my logic or not depends on the value of Minimum Bars -- but it's also not returning valid values.


Thanks in advance for any thoughts/pointers
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
474
Likes
189
Oh, but I feel your pain, @JoshS 😩

I too have experienced 'very weird' behavior, both on MW's scanner and on the watchlist.

Some issues that I have encountered (make no mistake: this is a non-exhaustive list!):
  • Open up MW, run a scan that I use for a long time already once and scan works. Run it again after the next bar closes: epic fail. No errors in the Study log. Not even debug info (that does show up first time I run it). So it's as if the Scan never really runs at all after the first successful one. 🥺
    (other scans can be run multiple times successfully, so I figured it _had_ to be something code-related. My beard grew up to my keyboard trying to figure out what)
  • Copy an existing scan and add one criteria (that uses the same Study). Scan refuses to spit out results. Switch the order of the criteria, same issue.
    Check the values on a chart with the 'cursor data window': values show setups found, so scan should fire a few hits. 🤷‍♂️
  • Run a scan and be amazed that it works. Check scan-results visually: all look ok. Port that scan over to the Watchlist (simply by adding a column that prints the value that the scan looks for) and get completely different results. Open the 'cursor data window' to check: values are correct both on the 'scan-chart', and on the 'watchlist-chart'. So the values are just misprinted in the watchlist's column. No clue why. 🤯
  • Have a Watchlist with 4 columns. All 4 use the same Study, but 'watch' a different timeframe: M1, M5, M15 and H1. All is well for the first hour or so, but then (bad) magic happens: values that appear in columns are wrong, on all timeframes.
    Furthermore, I never seem to get a value below 5, so watchlist refuses to find 'hits' of that Study in the last 5 bars (which I what I want: being warned that a nice setup appears in the last bar or 2 bars ago or so). Checked and re-checked the criteria and even my code (which is fairly simple and straightforward). No answers so far 😢
  • Watchlist shows a positive value (15), while cursor data window AND debug in Study log show that same value, but negative (-15) 😖
I could go on. (and I have actually posted about some of this before; feel free to search the forum)

Let me conclude by saying that both the scanner and the watchlist-functionality need work.
Or someone needs to tell us what we can / cannot code into a Study that is used for scanning / watchlisting.

😏
 

TradersCustom

Member
Joined
Sep 8, 2022
Posts
12
Likes
6
While we've seen issues with multi-timeframe studies in the scanner as well, there's something you should look at. Are you by chance seeing duplicate results in your scan? If you're using 'global member variables' across your study (eg. creating an ArrayList variable outside the scope of the standard functions like calculate, onCalculate, etc.), be sure to always properly override the clone method to reset them to their initial values. Eg.:

@Override
public YourStudy clone() {
YourStudy study = null;
study = (YourStudy ) super.clone();
study.MyArrayList= new ArrayList<>();
study.MyDoubleValue = Double.NaN;
return study;
}

When a study gets called in the scanner or a watchlist, or a strategy in the optimizer, it doesn't actually use brand new 'objects/instances' of the study... It actually copies the previous study 'object' and feeds the new price data through it - so the values for your global variables will carry over from call to call as they are cloned. The study's member objects/internal variables thus need to be reset to their initial values by manually overriding the clone method.

As you mentioned with minimum bars, the way that the scanner/watchlist loads data for other timeframes also differs compared to how it works with a study on the chart, and you'll probably have to do a lot of debugging in that area to find the exact source of the differences.

Just some food for thought.

Perhaps you could post an ultra-simplified version of your study to take a look at.
 
Last edited:

Spin

Well-known member
Joined
May 22, 2019
Posts
474
Likes
189
Very interesting comment, @TradersCustom !

I think you might be on to something, and I was wondering if I could pick your brain on one of the issues I am facing :)

I have a watchlist that uses a custom-coded Study, and for simplicity's sake we'll call it 'R1'. This Study looks for an event that took place on the chart and outputs the number of bars ago this happened to the cell on the Watchlist.
The first time it is run, all is well. This could either be on launching MW, or when I add a custom column (the one that uses this R1 to populate the cells) to the Watchlist. Say I have the custom column in my watchlist to check every 5 minutes.

The issue I am experiencing is this: the cells don't change values after a bar completes.
e.g.: I add the column and the EUR/USD column shows '5', telling me that I got a valid signal 5 bars ago. Time passes, and a few extra 5-minute bars closed, so I am expecting a 7 or 8 or 9 in that cell now. I see the correct number in the Study Log (so the Study and more specifically 'calculateValues' IS called every time a bar closes and DOES calculate correctly) but the number in the cell does not change.

Removing the custom column from the Watchlist and adding it again OR restarting MW helps: the correct values show up magically. But that is not what one would expect from a watchlist. 😏

I am using a few global variables that are calculated outside of 'calculate' and 'calculateValues', and I am resetting them before any calculation is done, and I believe that part works well (given the correct numebrs show up in the Study Log).
But I am curious about this phrase though:
When a study gets called in the scanner or a watchlist, or a strategy in the optimizer, it doesn't actually use brand new 'objects/instances' of the study... It actually copies the previous study 'object' and feeds the new price data through it - so the values for your global variables will carry over from call to call as they are cloned.

Is it possible that I need to reset something else or re-initialize the Study so that it starts with a clean sheet every time a bar is closed and every time it moves on to the next instrument ? And how would one do such a thing ? :unsure:

All input welcome !
Thanks in advance 🙂
 

TradersCustom

Member
Joined
Sep 8, 2022
Posts
12
Likes
6
Very interesting comment, @TradersCustom !

I think you might be on to something, and I was wondering if I could pick your brain on one of the issues I am facing :)

I have a watchlist that uses a custom-coded Study, and for simplicity's sake we'll call it 'R1'. This Study looks for an event that took place on the chart and outputs the number of bars ago this happened to the cell on the Watchlist.
The first time it is run, all is well. This could either be on launching MW, or when I add a custom column (the one that uses this R1 to populate the cells) to the Watchlist. Say I have the custom column in my watchlist to check every 5 minutes.

The issue I am experiencing is this: the cells don't change values after a bar completes.
e.g.: I add the column and the EUR/USD column shows '5', telling me that I got a valid signal 5 bars ago. Time passes, and a few extra 5-minute bars closed, so I am expecting a 7 or 8 or 9 in that cell now. I see the correct number in the Study Log (so the Study and more specifically 'calculateValues' IS called every time a bar closes and DOES calculate correctly) but the number in the cell does not change.

Removing the custom column from the Watchlist and adding it again OR restarting MW helps: the correct values show up magically. But that is not what one would expect from a watchlist. 😏

I am using a few global variables that are calculated outside of 'calculate' and 'calculateValues', and I am resetting them before any calculation is done, and I believe that part works well (given the correct numebrs show up in the Study Log).
But I am curious about this phrase though:


Is it possible that I need to reset something else or re-initialize the Study so that it starts with a clean sheet every time a bar is closed and every time it moves on to the next instrument ? And how would one do such a thing ? :unsure:

All input welcome !
Thanks in advance 🙂
Hey I'm sorry for the late response I totally missed the notification. Yes I 100% believe that the issue is related to this cloning/re-initialization problem. I've seen this exact issue countless times now, with new bars not updating the cells and with instrument changes as well. If you want, feel free to send me the study and I'll take a look if it's not some top secret proprietary stuff. I think we can figure it out. Good mental exercise for me.
 
Top