MQL4 - automated forex trading   /  

Forum

How to get the angle of a moving average?

Back to topics list  | 1 2 3 To post a new topic, please log in or register

avatar
6
aspdeveloper 2007.02.13 17:40 
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.
Displaying of Support/Resistance Levels

Displaying of Support/Resistance Levels

The article deals with detecting and indicating Support/Resistance Levels in the MetaTrader 4 program. The convenient and universal indicator is based on a simple algorithm. The article also tackles such a useful topic as creation of a simple indicator that can display results from different timeframes in one workspace.


avatar
19
JosTheelen 2007.02.13 19:42 
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.

avatar
6
aspdeveloper 2007.02.14 01:02 
Thanks for the suggestion!!! Sounds good ... in fact, I already have something working! But it needs a little tweaking ...

Greetingz,
Koen.

avatar
Moderator
33759
Rosh 2007.02.14 11:05 
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.

avatar
1631
DxdCn 2007.04.05 04:02 
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

avatar
9
wheel_of_fire 2007.04.05 17:38 
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.

avatar
Moderator
33759
Rosh 2007.04.05 17:42 
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.



avatar
9
wheel_of_fire 2007.04.05 17:56 
Thanks, Rosh.

avatar
Moderator
33759
Rosh 2007.04.05 18:51 
You're welcome.

avatar
1631
DxdCn 2007.04.06 10:52 
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.

avatar
9
wheel_of_fire 2007.04.11 21:17 
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
Back to topics list   | 1 2 3  

To add comments, please log in or register