Divergence pattern scanner
Author: topcat77
Creation Date: 4/25/2008 3:01 PM
profile picture

topcat77

#1
Wealth-Lab Version 5 (.NET) 5.0

I run a pattern-recognition system on 30min bars in currencies/indexes and would like to build an eod stock scanner to look for a single pattern signature:
If, in period n (which is an input variable defining no. of days as a time horizon) stock makes a new low (on daily bar) and 1)that low is at or under the Bollinger Band (close, 20, 2)and 2) there is an rsi divergence with the previous low for the period, then purchase the stock at next open (or simply flag an eod signal). The scanner would reverse all criteria to search for the same conditions at new highs. It would be great to get some help, I am a longtime ATP trader but have not used WealthLab before. Thnx
profile picture

Cone

#2
So we've got intraday and daily indicators. You specified new "daily" low, but what scale are the Bollinger and rsi?

Assuming they're both in the intraday scale, here's the code for the "Lowest" scan.

CODE:
Please log in to see this code.
profile picture

topcat77

#3
Thnx v m , let me play with this
profile picture

topcat77

#4
Cone, is there a community of expert programmers for WealthLab who would write out a custom strategy for a fee? For example there is such a group who programme around eSignal, the data provider,and this is an efficient way to get from A to B for a trader who is non-intuitive around systems
profile picture

Cone

#5
Do a title search for programmer
profile picture

topcat77

#6
Thnx again, though that thread (surprisingly) seemed not to lead anywhere
Now I have pasted in the script that you sent me but I can't seem to be able to generate any results , although I know that viable signals exist. I am using WLab 5.0. Even the simple things that I can see the script intends to do (like color the previous low bar) have not taken. All thoughts welcome
profile picture

Cone

#7
The script won't color the bar if the condition necessary to do that doesn't exist. If you see the indicators in the chart, then you've run the script properly, and, it works perfectly. If it doesn't do what you want, then your requirements were inadequate - I asked some questions that you never answered.
profile picture

topcat77

#8
The scale for both the Bollinger Bands and Rsi are "close" of the daily bars -
have I answered that correctly? the BB's are (2,20, close )the Rsi is (14, close). New lows are lowest price on daily bars. Hope that completes the info needed. And yes, I tried the "compile" button. Thnx
profile picture

Cone

#9
So what indicator, if any, is supposed to be 30-min intraday? The requirements are still not clear (or seemingly have changed from your first post).

This script above runs only on intraday data, and, the BBs and RSI are in the intraday scale. However, after looking at it just now, I can see that it does not test for the new daily low close dipping under the BB.

Nonetheless, if we can just clear up the requirements, it will only take 30 seconds to fix it.

But it will have to wait for another day now!
profile picture

topcat77

#10
ok I see the source of the confusion; my fault. At the outset I described my pattern-recognition system as running on 30-min bars but went on to describe a single-stock scanner without making clear that the pattern-signature that I was looking for there would use only daily bars at eod (ie not the same as the 30-min bars I trade off for currencies, indexes etc). So all the parameters would be for daily bars (hi's/lo's bb's, rsi etc)and only at eod. Does this clarify things ? Thnx again
profile picture

Cone

#11
That makes it even easier. Here's the code with a slider for "Period" -

CODE:
Please log in to see this code.
profile picture

topcat77

#12
Still can't any info from this baby. I must have the start-up blues - this is what I do : copy the script; delete the mock-up script on New Strategy from rules; post this script in; save; activate strategy. Is this all correct?

Can you get any signals if you run the strategy? If the low today is lower than the low 20 days ago and today's low (not necessarily the close) penetrated or touched the lower bb and todays rsi is higher than previous low's rsi then the strategy has a signal. There are loads of viable signals but the script doesn't get them. i'm sure that I'm missing something simple but what /
profile picture

Cone

#13
See User Guide, Introduction: How to run Example code.

Let's work it in reverse. What symbol do you think should be giving you a signal, and on which day?
profile picture

topcat77

#14

some examples

CME LOW RSI

mar17 399.01 33.56 signal
mar10 461.25 28.93

C

mar17 17.99 25.37 signal
mar10 19.69 20.07

AAPL

feb22 115.87 30.54 signal
feb7 117.27 21.57

IBM

jan7 99.03 33.27 signal
nov9 07 99.27 22.20

profile picture

Cone

#15
o The script gives a signal for CME for Mar 17.
o LOW - the Close is not below the BB on Mar 17.
o RSI - not a valid symbol
o C - the Close is not below the BB on Mar 17.
etc...

Remember, per your requirements, this is a scanner. It only looks for something that occurs on the last bar. If you're looking for a signal on Mar 17, then the last bar in the chart has to be Mar 17. You must set a Date Range in the Data Loading Control to see that.
profile picture

topcat77

#16
ok, i'm (slowly) getting the idea
1) the close does not have to be below the bb.; the only requirement is that the low of the daily bar breaches the lower bb; how can i correct the code for this? this would show the signals in C, AAPL etc
2) rsi - i included a column for rsi to illustrate the signal mechanism
3) is it possible to see all previously scanned signals? perhaps if i insert (simple) exit conditions then this will serve both as a scanner and allow for backtesting ?

thnx v m again
profile picture

Cone

#17
AAPL - there are actually 2 signals close together
IBM - doesn't qualify either because the RSI is not divergent with the low prices.

1) If you just take a look at the code, and perhaps review the WealthScript Guide just a little, you could do this easily on your own.

2) LOW is actually a symbol so that's confusing. In the future, when you post data that's supposed to be in columns click the format codes link so you can learn how to do it.

3) Done, code above has the changes. There are no backtesting rules for buying and selling, so the code just highlights the conditions when they occur.

That's it, you've wore me out. Next time, try to organize your requirements better and explain them concisely. Nobody likes to code when the requirements are changing.
profile picture

topcat77

#18
Cone you're a star. I changed the code in about four places to read the lows instead of the close and , having learnt how a scanner functions, everything works brilliantly. I'll begin trading my Fund on Atp this month. I'm going to attempt to program a sell version of this. Aplogies for the many iterations and thnx again
profile picture

denoving

#19
Hi: I'm almost embarassed to post this problem I'm having,
but I can't seem to find a way to accomplish what it is that I'm trying to do.

My trading system uses stocks that have increased or decreased [using day bars] from the
previous day by 0.7%.

Using the previous pascal based system to do what I want was incredibly simple, but
using the current version 6.0 based on C#, I can't figure it out.

All I need is a simple scanner that tells me every stock in a watch list that has
increased or decreased in value by 0.7% from yesterday close to today's close.


Is there a way to do this with the new system?

I tried to translate an old pascal based script, and that didn't work, and then I tried
to use the drag&drop system, using the price based conditions, but that didn't work.

Help!

I gotta think that this would be really simple, but I just don't get C#.

Pascal is intuitive, but C# seems to be anti-intuitive to me anyway.

regards,
Dan
profile picture

Eugene

#20
Re: "anti-intuitive"

C# was designed by the man behind Delphi (read: Object Pascal), and it's undoubtedly the most natural choice for transition from Pascal. Start by this FAQ and you'll quickly see that your first impression was far from truth: I'm a Wealth-Lab 3/4 user, how to learn C# ?

Here's a screener for identifying the symbols that increased by 0.7% (configurable, see Strategy Parameters) or decreased by -0.7%:
CODE:
Please log in to see this code.
profile picture

denoving

#21
Hello Eugene:

First of all thank you very much for your efforts!

I didn't mean to disrespect C#, I was just being honest with my
expression of frustration. I'm sure after I use this tool for a while
I'll come around to appreciating it's power and elegance.

But for now it's really a struggle for me to even intuit much.

So that makes it especially hard for a newby like me.

Having used pascal for the last 32years as well as PLM, Basic, C, assy, fortran,
and COBOL, it's just not as intuitive to ME as any of those languages.

