Experiments in Technical Analysis

kkseal

Well-Known Member
hI,
Good knowledge sharing for the learners like me. Thanks for that. Actually I was trying to make A/D (Larry williams) line in metastock but it is giving error of division by zero error. Please help in removing this error.

I am writing metastock coding here.
If(H-L<>0 AND C-O<>0,
If(C-O>0,PREV + PREC(((CLOSE-OPEN)/(HIGH-LOW)),2 ) * (VOLUME/10),
PREV - PREC(((CLOSE-OPEN)/(HIGH-LOW)),2 ) * (VOLUME/10)),
0)

But As I said I am getting division by zero error.

Please help me in clearing this error.

If any body has used A/D flow line of Larry williams then please tell me about the result as I am planning to use this in my trading.

Ashvin
Please refer my posts

#679 on pg 68
&
#662 on pg 67

in that order.

I think you'll be able to figure it out yourself.
BTW i'm not much of an expert in FLs.

Regards,
Kalyan.
 
Hi,
Thanks for your reply,

Actually I have gone thru your posts but I am still not able to find answer of my problem,

Plese help, actually I am getting the division by zero error while in your post u have not used any division formula and accumlation and distribution formula i am looking is ((CLOSE-OPEN) / (HIGH-LOW)) * VOLUME.

Please help if any body have any idea.

Thanks,

Ashvin

Please refer my posts

#679 on pg 68
&
#662 on pg 67

in that order.

I think you'll be able to figure it out yourself.
BTW i'm not much of an expert in FLs.

Regards,
Kalyan.
 

kkseal

Well-Known Member
hI,
Good knowledge sharing for the learners like me. Thanks for that. Actually I was trying to make A/D (Larry williams) line in metastock but it is giving error of division by zero error. Please help in removing this error.

I am writing metastock coding here.
If(H-L<>0 AND C-O<>0,
If(C-O>0,PREV + PREC(((CLOSE-OPEN)/(HIGH-LOW)),2 ) * (VOLUME/10),
PREV - PREC(((CLOSE-OPEN)/(HIGH-LOW)),2 ) * (VOLUME/10)),
0)

But As I said I am getting division by zero error.

Ashvin
The problem may arise from the Data Array type parameter used by the PREC function. Have you tried without the function? You can also try the 'lastvalue' function i.e. prec(lastvalue((C-O)/(H-L)),2) Better would be, first assign the result of the calculation to a variable (say AD) and then apply the PREC (or ROUND) function on AD.
 
Last edited:
Hi,
Thanks for your suggestion, Actually I tried with both the options u have given(using last value function and assigning variable to result) but still that error continues. Then I have calculated the value manually in excell and matched with metastock and found that values displayed by metastock is correct even when error is coming.
SO what I think is when we use IF function it calcultes both the options (that's why it is giving error) but display the result according to the expression result in IF function.

This is wht I understand if anybody has a similiar kind of experience please privide the input.

Ashvin

The problem may arise from the Data Array type parameter used by the PREC function. Have you tried without the function? You can also try the 'lastvalue' function i.e. prec(lastvalue((C-O)/(H-L)),2) Better would be, first assign the result of the calculation to a variable (say AD) and then apply the PREC (or ROUND) function on AD.
 

kkseal

Well-Known Member
Hi,
Thanks for your suggestion, Actually I tried with both the options u have given(using last value function and assigning variable to result) but still that error continues. Then I have calculated the value manually in excell and matched with metastock and found that values displayed by metastock is correct even when error is coming.
SO what I think is when we use IF function it calcultes both the options (that's why it is giving error) but display the result according to the expression result in IF function.

This is wht I understand if anybody has a similiar kind of experience please privide the input.

Ashvin
You must also be careful while using the PREV function; in your code it is not clear what PREV is referencing. Your intention is clear enough - you want to reference the previous value of A/D but the question is - is it equally clear to the program? :)
And if it does try to calculate the previous value it will do so bypassing the condition of H-L <> 0 and in the process generate the error.

I think a simpler way to do it would be to use the following code

Cum(If(H-L<>0, (C-O)/(H-L) * V/10, 0))

This will produce a cumulative total (which in fact is the A/D) for each of the bars loaded.

If this works, then you can add the PREC (though i prefer ROUND) as follows

PREC(Cum(If(H-L<>0, (C-O)/(H-L) * (V/10), 0)),2)

If it doesn't work then PM Oxy :)

Regards,
Kalyan.
 
Last edited:

asnavale

Well-Known Member
Dear Ashvin,

I am giving the Larry Williams' Acc/Disr formula as AmiBroker AFL here. You may try to write the Meta Stock code from this.

I am quoting here what Larry Williams has written in his book "The Secret of Selecting Stocks for Immediate and Substantial Gains", published by Windsor Books, Brightwaters, New York. This book is available as e-book.

... there is a battle ... every day on the floor of the Exchange between buyers and sellers in each stock.... The battle between the buyers and sellers ends each day with the final bell. Someone has won that round. The next day it is a new battle, but at the end of each day we can sit back and see who was the winner.
.... the daily high for the stock is established by the bulls. The distance from the morning's open to the daily high shows the power of the bulls. ... The Bears show their daily power by driving prices down. Hence, the distance from morning's opening to the low point represents their pressures, or the amount of selling.
.... accumulation and distribution is calculated by finding the difference between the stock's high and low for the day. We then find the difference between close and open. ... The next step is to divide the close-to-open distance by the high-to-low distance. This resulting figure is percentage of net buying or selling for the day.
....
In a concise form the equation is this: Close minus the opening, divided by the high minus the low times volume = net buying or selling for the day (net daily A/D). ... On the days when there is more buying the net daily A/D figure is added to yesterday's figure. On days of more selling the net daily A/D figure is subtracted from yesterday's figure.
Based on my understanding of the above I have written the Accumulation/Distribution AFL for AmiBroker as follows:
Code:
DR = H-L;		//Day's Range
DC = C-O;		//Day's Change
 F = 0;		        //Factor to calculate Acc/Dist. Initialised with zero.
WAD = 0;		        //William's Acc/Distr Value. Initialised with zero.

If(H[0] == L[0])	//In case first day's Hi and Lo are same
   F[0] = 1;            //Factor is taken as 1.         
else                    //Otherwise
F[0]=DC[0]/DR[0];	//Calculate the ratio and assign it to factor for first day.

WAD[0]=V[0]*F[0];	//First day's Acc.Dist 
	
for (i=1;i<BarCount;i++)	//For second day onwards
{
	
	if (H[i]==L[i] AND O[i]<C[i-1]) F[i]=-1;	//Lower circuit
	else
	if (H[i]==L[i] AND O[i]==C[i-1]) F[i]=F[i-1];	//Very rare case
	else
	if (H[i]==L[i] AND O[i]>C[i-1]) F[i]=1;		//Upper circuit
	else
		F[i]=DC[i]/DR[i];			//Normal case
		WAD[i]=V[i]*F[i]
}

Plot(Cum(WAD),"AccDist",colorRed,styleOwnScale+styleLine);
A few points explained:

1. When Volume is large number, say in lakhs, then divide the volume by a suitable number such as 1000 so that you get a smaller number which is easy to manage. The final A/D graph is not affected by this division.
2. When the stock is locked in lower circuit throughout the day, the High and Low are same and the Open would be lower than previous Close. In this case the factor F is taken as -1.
3. When the stock is locked in upper circuit throughout the day, the High and Low are same and the Open would be higher than previous Close. In this case the factor F is taken as 1.
4. In very rare cases the stock opens at previous Close and High and Low are same. In this case the factor F is taken to be same as previous day's value.
5. In the last line, the plot function uses styleOwnScale because we don't want the A/D graph to distort the price chart when it is used as an indicator in the same graph.

If the above claculation steps are used you will never get 'Divide by zero' error. I hope this will help you overcome the problem you are facing. Unfortunately I am not in a position to write the AFL in MS code. I hope the explanations will help you write your own MS code. Or somebody else may be able to write it for you and help.

As far as the method of using this indicator and its interpretation, you may refer to the book mentioned above. The space is not sufficient to explain it here. I may have to write a separate post for that.

Regards

-Anant
 

Ajax

Well-Known Member
Hi all

I see lots of traders discussing whole lot of bull **** & getting confused.
Are u people academicians hoping to win Noble prize in TA or in the markets
to make money???

Price action & volume is the what one requires to trade. All indicators & fancy structures are just derivatives of these two basic parameters.

I am attaching a yearly chart of CMC which has broken out of ascending triangle with big bull candle >> target of 3600 & 2nd target ~ 22000/- ??

No fancy indicators / calculations / algorithms , just PLAIN SIMPLE PRICE ACTION. i GOT INTO THE STOCK @ Rs 700/- , AND ITS DONE 1300/- ALREADY IN LESS THAN A WEEK. i AM NOT SELLING AS YET.
( big profits with least amount of trades , of course it requires tonnes of patience),

regards

Ajax
 
Last edited:

kkseal

Well-Known Member
Hi all

I see lots of traders discussing whole lot of bull **** & getting confused.
Are u people academicians hoping to win Noble prize in TA or in the markets
to make money???

Price action & volume is the what one requires to trade. All indicators & fancy structures are just derivatives of these two basic parameters.

I am attaching a yearly chart of CMC which has broken out of ascending triangle with big bull candle >> target of 3600 & 2nd target ~ 22000/- ??

No fancy indicators / calculations / algorithms , just PLAIN SIMPLE PRICE ACTION. i GOT INTO THE STOCK @ Rs 700/- , AND ITS DONE 1300/- ALREADY IN LESS THAN A WEEK. i AM NOT SELLING AS YET.
( big profits with least amount of trades , of course it requires tonnes of patience),

regards

Ajax
You're in the wrong thread There's one on Pattern Trading where you ought to have posted your wonderful discovery. :rolleyes:

Kalyan.
 

Similar threads