Zahorchak measure
Author: WEALTHPRO25
Creation Date: 4/22/2019 1:35 AM
profile picture

WEALTHPRO25

#1
stock charts has this Zahorchak indicator !BINYZM2DW can we possibly get this as one of our indicators in wealth lab pro, thank you greatly appreciated thank you. perhaps in the next update.
profile picture

Eugene

#2
Let me see how best to handle it: as do-it-yourself or a new IndexDefinition. Stay tuned.
profile picture

Eugene

#3
So I've reviewed everything re: Zahorchak measure I could get my hands on:

https://stockcharts.com/articles/dancing/2015/07/zahorchak-measure.html
https://stockcharts.com/articles/dancing/2015/09/zahorchak-measure-ii.html
https://stockcharts.com/articles/dancing/2017/11/zahorchak-revisited.html
"The Complete Guide to Market Breadth Indicators" by Gregory Morris

The design of Index-Lab doesn't make it easy to refer to external symbols and the method depends on it. For this reason a new IndexDefinition is not considered, only a script-based solution.

Prerequisites:

1. You will have to create and update two DataSets: one with .NYA in it and another with all NYSE stocks (let's call it "NYSE"). If not interested in the broad market you may substitute it with your own symbol universe. The power of Index-Lab gives you such flexibility.

2. Use the built-in "Advancing -- Declining" IndexDefinition in Wealth-Lab's Index-Lab tool to create the %AD_NYSE index (or the index of your choice). If unsure how to use I-L please see to the Wealth-Lab User Guide (Help menu) > Index-Lab® > Custom Indexes.

There's much ambiguity in the articles and the book regarding the exact formula which reflects in the different readings of the index. Variations of its on some charts range from -15 (bearish) to +15 (bullish) while the other and the book's are -10/+10. But the logic of it is that the indicator rises or falls based on the sum of all its components.

My understanding is that we add (subtract) a point whenever an X-week average of the NYSE Composite Index rises above (falls under) an Y-week moving average. Next do the same for the NYSE Advance Decline Line. It's confusing how Greg Morris says in one of the articles that "There are also a few relationships between the Advance Decline line averages and the NYSE Composite averages that contribute to the measure." But how does it do that exactly?

Anyway, now the sample code is all yours. See WL User Guide > Index-Lab® > Using Indexes on how to refer to the index in your Strategy:

CODE:
Please log in to see this code.


The indicator readings will not match StockCharts (below) but you have the idea what to do. Fine tune the code until the indicator's values look meaningful. It's up to you now!

profile picture

WEALTHPRO25

#4
thank you
profile picture

WEALTHPRO25

#5
when i use symbol .NYA it works, but when i use the symbol %AD_NYSE i get run time error, please help , thank you
profile picture

Eugene

#6
Try searching our Knowledge Base (the Wiki) yourself first, I'm sure you'll find the answer here: Errors | Strategy under "Value cannot be null".
profile picture

superticker

#7
Perhaps I'm missing something (I didn't read the Zahorchak articles.), but I see the two lines of code below as unconditionally incrementing cnt by one regardless of the values of nyc5[bar] and nyc15[bar] (unless they are exactly equal). Is this intended or is there a typo? Is the intent to include one of these lines and comment out the other?
CODE:
Please log in to see this code.

Based on the explanation of the run-time error (given in the above link), the posted code is already calling out the DataSet name of the %AD_NYSE index (see code below), so there shouldn't be a run-time error in the first place since the suggested fix is already present (unless an Index-Lab time frame other than "Daily" is being used).
CODE:
Please log in to see this code.

Disclaimer: I haven't tried running this code. I'm just making casual observations.
profile picture

Eugene

#8
Thanks Mark. Looks like this indeed gives more weight to the condition as the MA5/MA15 rule is mutually exclusive (unless the value is equal as you point out). Let's have it excluded then:

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

superticker

#9
Thanks for the update. I can follow the new code better. You could write the lines below ...
CODE:
Please log in to see this code.

as ...
CODE:
Please log in to see this code.

without sacrificing readability. The only shortcoming with this simplified solution is that cnt will be decremented when nyc[5] == nyc[15], and such, but that only happens when all 23 decimal places (double precision) of both number are exactly equal, which is rare.

You could reduce it even further with nested if...else statements, but you would loose readability.
profile picture

Eugene

#10
Sure. Just wanted to make it easier to match against the article for the user to comprehend.
profile picture

scrungy_doolittle

#11
O.K.
I have been aware of the zahorchak system since the 70's and have always wanted to implement it. I have the book,
The art of low risk investing.
Years ago, I started a basic program, I will share the comments here. These are from my analysis of the book back in 1980 when
I started writing the program. I did not have access to databases of stocks, so I created data statements in Basic to try to test the code.

These are the "other relationships" you are looking for.
There are two sets of rules, one for the DJI and one for individual stock purchases. The DJI stuff times the overall market,
My rambling comments Timing a bull market:

5wk DJI will turn up.Signals strong rally in a bear, or later will be a bull. Buy if you are aggressive and don't mind selling in a little while.
5wk goes above the 40 wk Buy strong stocks, very good chance of a bull
15wk A/D turns up, buy according to the following (ideally, the stock has completed a bottoming formation and the
15 wk has moved above the 40 week. we have a fully confirmed bull. Once you buy as stock, you switch to the stock rules below


Rules for the DJI X is a don't care DN is DOWN
5 wk 15 wk 40wk A/D Action
-----------------------------------------------------------
x >40wk UP UP Stay fully invested
x <40wk UP UP Uncertain, avoid new purchases
x >40 wk UP DN Uncertain, avoid new purchases
x <40wk UP DN Avoid new purchases
<40wk <40wk DN DN Avoid new purchases
>40wk <40wk DN DN BUY rally or leg of bull
>40wk <40wk DN UP Second sign of bull, the A/D is the tipoff
>40wk >40wk DN UP Buy aggressively, new bull.


Rules for buying and selling individual stocks.
AS long as the 15 week DJI average continues to be above the 40 week average, and
as long as the 15 week A/D average continues to move in an upward trend.
1. Ideally, the stock should be one that is making or
has just completed a bottoming formation. The 4 week average price has just moved above the 40 week price, and the 15 week line
is moving rapidly toward the 40 week line.
2. Alternatively, look for stocks that have previously given buy signals, and reached a price point between the 15wk and 40wk (the ideal
buying area). Look for stocks selling close to the 40wk line for the least risky stocks.
3. An initial purchase can be made when the short term (5 wk) line crosses the 40wk line. After this point, always wait for stocks to get to the ideal buying range.
In summary: Do not make an initial commitment in a bull market until the 5 week averages rises above the 40 week average. If you don't buy at this time, wait for the stock to drop down to the "ideal" buying range, below the 40 week and above the 15 week.


5 wk 15 wk 40wk
---------------------------------------------------------
>40wk >40wk UP HOLD regardless of the general market
<15wk >40wk UP HOLD if bear SELL if bull
<40wk >40wk UP HOLD
>40wk <40wk DN BUY if bull, AVOID if bear
x >40wk x BUY if bull
<40wk <40wk DN AVOID regardless of bear or bull

Selling when the primary trend is up:
After purchase during a bull, hold as long as the 15 week price remains above the 40wk price. When the 15 drops below the 40, the stock should be sold, as soon as the stock rises to it's ideal SELLING range ( price is between the 15 week average and the 40 wk. The secondary selling range is between the 5wk and the 15 wk prices.
SUMMARY:
A drop of the 15wk price below the 40wk price tells you that holding the stock is a high risk. A conservative investor will sell at the earliest opportunity.

Timing the sale when the trend is down or uncertain:
When the 15 wk A/D line is dropping but the 15wk DJI is still above it's 40wk average, the stock should be held as long as it's 15 week average remains above it's 40 wk average. Then sell on the first rally into the range between the 5 wk and 40 week. i.e sell on the first small rally that comes along. If the primary trend of the market is down and the 15wk DJI is below the 40wk, sell out each position as soon as the 5 week line of each stock falls below the 15wk average. Do not wait for it to drop all the way below the 40 week or any rallies to set in.
profile picture

scrungy_doolittle

#12
While I don't have a subscription to the wealth lab, I would love to. Right now, I use fidelty active trader pro and it does all the graphing, other than the A/D line.
To compute the A/D line:
It is necessary to start at an arbitrary number, say 20,000 because the line can go negative.
Advances - Decline + 20,000=new value
for the next 15 weeks,:
new value + (Advances - Declines).
Then you take the rolling average of that set of data, going forward, and updating new value each week.

If the A/D falls into negative territory, you can simply add 10,000 to all of the data points. The absolute value of the A/D line is not the critical part, it is the trend of the moving average that matters.

profile picture

Eugene

#13
The Advance/Decline Line is a built-in IndexDefinition in Wealth-Lab's Index-Lab. It's easy to build it for any custom portfolio (DataSet) or the whole universe of stocks.
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).