Download MetaTrader 5

Trendlinebyangle is completely useless

To add comments, please log in or register
Forex Trader
114269
Forex Trader  

This is an mql4 question.

So, let me get this straight; If draw a trendlinebyangle on the chart, I can only pull values off of the trendlinebyangle that I've already set? That's completely useless.

It doesn't matter how I draw the trendlinebyangle, I cant' get a value that I didn't set.

See code. I'm trying to get the angle by setting time1/price1 and time2/price2. My angle result is 0. If I set time1/price1, time2 and angle, I get 0 for price2 when I try to get it.

What gives MT?! Got an answer?, I hope.


#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");
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   ArraySetAsSeries(floor,true);
   ArraySetAsSeries(ceiling,true);
   return(0);
  }
int deinit()
  {
   ObjectDelete("LowerAngle");ObjectDelete("UpperAngle");
   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=limit; i>=0; 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);
      if (ObjectFind("LowerAngle")==-1)
         {ObjectCreate("LowerAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varLowMALast,Time[i+1],varLowMACurrent);}
      ObjectSet("LowerAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("LowerAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("LowerAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("LowerAngle",OBJPROP_PRICE1,varLowMALast);
      ObjectSet("LowerAngle",OBJPROP_PRICE2,varLowMACurrent);
      ObjectSet("LowerAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("LowerAngle",OBJPROP_RAY,true);      
      floor[i]=ObjectGet("LowerAngle",OBJPROP_ANGLE);
      if (ObjectFind("UpperAngle")==-1)
         {ObjectCreate("UpperAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varHighMALast,Time[i+1],varHighMACurrent);}
      ObjectSet("UpperAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("UpperAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("UpperAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("UpperAngle",OBJPROP_PRICE1,varHighMALast);
      ObjectSet("UpperAngle",OBJPROP_PRICE2,varHighMACurrent);
      ObjectSet("UpperAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("UpperAngle",OBJPROP_RAY,true);      
      ceiling[i]=ObjectGet("UpperAngle",OBJPROP_ANGLE);
      WindowRedraw();
   }
   return(0);
  }
//+------------------------------------------------------------------+
Forex Trader
114269
Forex Trader  

forgot, metatrater 4.00, build 225 (10 July 2009). If there's a new build, I don't know about it. LiveUpdate isn't working either.

Forex Trader
114269
Forex Trader  
nondisclosure007 :

This is an mql4 question.

So, let me get this straight; If draw a trendlinebyangle on the chart, I can only pull values off of the trendlinebyangle that I've already set? That's completely useless.

It doesn't matter how I draw the trendlinebyangle, I cant' get a value that I didn't set.

See code. I'm trying to get the angle by setting time1/price1 and time2/price2. My angle result is 0. If I set time1/price1, time2 and angle, I get 0 for price2 when I try to get it.

What gives MT?! Got an answer?, I hope.

#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");
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   ArraySetAsSeries(floor,true);
   ArraySetAsSeries(ceiling,true);
   return(0);
  }
int deinit()
  {
   ObjectDelete("LowerAngle");ObjectDelete("UpperAngle");
   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=limit; i>=0; 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);
      if (ObjectFind("LowerAngle")==-1)
         {ObjectCreate("LowerAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varLowMALast,Time[i+1],varLowMACurrent);}
      ObjectSet("LowerAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("LowerAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("LowerAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("LowerAngle",OBJPROP_PRICE1,varLowMALast);
      ObjectSet("LowerAngle",OBJPROP_PRICE2,varLowMACurrent);
      ObjectSet("LowerAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("LowerAngle",OBJPROP_RAY,true);       
      floor[i]=ObjectGet("LowerAngle",OBJPROP_ANGLE);
      if (ObjectFind("UpperAngle")==-1)
         {ObjectCreate("UpperAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varHighMALast,Time[i+1],varHighMACurrent);}
      ObjectSet("UpperAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("UpperAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("UpperAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("UpperAngle",OBJPROP_PRICE1,varHighMALast);
      ObjectSet("UpperAngle",OBJPROP_PRICE2,varHighMACurrent);
      ObjectSet("UpperAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("UpperAngle",OBJPROP_RAY,true);       
      ceiling[i]=ObjectGet("UpperAngle",OBJPROP_ANGLE);
      WindowRedraw();
   }
   return(0);
  }
//+------------------------------------------------------------------+

I've concluded that if you want to find the angle of a trendline, you need to do some trigonometry with the points you already have for the trendline... solviing for ARCTANGENT works well... also, since the charts are not ever a 1:1 aspect... don't waste your time converting RADS to DEGREEs... simply use the result in RADS and use some threshold...

Hope this helps

-charliev

Forex Trader
114269
Forex Trader  
charliev :
nondisclosure007 :

This is an mql4 question.

So, let me get this straight; If draw a trendlinebyangle on the chart, I can only pull values off of the trendlinebyangle that I've already set? That's completely useless.

It doesn't matter how I draw the trendlinebyangle, I cant' get a value that I didn't set.

See code. I'm trying to get the angle by setting time1/price1 and time2/price2. My angle result is 0. If I set time1/price1, time2 and angle, I get 0 for price2 when I try to get it.

What gives MT?! Got an answer?, I hope.

#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");
   SetIndexEmptyValue(0,0.0);
   SetIndexEmptyValue(1,0.0);
   ArraySetAsSeries(floor,true);
   ArraySetAsSeries(ceiling,true);
   return(0);
  }
int deinit()
  {
   ObjectDelete("LowerAngle");ObjectDelete("UpperAngle");
   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=limit; i>=0; 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);
      if (ObjectFind("LowerAngle")==-1)
         {ObjectCreate("LowerAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varLowMALast,Time[i+1],varLowMACurrent);}
      ObjectSet("LowerAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("LowerAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("LowerAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("LowerAngle",OBJPROP_PRICE1,varLowMALast);
      ObjectSet("LowerAngle",OBJPROP_PRICE2,varLowMACurrent);
      ObjectSet("LowerAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("LowerAngle",OBJPROP_RAY,true);       
      floor[i]=ObjectGet("LowerAngle",OBJPROP_ANGLE);
      if (ObjectFind("UpperAngle")==-1)
         {ObjectCreate("UpperAngle",OBJ_TRENDBYANGLE,0,Time[i+2],varHighMALast,Time[i+1],varHighMACurrent);}
      ObjectSet("UpperAngle",OBJPROP_STYLE,STYLE_DOT);
      ObjectSet("UpperAngle",OBJPROP_TIME1,Time[i+2]);
      ObjectSet("UpperAngle",OBJPROP_TIME2,Time[i+1]);
      ObjectSet("UpperAngle",OBJPROP_PRICE1,varHighMALast);
      ObjectSet("UpperAngle",OBJPROP_PRICE2,varHighMACurrent);
      ObjectSet("UpperAngle",OBJPROP_COLOR,Magenta);
      ObjectSet("UpperAngle",OBJPROP_RAY,true);       
      ceiling[i]=ObjectGet("UpperAngle",OBJPROP_ANGLE);
      WindowRedraw();
   }
   return(0);
  }
//+------------------------------------------------------------------+

I've concluded that if you want to find the angle of a trendline, you need to do some trigonometry with the points you already have for the trendline... solviing for ARCTANGENT works well... also, since the charts are not ever a 1:1 aspect... don't waste your time converting RADS to DEGREEs... simply use the result in RADS and use some threshold...

Hope this helps

-charliev

Thanks. I did figure out what was wrong, despite the fact it didn't make sense, I added floor[i]=0; ceiling[i]=0; to the begining of the for loop. Now I get the correct answer.

I'm curious about your Trig idea. I never made it that far in school, but if you've got the formula code to do it, I'd be willing to give it a try.

To add comments, please log in or register