Download MetaTrader 5
To add comments, please log in or register
Follow the news. View our company's official channel!
Michael
492
Michael 2016.01.28 20: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);
}
Michael
492
Michael 2016.01.28 22: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.
whroeder1
13596
whroeder1 2016.01.29 00: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.

Michael
492
Michael 2016.01.29 01: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?

Michael
492
Michael 2016.01.29 04: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);
  }
whroeder1
13596
whroeder1 2016.01.29 15: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.






/
To add comments, please log in or register