# Angle of a line

I want to compare the angle of lines drawn (between 2 points) in different charts of different instruments. I am aware of Tomasz post regarding anisotropic charts but if scaling and zoom level are equal for every chart then is it possible?
I mean there must be some way, Right? If I can see it then I should be able to determine it programmatically. Does not have to be perfect but must be COMPARABLE.

I tried something like this below but it is not comparable. It works in some instances and but not reliable.

// not reliable code
barDistancebeweenPt1Pt2 = baRef1 -barRef2;
PriceDifferenceBeweenPt1Pt2 = PriceP2 - PriceP1;
percentChangeInPriceBeweenPt1Pt2 = PriceDifferenceBeweenPt1Pt2 /PriceP1 * 100;

angle= percentChangeInPriceBeweenPt1Pt2/barDistancebeweenPt1Pt2 *100;

type or paste code here

As explained in other thread Need Help Gann Line - #2 by Tomasz :

There are no angles on price vs time charts

Angles can only exist if X and Y axis use same unit. Angle is arc tangent of Y/X ratio. For that calculation to make sense Y/X ratio must be unit-less.

1 Like

ok agreed. Let me ask my question in a different way. is there a way to compare the slope of the lines of below chart such that one can arrive at a determination that lineChart3>lineChart1>lineChart2. All three charts are of the same time frame and same zoom level (number of bars visible is equal)

The code in your original post does not calculate an "angle", but it does appear to calculate the average % Return per Bar between points 1 and 2, and it seems to me that such a value should achieve your stated goal. However, you said that it was "unreliable", so perhaps you need to post your complete code along with an example of it not working as desired.

Yes it does not give WYSWYG results. I want a code that can work like human eye. Anyone can tell by visual examination that angle of line in chart3 is greatest. I want code that can do the same thing.

To repeat: if you want help, you will need to post your code and examples of how it's not working as you want it to.

@AlgoEnthusiast I agree with @mradtke that you may get more helpful answers with complete code example (properly formatted for this forum) and perhaps more details on your methods.

If you are manually entering a line on the chart you can get information from the chart itself.

Programmatically there may be help for you in learning the LinRegSlope function, AFL Function Reference - LINREGSLOPE

And there may be some more help in the Official Knowledge Base if you are drawing your lines programmatically.

I suspect all you need for comparison purposes is the Rate-of-Change between the two points, so the built in indicator could solve that, `ROC( P, periods)` Good luck!

``````// not reliable code
barDistancebeweenPt1Pt2 = baRef1 -barRef2;
PriceDifferenceBeweenPt1Pt2 = PriceP2 - PriceP1;
percentChangeInPriceBeweenPt1Pt2 = PriceDifferenceBeweenPt1Pt2 /PriceP1 * 100;

angleOrSlopeOrWhatever= percentChangeInPriceBeweenPt1Pt2/barDistancebeweenPt1Pt2 *100;

``````

Well the code is as I posted in my original post. It sometimes fails to compare lines from different instruments. It returns greater values for angleOrSlopeOrWhatever , sometimes, for the lines that are visually flatter. Hence I am unable to rely on it.

Yes lines are drawn programmatically.

Thats what i thought But unfortunately that does NOT work. Visually things look different.

@AlgoEnthusiast yes, as I look at your charts I see you are comparing a different number of bars so a simple Rate-of-Change comparison is inadequate. But I would suggest debugging your code (my personal preference is to break down each variable in an Explore and confirm it is calculating what is intended).

The code that you posted will not run, because the variables baRef1 (should be barRef1, perhaps?), barRef2, PriceP1, PriceP2 are all UNDEFINED.

Also, saying something like this:

It sometimes fails to compare lines from different instruments.

Is entirely useless. Nobody here is going to keep experimenting with your code until they find a pair of instruments where your code breaks. You need to provide EXAMPLES. You should probably also review: How do I debug my formula?

2 Likes

@AlgoEnthusiast - Rate of change works. What you are missing is that on chart whenever line is flatter or not depends on zoom factor (both X and Y zoom factors). Rate of change on the other hand is giving you number (percentage rate of change over specified number of bars) that does NOT depend on zoom factors.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.