MQL5: Bug or user error using CChartObjectTrendByAngle objec

Post Reply
imamushroom
Posts: 6
Joined: Fri Oct 30, 2015 9:48 pm

MQL5: Bug or user error using CChartObjectTrendByAngle objec

Post by imamushroom »

Have I found a bug?

I'm having difficulty using the CChartObjectTrendByAngle class as it is not doing what I expect it to do (drawing lines from the previous opens). Have I found a bug or am I doing something wrong?

My code is this

Code: Select all

#include <Kerching!/libIndicators.mqh>
#include <ChartObjects/ChartObjectsLines.mqh>

class CPlayable : CCustomIndicator
{
   private:
      bool _selectable;
      bool _hidden;
      color _l1Colour;
      color _l2Colour;
      bool _playable;        
      datetime _t[];
      double _o[];

      CChartObjectTrendByAngle* _L1;
      CChartObjectTrendByAngle* _L2; 
   
      double GetMa(int pAppliedPrice, int pShift);
      void UpdateMa(int pShift);
      
   public:
      void CPlayable(string pSymbol, int pTimeframe, bool pSelectable, bool pHidden, color pL1Colour, color pL2Colour);
      void ~CPlayable(void);
      bool Playable(int pShift);     
      int Direction(int pShift); 
};

void CPlayable::CPlayable(string pSymbol, int pTimeframe, bool pSelectable, bool pHidden, color pL1Colour, color pL2Colour)
{
   Init(pSymbol,pTimeframe);
   
   _selectable = pSelectable;
   _hidden = pHidden;
   _l1Colour = pL1Colour;
   _l2Colour = pL2Colour;
   _playable = false;

   
   _L1 = new CChartObjectTrendByAngle();
   _L2 = new CChartObjectTrendByAngle();

   
   const int m = 3;
   
   ArrayResize(_t,m);
   ArrayResize(_o,m);
}

void CPlayable::~CPlayable(void)
{
   delete _L1;
   delete _L2;
}

bool CPlayable::Playable(int pShift)
{
   if( _L1 != NULL ) _L1.Delete();
   if( _L2 != NULL ) _L2.Delete();
   
   int mt = ArraySize(_t);
   int mo = ArraySize(_o);
   
   CopyOpen(_symbol,_timeFrame,0,mt,_o);
   CopyTime(_symbol,_timeFrame,0,mo,_t);
   
   mt--;
   mo--;

   long chartid = ChartID();
   
   _L1.Create(chartid,"L1",0,_t[mt-1],_o[mo-1],_t[mt],_o[mo]);   // displays example screenshot
//   L1.SetDouble(OBJPROP_PRICE2,o0);  //works with this line but shouldn't need it 
   _L1.Selectable(_selectable);
   _L1.Selected(true);
   _L1.Hidden(_hidden);
   _L1.Color(_l1Colour);
   _L1.RayRight(true);
   
   _L2.Create(chartid,"L2",0,_t[mt-2],_o[mo-2],_t[mt-1],_o[mo-1]);
//   L2.SetDouble(OBJPROP_PRICE2,o1);
   _L2.Selectable(_selectable);
   _L2.Selected(true);
   _L2.Hidden(_hidden);
   _L2.Color(_l2Colour);
   _L2.RayRight(true);

   ObjectCreate(chartid,"Test",OBJ_TRENDBYANGLE,0,_t[mt-1],iClose(_symbol,_timeFrame,pShift+1),_t[mt],iClose(_symbol,_timeFrame,pShift));  //works
   
   double l1angle = _L1.Angle();

   PrintFormat("&& l1angle = %f, l2angle = %f, initalAngle = %i",l1angle,_L2.Angle());    // displaying 0.00
   PrintFormat("&& ObjectGetDouble(m_chart_id,m_name,OBJPROP_ANGLE) = %f,",ObjectGetDouble(chartid,"L1",OBJPROP_ANGLE));    // displaying 0.00
   PrintFormat("&& ObjectGetDouble(Close) = %f,",ObjectGetDouble(chartid,"Test",OBJPROP_ANGLE));  // displaying 0.00  

   
   return _playable;
}
I find that point2 of the Create command doesn't follow the open price of o0. If I add this line

Code: Select all

 L1.SetDouble(OBJPROP_PRICE2,o0);
after the L1.Create command the line seems to be drawn correctly.

Also, the Angle printformat statement says that the angle of the line is 0.000 which is also incorrect.

I've tried a test using the ObjectCreate command directly and the points are drawn correctly,however, the angle retrieved from the command

Code: Select all

ObjectGetDouble(chartid,"Test",OBJPROP_ANGLE)
(where "Test" is the name of the line created using the ObjectCreate command) still reports 0.000

Any ideas what I should do to get it working correctly?

Thanks in advance.
Post Reply

Return to “Coders Hangout”