MA Angle Indicator help

 

I'm trying to create an indicator that is based on the angles of a few moving averages. I figured that since this has been done before that I'll start by recreating a previously made indicator to make sure I'm doing this correctly, then modify the code after that.

The indicator I chose to clone is the Sidewinder (https://www.mql5.com/en/forum/174836). The code for this indicator as I can understand it is by adding the angle (in degrees) of the LSMA25 and the EMA34 of a given chart. If the sum is greater than 100, the sidewinder is represented by a green block. If the sum is 75 to 100, it's yellow. Less than 75 is red.

Since the angle is simply the arctangent of the slope, and based on what I (think?) I remember reading something in the link above about the slope being taken only from the last two bars of the MA in the sidewinder. Since the slope is simply the change in the y-axis divided by the change in x-axis, I'm computing slope by subtracting the old bar's close from the new bar's close (and divide by one since it's only one timeframe apart, but that doesn't need to actually be computed since it doesn't affect the number). This gives me the slope of the MA. I then use the MathArctan() function with my newly-found slope value and that returns the angle of the slope in radians. A simply conversion (multiply by 180/pi) and we have the angle in degrees.

Unfortunately, I'm doing something wrong and can't figure out what the hell it is. It might be in the way I'm going about this (in which case the error could be found in the previous few paragraphs). It might be the way I'm implementing the code (which is found below). Any help or guidance would be greatly appreciated.

double lsma25 = LSMA(25,1);

double oldLsma = LSMA(25,2);

double slopeLsma = (lsma25/oldLsma)*1000;

double angleLsma = MathArctan(slopeLsma)*(180.0/3.14159);

double ema34 = iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE,1);

double oldEma = iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE,2);

double slopeEma = (ema34/oldEma)*1000;

double angleEma = MathArctan(slopeEma)*(180.0/3.14159);

double sidewinderValue = angleLsma + angleEma;

The function LSMA() takes two values, the number of periods and the shift from the current bar (it uses the Close of a bar). So, the function call "LSMA(25,1)" returns the 25-period LSMA with the final bar being the bar before the current bar (the final complete bar).

I don't know if I'm missing any important information, so if anyone needs any more information just post what you need and I'll get you what I can do. I really appreciate any help you guys can give me.

 

Did you finish your sidewinder indicator?

 

The slope would be obtained by subtraction and not division....

double lsma25 = LSMA(25,1);

double oldLsma = LSMA(25,2);

double slopeLsma = lsma25 - oldLsma;

etc. I'm not sure about the "angle", since that depends on aspect ratio. But slopeLsma in the above is the derivative or "direction" of the movement.

Personally I would look back a bit more than one bar, like 5 or 10 bars, in order to reduce the brittleness of the logic; the 1-bar delta tends to hover around 0 a bit when the line turns, whereas, say, the 10-bar delta moves more distinctly through 0. As you may know, with any N-bar delta, you find the actual turning point in middle between the pair where the delta changes sign.

 

Slope calculation

When you want to calculate the slope of the MA in the code you present, you divide instead of substracting. In my opinion the slope should be slope=lsma-oldlsma instead of slope=lsma/oldlsma

Try the calculation I propose and inform us.

mikelina

 

Change MA Angle Indicator

Hi all,

I'm looking for a kindly coder to change the attached MA angle indi.

What I would like is for the plotted histogram to change colour when the value is greater or lower then the previous bar, similar to MACD coloured, rather than just when the value is larger than the specified parameters.

I have looked at the code but I am quite frankly rubbish and while I can hack EA's indis are currently way beyond me. I think there was a previous request from another user for something similar but I could find anything on the site.

If is already exists please direct me in that direction. Any help gratefully received.

Thanks,

G-Man

Files:
 

have you thought about to search for the indicator instead

as it sound like AMA to me -- and you seems to have certain assumption in mind -- to make this code become useful to you-- and only if >> the market agree with your presumption

 

Keep in mind - pure angle in degrees (or radians) can be calculated to one dimension values (metre to metre for example). In Forex, Futures etc. we have relations Price to Time - that's NOT one dimension values!!!

Because relations Price to Time CAN"T be in pure degrees/radians.

 

if 2 persons post this indicator best SETTINGS -- during LIVE TRADING (please try it live before posting it)

and please comment on any repaint or retract issue of this indicator

my guess, there could be REPAINT or STEP BACK issue when the candle in 30M change direction slightly i.e U-turning with this indicator

then >>> I will post my settings here too !!

I think this indicator has to combine with range or envelop type of indicator to yield some VERY GOOD ENTRY or it got good CROSS potential [ cross of indicator could be the LATEST fashionable tools that people use in current market Candle pattern Scenario, so it has some potential , simple to tune too

 

lol you can't calculate an angle of price and time.

actually you can, but you need to specify how much price consists inside one x-axis bar :):):)

better use something like this.. dma.mq4

Files:
dma.mq4  2 kb
 
 

ok thank you for your reply, I tried your indicator but I do not quite agree.

Is ilpossible to calculate the angle with 2 or 3 prices

Reason: