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 (
SideWinder for CCI: My first release). 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.
Code:
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.