Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 can create custom graphical tools?
vladi rozen
51
vladi rozen 2012.03.28 12:35 

hey everybody!

i would like to calc the angle of Moving Average 10.

i tried this:

double MAShift1 = iMA(NULL, 0, MA, 0, MODE_SMA, PRICE_CLOSE, 3);

double MAShift3 = iMA(NULL, 0, MA, 0, MODE_SMA, PRICE_CLOSE, 7);

double test = (SignalPeriod-0.0)/WindowBarsPerChart();

int angle = MathArctan(MathTan(((MAShift1-MAShift3)/(WindowPriceMax()- WindowPriceMin()))/((test-0.0)/WindowBarsPerChart())))*180/3.14;


it seem to be calculating wrong angles, i get answers without any sense,

i want to check whats the angle between 3 and 7 shifts back.

thanks.

Point Zero
794
Point Zero 2012.03.28 13:06  
VladiRozen:

hey everybody!

i would like to calc the angle of Moving Average 10.

i tried this:

double MAShift1 = iMA(NULL, 0, MA, 0, MODE_SMA, PRICE_CLOSE, 3);

double MAShift3 = iMA(NULL, 0, MA, 0, MODE_SMA, PRICE_CLOSE, 7);

double test = (SignalPeriod-0.0)/WindowBarsPerChart();

int angle = MathArctan(MathTan(((MAShift1-MAShift3)/(WindowPriceMax()- WindowPriceMin()))/((test-0.0)/WindowBarsPerChart())))*180/3.14;


it seem to be calculating wrong angles, i get answers without any sense,

i want to check whats the angle between 3 and 7 shifts back.

thanks.

Hello,

You can't properly calculate the angle of the moving average because that depends on the amplitude of the chart (how many bars are displayed in the chart) and therefore is a very disfunctional way to analize data. But you can calculate the variation of the moving average over time: if it is above 0, it means is rising. If not, is falling. Then, you can paint those in an bars indicator (sort like OsMA or Awesome) and get the information visually.

double variation = current_moving_average - last_moving_average;
if(variation > 0) Alert("Moving average rising"); else Alert("Moving average falling");
vladi rozen
51
vladi rozen 2012.03.28 15:11  
flaab:

Hello,

You can't properly calculate the angle of the moving average because that depends on the amplitude of the chart (how many bars are displayed in the chart) and therefore is a very disfunctional way to analize data. But you can calculate the variation of the moving average over time: if it is above 0, it means is rising. If not, is falling. Then, you can paint those in an bars indicator (sort like OsMA or Awesome) and get the information visually.


so you saying it only visual?

cant i calculate it logically?

Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2012.03.28 15:18  
VladiRozen:


so you saying it only visual?

cant i calculate it logically?

How can you possibly calculate an angle logically when one dimension is price and the other is time ? of course you can, but does it actually mean anything ? in effect it's the same but wouldn't it be more logical to calculate the rate of change of the MA ?
vladi rozen
51
vladi rozen 2012.04.04 13:20  

ok, lets leave logics aside,

Can please anybody can help with a code that calculating angles of ma's?

Simon Gniadkowski
Moderator
17994
Simon Gniadkowski 2012.04.04 13:23  
VladiRozen:

ok, lets leave logics aside,

LOL . . . if you want to leave logic aside then any garbage answer is as good as any other as they will all be logically wrong . . .
Ian Venner
2583
Ian Venner 2012.04.04 14:58  

you cant calculate a true angle for the reason Raptor said, you are dealing with price and time which are apples and oranges.

If the intent is just to guage strength of direction, you could make a simulation of an angle. You must first decide how many pips == 1 minute. That would be entirely up to your discretion as there is no real corrolation between pips and minutes you could invent one.

For example, you may decide 10 pips = 1 minute so if the price rises by ten pips in 1 minute that could be considered a 45 degree angle so 1 pips per minute = 4.5 degrees of "angle"

erzo
109
erzo 2012.04.04 18:28  

Not that stupidity, similar find here: http://www.forexfactory.com/showthread.php?t=76018.

Anyway:

double scalingFactorToBars = 1.0 / WindowSizeInBars;
double scalingFactorToPrice = 1.0 / winHight;
double xCoordinateFromScaledBars = LookBackBars * scalingFactorToBars;
double yCoordinateFromScaledPrice = (maNow - maLookBack) * scalingFactorToPrice;
double countedAngleInDegrees = (MathArctan(yCoordinateFromScaledPrice / xCoordinateFromScaledBars) / 3.14159265) * 180.0;
bruce_loco
19
bruce_loco 2012.04.17 13:50  

Well

This is a flawed approach to a visual/non visual problem.

An angle is not valid because the window is shaped according to the candles with the highest and lowest values, also if you distort the window, ie: zooming, the angle changes.

Also try to think: how can you calculate past angles? Based on the Max/Min price of the current window? What defines which candles are seen to choose max and min? not only bars per window but also where you are scrolling wise.

Try it.

The best way to review this(still crappy approach) is to use an ADR(average daily range) over lets say 5/10 Days. The angle will be relative to the recent action, plus adr is not calculated visually. For 5 days

Also you can just do a pip difference(adr is also usefull here). It is what I use for cross overs, I check cross over, but sometimes, there is 1-5 pips difference(equivalent to a small angle) between MA points and that can say whether I have a positive or negative trend.

5 day adr(add all 7 days, saturday does not matter as it will be 0, if you have gmt offsets, they will be caught by this anyway)

int day = 0;

double sum = 0;

for(day = 0; day < 7 ; day ++)

{

sum += iHigh(Symbol(), PERIOD_D1, day) - iLow(Symbol(), PERIOD_D1, day);

}

sum = sum/5;

PS: I'm not being arrogant, I just was playing around with this yesterday and I did not find a proper solution. If somebody knows a way I am all ears.

texto
32
texto 2012.04.17 14:25  
RaptorUK:
LOL . . . if you want to leave logic aside then any garbage answer is as good as any other as they will all be logically wrong . . .

LOL. Well said.

texto
32
texto 2012.04.17 14:33  
VladiRozen:


so you saying it only visual?

cant i calculate it logically?

As Raptor has already mentioned, a rate of change is appropriate for your requirements. Here is something you can do:

1. Find the difference between closing prices (say Bar 1 to Bar 3) and divide by point. This will give you no of Pips gained (or lost) between Bar1 and Bar 3.

2. Now divide the above value by chart Time Frame in minutes (for example PERIOD_M30 if it is a 30 min chart). The resulting value will be no of Pips gained or lost per min in 3 bars. You can further divide by 3 and get Pips/Minute/Bar.


Now you cans set a threshold for the calculated value and trade when it reaches the threshold. Is that clearer?

/ /12
To add comments, please log in or register