Why does this always draw a flat trend angle

Back to topics list To post a new topic, please log in or register
avatar
147
nondisclosure 2016.01.28 21:44
 

Put this on chart.  No matter how far apart the 2 prices are, it ALWAYS draws a flat trend line.  Why?

#property strict
#include <ChartObjects\ChartObjectsLines.mqh>
CChartObjectTrendByAngle myAngle;
#include <Files\FileTxt.mqh>
CFileTxt nFile;
bool IsInit=false;
datetime LastTime;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   nFile.Open(StringConcatenate("Recording Angles for ",Symbol(),".csv"),FILE_READ|FILE_WRITE);
   IsInit=true;
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   nFile.Close();
   myAngle.Delete();   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(IsInit)
     {
      LastTime=Time[0];
      IsInit=false;
      BuildAngle();      
     }
   if(!IsInit && LastTime!=Time[0])
     {
      BuildAngle(); LastTime=Time[0];
     }
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
void BuildAngle()
{
      double Price1=NormalizeDouble(iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,1),_Digits);
      double Price2=NormalizeDouble(iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,5),_Digits);
      myAngle.Delete();
      myAngle.Create(0,"myAngle",0,Time[5],Price2,Time[1],Price1);
      myAngle.Hidden(false);
      double GetAngle=myAngle.Angle();
      string IBWritin=StringConcatenate(GetAngle,",",Price1,",",Price2,",","\r\n");
      nFile.WriteString(IBWritin);
}
avatar
147
nondisclosure 2016.01.28 23:08 #
 
Before anyone asks "Why do you want to do this" or "Angles are pointless" etc. that's been said all over this site.  Understand that those are NOT the questions.  The question is why does it draw a straight line instead of a trend line by angle.
avatar
13001
WHRoeder 2016.01.29 01:41 #
 

An angle has nothing to do with price/time #2; if you understood that "Angles are pointless" you would know that. You call the GetAngle but you never set one Angle(double). An angle is one price + the angle.


avatar
147
nondisclosure 2016.01.29 02:55 #
 
WHRoeder:

An angle has nothing to do with price/time #2; if you understood that "Angles are pointless" you would know that. You call the GetAngle but you never set one Angle(double). An angle is one price + the angle.


What is your problem?  You couldn't just answer the question?  You HAD to add that comment? 

Then why does MQL4 REQUIRE a second date and time price when creating the object (from the Metaedit help file: ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time,price,time2,price2)?  And what's the point of reading the angle of the object if all you do is just set it?  Or is this just another MetaQuotes f-up?

avatar
147
nondisclosure 2016.01.29 05:02 #
 
nondisclosure:

What is your problem?  You couldn't just answer the question?  You HAD to add that comment? 

Then why does MQL4 REQUIRE a second date and time price when creating the object (from the Metaedit help file: ObjectCreate(chart_ID,name,OBJ_TRENDBYANGLE,sub_window,time,price,time2,price2)?  And what's the point of reading the angle of the object if all you do is just set it?  Or is this just another MetaQuotes f-up?

Solved it

void BuildAngle()
  {
   double Price1=NormalizeDouble(iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,1),_Digits);
   double Price2=NormalizeDouble(iMA(NULL,0,5,0,MODE_SMA,PRICE_CLOSE,5),_Digits);
   myAngle.Delete();
   myAngle.Create(0,"myAngle",0,Time[5],Price2,Time[1],Price1);
   myAngle.Hidden(false);
   ObjectSet("myAngle",OBJPROP_TIME2,Time[1]);
   ObjectSet("myAngle",OBJPROP_PRICE2,Price1);
   //ChartRedraw();
   double GetAngle=myAngle.Angle();
   string IBWritin=StringConcatenate(GetAngle,",",Price1,",",Price2,",","\r\n");
   nFile.WriteString(IBWritin);
  }
avatar
13001
WHRoeder 2016.01.29 16:10 #
 
nondisclosure:

What is your problem?  You couldn't just answer the question?  You HAD to add that comment? 

Then why does MQL4 REQUIRE a second date and time price when creating the object

And what's the point of reading the angle of the object if all you do is just set it?  Or is this just another MetaQuotes f-up?

  1. I did answer it. I had to add that comment because you said you understood but apparently don't.
  2. MQL4 does NOT require the second point when creating the object. The help file and ObjectCreate - MQL4 Documentation clearly shows the second and subsequent ones have default. OBJ_TRENDBYANGLE - MQL4 Documentation also clearly shows TrendByAngleCreate contains one price/time and one angle.
  3. Reading values from objects is done all the time so you don't have to remember a second copy.






Back to topics list  

To add comments, please log in or register