How to get the angle of a moving average?

 
Hi there,

How can I get the angle of a moving average which is plotted on a chart?

For example: I have 2 to 3 moving averages plotted on my charts. Based on the angle (f.e. 60 degrees) I have an indicator on how strong the current uptrend is.

Should I calculate the angle myself, based on the MA-values of the f.e. last 10 candles, or should I use the ObjectGet()-function? I tried the latter, but you have to specify a name, and since all my MA's have the same name (and I don't see how I can change them), there's nothing coming out ... (they're actually the same MA's, but based on close, high and low prices).

Any help would be very much appreciated! Thanks in advance.

Greetingz,
Koen.
 
The angle depends on how much time you have on the horizontal axis. Suppose your chart shows 2 days and you changes that to 1 day, the angle will become smaller. So I suggest you don't use an angle, but something like "average difference in pips per timeframe". That means: take the difference in value from MA1 and MA2 and divide it by the number of timeframes between the moment the MA's intersected and the moment you want the angle.
 
Thanks for the suggestion!!! Sounds good ... in fact, I already have something working! But it needs a little tweaking ...

Greetingz,
Koen.
 
You cannot measure a corner of an inclination of a straight line on the schedule because have different units - the Price and Time. It is possible to measure only similar with similar (like to like). In this case you try to measure a corner of an inclination of a straight line on the schedule, expressed through pixels. You can is authentic measure only speed of change of the price in terms of Point unit for a Time unit.
 
Gann Fan Lines of Gann Fan are built at different angles !!

MT can supply Angle function based on screen pixels (trans from two values and two times coodinates).
Since Angle is more good for people to watch.

Like:

MathArctan(MathTan(
((price1-price2)/(WindowPriceMax()- WindowPriceMin()))
/
((shift2-shift1)/WindowBarsPerChart())
))
*180/3.14
 
DxdCn,

I completely agree with you. Angles matter and they are used all the time.

I'm interested in the formula you posted. I've been getting the angle with the following formula:

(((MathArctan(line_slope/100))*(180/3.14159))*angle_factor);

Slope is calculated in another function. Angle_factor controls for the format of the yen. Anyway, it gets close but it's still not right.

When I put your formula instead, I get a divide by zero error in the strategy tester. Is this because the window functions don't work within the tester or did I do something wrong?

Peace.
 
Let see Testing Features and Limits in MetaTrader 4 and will view there

Special Features of Optimization Process

  • Nothing is output in the journal (either Print() function)

    This was done in order to accelerate the testing and save disk space. If complete logs are output the journal files will need hundreds of MByte.

  • Draw objects are not really set

    The objects are disabled in order to accelerate the testing.

  • "Skip useless results" function is used

    In order not to garble the table and chart with testing results, the possibility to skip very bad results is used. This function can be enabled in context menu of "Optimization Results" -> &quotSkip useless results" tab.

 
Thanks, Rosh.
 
You're welcome.
 
Note : based on screen pixels !!! dx,dy should be in same unit,best trans to screen pixels.

MathArctan(MathTan(
((price1-price2)/(WindowPriceMax()- WindowPriceMin()))
/
((shift2-shift1)/WindowBarsPerChart())
))
*180/3.14

divide by zero error ? check (shift2-shift1) should not equal ZERO before calculating.

I test them on newest version 203.
I do not test them when testing EA.
 
DxdCn,

I want to give you my deepest appreciation for the formula you shared. I didn't respond earlier because I had to finish getting my EA together. Works like a charm.

Peace and goodwill.--The Wheel of Fire