Probably it's my lack of exposure to the "object orientation" of that language
that is causing my confusion.

Nonetheless, it is what it is, and I need to learn.

Thanks for the code. I copied it, and when I pasted it it ended up all on one
line. so I had to go through and manually reformat it. Ug.

On the line....

ParamChange = CreateParameter("% Change", 0.7, 0.1, 5.0, 0.1);

I get that the 0.7 is the percent change sought.
But what are the other 3 numbers that follow (e.g. 0.1, 5.0, 0.1) ?

regards,
Dan
profile picture

Eugene

#22
Dan,
QUOTE:
I copied it, and when I pasted it it ended up all on one line.

You're using Internet Explorer, and probably an outdated one. Paste in Wordpard, copy again, paste in Wealth-Lab. Alternatively, copying from any other browser is fine.
QUOTE:
But what are the other 3 numbers that follow (e.g. 0.1, 5.0, 0.1) ?

You'll find the answer to this question (and other basic question) in the WealthScript Programming Guide.
profile picture

denoving

#23
Eugene:

I'll look that up in the programming guide.

Thanks again.

One other question...

If I wanted to change the scanner to look for the closing price of 2 days ago vs. today instead of
the closing price of 1 day ago vs. today, what code would I change?

I tried to change

int bar = Bars.Count - 1;
if (bar < 2) return;

to

int bar = Bars.Count - 2;
if (bar < 3) return;

but that didn't do what I was expecting it to do.

maybe it should be

int bar = Bars.Count - 2;
if (bar < 2) return;

I'll try that. If I'm on the wrong track, please at least
point me in the right direction.

Thanks.

Regards,
Dan
profile picture

Eugene

#24
CODE:
Please log in to see this code.

This should not be altered...
CODE:
Please log in to see this code.

...and this line is there to guard against loading too few bars of data.

Simply change this:
CODE:
Please log in to see this code.

To:
CODE:
Please log in to see this code.
profile picture

denoving

#25
Thanks Eugene.

That works pretty good, but after running some scans I notice that if I use a large net,
I get some stocks that are very low in price or volume.

Is there a way to be certain that for example the scanner will only buy stocks with a 10 day MA of 30,000 shares volume traded per day or more, and price of greater than a daybar low of $4.00 per share?

I think i need to reread the C# book so I can intuit some of these things myself.

I read the code and I just can't mentally visualize how things work. It's hard for me to
know how to create code when I can't visually understand it.

regards,
Dan
profile picture

Eugene

#26
Here you go:
CODE:
Please log in to see this code.
profile picture

denoving

#27
Eugene:

Thank you. That works really well.

There is just one final feature that I would like.

In addition to the features you have already added, I would like the scanner to identify:

>> all stocks whose 1 year linear regression line has a positive slope, and
>> that are priced at least 2.5% below the 3-month linear regression line, and
>> that are priced at least 1.5% below the average for the trailing 20days.

Thank you for your help.

regards,
Dan
profile picture

Eugene

#28
I'm guilty for letting your query break in this unrelated thread by a different topic starter but since you mentioned "final", let's do close this topic:
CODE:
Please log in to see this code.
profile picture

denoving

#29
Eugene:

I'm sorry, I read the topic as "pattern scanner", and since my questions are about pattern scanners, I thought this was the right place to ask the question.

Please let me know where I should ask any further questions should any arise on this topic, or for that matter if I should start developing other kinds of strategies.

Regards,
Dan
profile picture

Eugene

#30
Dan,

I did not want to sound like you were making a mistake - it's my bad. I should have promptly renamed this thread as "Divergence pattern scanner" and asked you to start a dedicated one for developing your own, unrelated screen. A variation of a divergence screen would fit here perfectly, but if we plant all kinds of pattern scanners here, we'd end up with a gigantic thread hard to navigate. Anyway, no problem here. Please just consider this aspect when targeting your questions in both new or existing topics should new ideas arise.
profile picture

Eugene

#31
Let's rename this thread - it's now dedicated to scanning for Divergence patterns.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).