Download MetaTrader 5

ChartXYToTimePrice() does not work

To add comments, please log in or register
Tarp999
46
Tarp999  

I want to draw an ellipse on the chart to the fixed coordinates x1=250 y1=70, x2=250 y2=120 (in pixel).

This is the code:

 ObjectCreate("Insegna", OBJ_ELLIPSE,0,0,0);
 int x = 250, y1 = 70, y2 = 120, sub_window; datetime time; double price1, price2;
 ChartXYToTimePrice(0, x, y1, sub_window, time, price1);
 ChartXYToTimePrice(0, x, y2, sub_window, time, price2);
 ObjectSet("Insegna", OBJPROP_TIME1, time);
 ObjectSet("Insegna", OBJPROP_PRICE1, price1);
 ObjectSet("Insegna", OBJPROP_TIME2, time);
 ObjectSet("Insegna", OBJPROP_PRICE2, price2);
 ObjectSet("Insegna", OBJPROP_SCALE, 0.6);
 ObjectSet("Insegna", OBJPROP_COLOR, clrMediumBlue);
 ObjectSet("Insegna", OBJPROP_BACK, true);
 ChartRedraw(0);

Does not show anything!

I have found that ChartXYToTimePrice() does not correctly convert the y coordinate. The x coordinate is converted well.

I get price1=1.3697 and price2=1.3699, and these prices remain outside the visible area of the window (price ranging from min 1.3739 to max 1.3783).

Why? Where I'm wrong?

Alain Verleyen
Moderator
32008
Alain Verleyen  
GarZed9:

I want to draw an ellipse on the chart to the fixed coordinates x1=250 y1=70, x2=250 y2=120 (in pixel).

This is the code:

Does not show anything!

I have found that ChartXYToTimePrice() does not correctly convert the y coordinate. The x coordinate is converted well.

I get price1=1.3697 and price2=1.3699, and these prices remain outside the visible area of the window (price ranging from min 1.3739 to max 1.3783).

Why? Where I'm wrong?


Which build are you using ? It works for me with 610 and 614, but the ellipse is flattened as you are using the same time for both points
Keith Watford
Moderator
10372
Keith Watford  

Maybe it is to do with the variable sub_window ?

Try sub_window = 0

Tarp999
46
Tarp999  
angevoyageur:
Which build are you using ? It works for me with 610 and 614, but the ellipse is flattened as you are using the same time for both points



I'm using Build 883.

I also tried with x1=250 (time1) and x2=350 (time2) but still does not work.

Tarp999
46
Tarp999  
GumRai:

Maybe it is to do with the variable sub_window ?

Try sub_window = 0



Does not work.
qjol
3243
qjol  
GarZed9:

I want to draw an ellipse on the chart to the fixed coordinates x1=250 y1=70, x2=250 y2=120 (in pixel).

This is the code:


works just fine for me (maybe u have to change the color to see it)
Tarp999
46
Tarp999  
qjol:
works just fine for me (maybe u have to change the color to see it)


Unfortunately, nothing to do, to me it does not work, even with other colors.
Alain Verleyen
Moderator
32008
Alain Verleyen  
GarZed9:



I'm using Build 883.

I also tried with x1=250 (time1) and x2=350 (time2) but still does not work.

Which MT4 build ? 883 is for MetaEditor.

#property strict
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()
  {
   ObjectCreate("Insegna",OBJ_ELLIPSE,0,0,0);
   int x=250,y1=70,y2=120,sub_window; datetime time; double price1,price2;
   ChartXYToTimePrice(0,x,y1,sub_window,time,price1);
   ChartXYToTimePrice(0,x,y2,sub_window,time,price2);
   ObjectSet("Insegna",OBJPROP_TIME1,time);
   ObjectSet("Insegna",OBJPROP_PRICE1,price1);
   ObjectSet("Insegna",OBJPROP_TIME2,time);
   ObjectSet("Insegna",OBJPROP_PRICE2,price2);
   ObjectSet("Insegna",OBJPROP_SCALE,0.6);
   ObjectSet("Insegna",OBJPROP_COLOR,clrMediumBlue);
   ObjectSet("Insegna",OBJPROP_BACK,true);
   ChartRedraw(0);
  }// End of OnStart


Tarp999
46
Tarp999  
angevoyageur:
Which MT4 build ? 883 is for MetaEditor.




Sorry, MT4+ (JFD Brokers) Build 600.

I tried again with a new Script file, instead of an Expert Advisor, but nothing to do.

Strange, very very strange!

Alain Verleyen
Moderator
32008
Alain Verleyen  
GarZed9:



Sorry, MT4+ (JFD Brokers) Build 600.

I tried again with a new Script file, instead of an Expert Advisor, but nothing to do.

Strange, very very strange!


Current build is 610. Maybe there is a bug in 600 with Ellipse or ChartXYTimeToPrice, nothing strange.
Donald R Isbell Jr
283
Donald R Isbell Jr  

I need help with ChartXYToTimePrice.

I want to step a horizontal line down a number of times from top to bottom of screen.

I made a function, but it does not work.

#property copyright "Don Isbell"
#property link      "disbellj@gmail.com"

#property indicator_chart_window

extern int startYoffset = 175;
extern int Yoffset = 5;
extern int h = 35;
extern color HLcolor = Blue;
//---- parameters
int length = 28;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+




int start()
  {
 
   DrawHorizontalLinesDown();

   return(0);
  }
//+------------------------------------------------------------------+
void DrawHorizontalLinesDown() {
   int Ystep=h*1.5;
   int m = 0;
   int y = startYoffset+Ystep+Yoffset;
   int x = 0;
   datetime dt = 0;
   double price = 0;
   int window = 0;
   string name = "test_line ";
   int number = 1;
   for(int i=0;i<length;i++) {
      ChartXYToTimePrice(0,x,y,window,dt,price);
      if(ObjectFind(name+number) == -1) {
         ObjectCreate(0,name+number, OBJ_HLINE, window, dt, price);
         ObjectSetInteger(0,name+number,OBJPROP_COLOR,HLcolor);
      }
      Ystep+=h;   
   }
}

Please let me know if you have any insights as to where I went wrong (me knowing only old MQL4 and not new MQL4/MQL5, and this is first new MQL4 function I've tried to implement into my code).

Thanks in Advance!

Kindest regards,

Don

12
To add comments, please log in or register