Calculating the Slope of iMA

 

Hey,

im trying to get the Slope of an iMA in percent.
I have read multiple posts here but non of them seem to work or im missing out on something (probably last option)
I think it doesnt have to do with my code structure, but my math.

Heres my code in the OnTick function:

   double array_ima50[],array_ima100[],array_ima150[];
   ArraySetAsSeries(array_ima50, true);
   ArraySetAsSeries(array_ima100, true);
   ArraySetAsSeries(array_ima150, true);

   int start_pos=0,count=6;

   if(CopyBuffer(handle_iMA50,0,0,count,array_ima50)!=count)
      return;
   if(CopyBuffer(handle_iMA100,0,0,count,array_ima100)!=count)
      return;
   if(CopyBuffer(handle_iMA150,0,0,count,array_ima150)!=count)
      return;
   
  if (array_ima50[0] < array_ima100[0]){
  if (array_ima100[0] < array_ima150[0]){
  signal = "SELL";
  } 
  }
  if (array_ima50[0] > array_ima100[0]) { 
  if (array_ima100[0] > array_ima150[0]) {
  signal = "BUY";
  }
  }
  double slope50 = array_ima50[5] - array_ima50[0] / count;
  double slope100 = array_ima100[5] - array_ima100[0] / count;
  double slope150 = array_ima150[5] - array_ima150[0] / count;
  Comment("iMA50: " + array_ima50[0]
   + "\niMA100: " + array_ima100[0]
   + "\niMA150: " + array_ima150[0]
   + "\niMA50Slope: " + slope50
   + "\niMA100Slope: " + slope100
   + "\niMA150Slope: " + slope150
   +"\nSignal: " + signal);

Thanks in advance.

 
iSDK: im trying to get the Slope of an iMA in percent.

Where in your code to you convert slope to percent?

Slope is: m=ΔPrice÷ΔTime.

Percent would be: 100 × m ÷ Price.

 
William Roeder:

Where in your code to you convert slope to percent?

Slope is: m=ΔPrice÷ΔTime.

Percent would be: 100 × m ÷ Price.

I messed up, sorry.

You are right, i there is no part, where the decimal number is converted to percent.

i didnt meant percent, but the angle in degree.

Still any ideas ?

 
iSDK: i didnt meant percent, but the angle in degree.
Can't be done.
  1. There is no angle from 2 anchor points. An angle requires distance divided by distance; a unit-less number. A chart has price and time. What is the angle of going 30 miles in 45 minutes? Meaningless!

  2. You can get the slope from a trendline: m=ΔPrice÷ΔTime. Changing the price scale, bar width, or window size, changes the apparent angle, the slope is constant. Angle is meaningless.

  3. You can create an angled line using one point and setting the angle (Object Properties - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference.) The line is drawn that angle in pixels. Changing the axes scales does NOT change the angle (and thus is meaningless.)

  4. If you insist, take the two price/time coordinates, convert them to pixel coordinates and then to apparent angle with arctan.
              How to get the angle of a trendline and place a text object to it? - Trend Indicators - MQL4 programming forum - Page 2

 
iSDK:

Hey,

im trying to get the Slope of an iMA in percent.
I have read multiple posts here but non of them seem to work or im missing out on something (probably last option)
I think it doesnt have to do with my code structure, but my math.

Heres my code in the OnTick function:

Thanks in advance.

I believe mathematically you cannot have percentage in slope unless you know what your 100% is, or you want to check the increase or decrease of slope. This means, you must have a reference slope. But now the slope of iMA is the the difference between two values of the same iMA, ie. ima50[n1] and ima50[n2]. There in no need to divide iMA by count as slope is a price already divided by time which is int ma_period. If you want a slope of 6 bars then multiply your current  int ma_period by 6.

This is just my understanding.

 
iSDK #:

I messed up, sorry.

You are right, i there is no part, where the decimal number is converted to percent.

i didnt meant percent, but the angle in degree.

Still any ideas ?

Even with this one, you do not need an angle in  degree.  Just a diffence on ima50[0] and ima50[1] can tell how the slope is. The more the difference the more the angle, the lesser the difference the lesser the angle.
Reason: