ChartTimePriceToXY giving same (wrong) results

 

I am trying to use an indicator only as dashboard to draw rectangles, labels, present information...

As drawing objects is easier with X and Y coordinates, I will end up using OBJ_LABEL and OBJ_RECTANGLE_LABEL... But the indicator subwindow is based (?) on datetime and prices.

The necessary conversion ChartTimePriceToXY is giving me errors. The simple following test fails:

//+------------------------------------------------------------------+
//| Tests() The following is inside the dummy Indicator              |
//|                                                                  |
//+------------------------------------------------------------------+
void Tests()
{
datetime T1; 
int subwo=0;
T1=Time(_Symbol,_Period,0);  // MQL5 emulation of MQL4 function
Print(T1); // gives 2018.11.29 21:00:00
bool ok = ChartTimePriceToXY(0,subwo,T1,1.2,X1,Y1);
Print (ok); // gives false
Print ("X1=",X1); // gives 1
Print ("Y1=",Y1);  // gives 540

T1=Time(_Symbol,_Period,40); 
Print(T1); // gives 2018.11.28 05:00:00
     ok = ChartTimePriceToXY(0,subwo,T1,36.7,X1,Y1);
Print (ok);  // gives false
Print ("X1=",X1); // gives 1
Print ("Y1=",Y1); // gives 540
}


Any help please?

 
Ziad El:

I am trying to use an indicator only as dashboard to draw rectangles, labels, present information...

As drawing objects is easier with X and Y coordinates, I will end up using OBJ_LABEL and OBJ_RECTANGLE_LABEL... But the indicator subwindow is based (?) on datetime and prices.

The necessary conversion ChartTimePriceToXY is giving me errors. The simple following test fails:

What is the Last Error?

You talk about the indicator sub window, but check the main chart?

 

You are right, sorry

int subwo=1;

 
Ziad El:

You are right, sorry

int subwo=1;

I'm betting everything that you are trying to plot Times and Prices that are beyond the visual bounds of the chart. In order to get X, Y the time and price need to be in the visual window, afterall, it couldn't return X=-100, y=-50, right? So if you need time, price coordinates than you obviously should use time, price coordinates. 

 

The problem with datetime and double is that it is difficult to program matrices of rectangles.

The weird thing I just found (after a day of suffering) is that using corners with int X and Y coordinates work well:


//+------------------------------------------------------------------+
//| DrawRectangle                                                    |
//|                                                                  |
//+------------------------------------------------------------------+
void Rc(string label, int xPixel_1, int yPixel_1, int width, 
  int height, color clrFill, color clrBorder, double style,
  int Corner=0,int subwindow=0)                                      {
ObjectDelete    (0, label )                                          ;
ChartSetInteger(0,CHART_FOREGROUND,0,false);  
ObjectCreate    (0,label,OBJ_RECTANGLE_LABEL,subwindow,0,0);
ObjectSetInteger(0,label,OBJPROP_XDISTANCE,  xPixel_1               );
ObjectSetInteger(0,label,OBJPROP_YDISTANCE,  yPixel_1               );
ObjectSetInteger(0,label,OBJPROP_XSIZE,      width                  );
ObjectSetInteger(0,label,OBJPROP_YSIZE,      height                 );
ObjectSetInteger(0,label,OBJPROP_BACK,       true                   );
ObjectSetInteger(0, label, OBJPROP_CORNER,    Corner                );  
ObjectSetInteger(0,label,OBJPROP_COLOR,      clrBorder              );
ObjectSetInteger(0,label,OBJPROP_BGCOLOR,    clrFill               );}

And calling this into my indicator with:


// Let me try to draw a rectangle from some corner:
Rc("R1", 22,32,22,44,clrAliceBlue,clrAntiqueWhite,SS,0,1); 
Rc("R2", 22,122,22,44,clrAliceBlue,clrAntiqueWhite,SS,1,1); 

work very well... (SS=StyleSolid redefined)


Anyway this whole idea of Indicator used as dashboard is not very elegant, I have seen EAs with large empty space below prices in the main window filled with data and labels... I do not know how to emulate this, the main window height seems so much linked with the prices themselves...

 
Ziad El:

The problem with datetime and double is that it is difficult to program matrices of rectangles.

The weird thing I just found (after a day of suffering) is that using corners with int X and Y coordinates work well:


And calling this into my indicator with:


work very well... (SS=StyleSolid redefined)

I don't understand why you need to work with time and price at all if want you want to do is create a matrix of chartobjects?


#include <chartobjects/chartobjectstxtcontrols.mqh>
void OnStart()
{
   //MATRIX
   CChartObjectRectLabel r1, r2, r3, r4;
   r1.Create(0, "r1", 0, 10, 10, 100, 100);
   r2.Create(0, "r2", 0, 120, 10, 100, 100);
   r3.Create(0, "r3", 0, 10, 120, 100, 100);
   r4.Create(0, "r4", 0, 120,120, 100, 100);
   ChartRedraw();
   while(!IsStopped())
      Sleep(10);
}
 

thanks nicholi for the code.

This class may be helpful for me.

Yes you are write, I was experimenting both directions, and instead of showing you my trials with ChartXYToTimePrice, I mistakenly began my question by showing ChartTimePriceToXY... So It was also an error in my question.

Maybe in the morning I had no internet connections so both ChartXYToTimePrice and ChartTimePriceToXY where giving "false"...

Reason: