Attention Trigonometry people!

 

What is wrong with the following code? I'm not getting any values back.

#property copyright "Copyright © 2010, Nondisclosure007"
#property link      "http://no.link.yet"
#property indicator_chart_window
#property indicator_buffers 2

double floor[];
double ceiling[];
int init()
  {
   IndicatorBuffers(2);
   IndicatorDigits(Digits);   
   SetIndexBuffer(0,floor);   
   SetIndexLabel(0,"Lower Angle");
   SetIndexBuffer(1,ceiling);
   SetIndexLabel(1,"Upper Angle");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int i, k, limit, counted_bars=IndicatorCounted();
   limit = Bars-counted_bars-1; 
   double varLowMACurrent, varLowMALast, varHighMALast, varHighMACurrent;
   datetime varTime;
   for(i=0; i<limit; i++)
   {
      varLowMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+1);
      varLowMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+2);
      varHighMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+1);
      varHighMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+2);
      floor[i]=MathArctan(MathTan(((varLowMALast-varLowMACurrent)/(WindowPriceMax()- WindowPriceMin()))/((1)/WindowBarsPerChart())))*180/3.14;
      ceiling[i]=MathArctan(MathTan(((varHighMALast-varHighMACurrent)/(WindowPriceMax()- WindowPriceMin()))/((1)/WindowBarsPerChart())))*180/3.14;
   }
   return(0);
  }
//+------------------------------------------------------------------+
 
Try changing the amount of buffers to 6... and you need to declare & use your other calculating buffers as arrays
int init()
  {
   IndicatorBuffers(6);
   IndicatorDigits(Digits);   
   SetIndexBuffer(0,floor);   
   SetIndexLabel(0,"Lower Angle");
   SetIndexBuffer(1,ceiling);
   SetIndexLabel(1,"Upper Angle");
   return(0);
  }

double varLowMACurrent[], varLowMALast[], varHighMACurrent[], varHighMALast[]
 
cameofx wrote >>

Try changing the amount of buffers to 6... and you need to declare & use your other calculating buffers as arrays


Thanks, but that didn't do it. I changed '1' to '1.0. I've got numbers now, I just don't have anything accurate to the actual angles if I were to actually draw them on the screen.
 
nd, this is off the top of my head

- Since you're using incrementing loop
for(i=0; i<limit; i++)
the shift in iMA for past bars need to be i - 1 and i - 2
- Try to call and normalize WindowsPriceMax() and WindowsPriceMin() outside the iMA functions
 
#property copyright "Copyright © 2010, Nondisclosure007"
#property link      "http://no.link.yet"
#property indicator_separate_window
#property indicator_buffers 2

double floor[];
double ceiling[];
int init()
  {
   IndicatorBuffers(2);
   IndicatorDigits(Digits);   
   SetIndexBuffer(0,floor);   
   SetIndexLabel(0,"Lower Angle");
   SetIndexBuffer(1,ceiling);
   SetIndexLabel(1,"Upper Angle");
   return(0);
  }
int deinit()
  {
   return(0);
  }
int start()
  {
   int i, k, limit, counted_bars=IndicatorCounted();
   limit = Bars-counted_bars-1; 
   double varLowMACurrent, varLowMALast, varHighMALast, varHighMACurrent;
   datetime varTime;
   double winbc=WindowBarsPerChart();
   for(i=0; i<limit; i++)
   {
      varLowMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+1);
      varLowMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_LOW,i+2);
      varHighMACurrent=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+1);
      varHighMALast=iMA(NULL,0,34,0,MODE_EMA,PRICE_HIGH,i+2);
      floor[i]=MathArctan(MathTan(((varLowMALast-varLowMACurrent)/(WindowPriceMax()- WindowPriceMin()))/((1)/winbc)))*180/3.14;
      ceiling[i]=MathArctan(MathTan(((varHighMALast-varHighMACurrent)/(WindowPriceMax()- WindowPriceMin()))/((1)/winbc)))*180/3.14;
      if(i<10) Print("ceiling:",ceiling[i],",floor:",floor[i]);
   }

   return(0);
  }
//+----------------
This worked for me.
Not sure if you were aiming for a separate window or not. The result values implied that you were.
Watch out for int's in double calculations.
Also, your lines are going to default to black, so if you have a black BG, you won't see them.
 
cameofx wrote >>
nd, this is off the top of my head

- Since you're using incrementing loop
the shift in iMA for past bars need to be i - 1 and i - 2
- Try to call and normalize WindowsPriceMax() and WindowsPriceMin() outside the iMA functions


Not quite sure what I should do w/ the data that pricemin and pricemax return though.
 
circlesquares wrote >>
This worked for me.
Not sure if you were aiming for a separate window or not. The result values implied that you were.
Watch out for int's in double calculations.
Also, your lines are going to default to black, so if you have a black BG, you won't see them.


Once I changed '1' to 1.0, I got values. But they weren't accurate. They weren't even close to the actual angle.

I'm guessing that although when you 'draw' manually the trendline by angle by setting the 2 time and price coordinate, it must figure out what the angle is based on pixels and not price/time.
 

The angles you get and what you see can be different.

Duh! It depends on size of monitor, how you size the application window, how you zoom it, etc....

I use angles before BUT it is not effective because it cannot predict the future angle/movement.

 
I think see what you were trying now. I would say that angles have no place on price charts though. It's been discussed on these forums before if you want to see others experience.
What you can do instead is maybe deal with slopes/rate of change if you're looking to compare or analyze segments.
For example, 20 pips per bar is a measurement that fits price charts well.
 
cameofx:

Try changing the amount of buffers to 6... and you need to declare & use your other calculating buffers as arrays

Those intermediate values are never referred to in the past, so no need for additional buffers.


Angles have no place on price charts. Angle is delta y/delta x. But price charts are price vs time. Angle makes no sense. Slope on the other hand does.

 
WHRoeder:

Those intermediate values are never referred to in the past, so no need for additional buffers.

Angles have no place on price charts. Angle is delta y/delta x. But price charts are price vs time. Angle makes no sense. Slope on the other hand does.

WHRoeder, you're correct that's a once-off calculation. no need for buffers there... thank you


as far as angle, let me see if I can get this correctly :

- delta y / delta x (rise / run), will get you tangent ratio

- to get the degree of slope you must put that ratio back with MathArcTan() - and convert its value from radians to degree.

thus angleDegree = MathArctan( tangent )/ 3.1415965 * 180;


nd,

- Using WindowsPriceMax and WindowsPriceMin has occured to me also. But that meant that you want your indicator to calculate conversion each

time you zoom in/out, scroll windows, etc. There's no way to call that event yet, afaik.

- Angles apply in 1:1 fix chart (set options in F8) so you don't need to see 30 degree angle corresponds visually. You only need to compare it relatively

with other angle values. if the value of older Bar1 - Bar2 is, for example : 28,3 degree ; and newer Bar3 - Bar4 : 40.2 degree
than we have ourselves an inclination in degree. etc... another way of putting it : you won't see a 45 degree angle in chart as you know how a 45 degree should look like.
But you will see it is 45 degrees in comparison with it's neighbouring 23 and 51 degrees values for example...

edited : rise / run cannot be exchanged, tangent = opposite (rise) / adjacent (run);
Reason: