Download MetaTrader 5

ChartXYToTimePrice() does not work - page 2

To add comments, please log in or register
Keith Watford
Moderator
10561
Keith Watford  
disbellj:

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.

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

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);
      }

I haven't tested the code but I think that this will only create 1 line

You could name the line name+ (string) i

You also need to change the y value inside the loop

Donald R Isbell Jr
283
Donald R Isbell Jr  

GumRai,

You are right that the code was producing just one line. I forgot to add number++ at end of for cycle. After doing that, it creates the correct number of objects on chart, even makes them the correct color and width. But they're 0 value. This leads back to ChartXYToTimePrice, which is not returning the correct value for price for horizontal line.

#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 = Yellow;
extern int LineWidth = 3;
//---- parameters
int length = 28;

int init() {
   return(0);
}

int deinit() {
   ObjectsDeleteAll();
   return(0);
}

int start() {
   DrawHorizontalLinesDown();
   return(0);
}

void DrawHorizontalLinesDown() {
   int Ystep=h*1.5;
   int m = 0;
   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++) {
      int y = startYoffset+Ystep+Yoffset;
      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_WIDTH,LineWidth);
         ObjectSetInteger(0,name+number,OBJPROP_COLOR,HLcolor);
      }
      number++;
      Ystep+=h;   
   }
}

Shows multiple lines numbered with different numbers so this is correct.

Shows line color and width has been applied correctly.

The horizontal line value is 0, so not correct Y offset to price conversion.

Thanks for your help! At least making progress :) Any more replies are welcome and desired.

Kindest regards,

Don

Donald R Isbell Jr
283
Donald R Isbell Jr  

If I add:

Alert(price);

... right below ObjectCreate line of code, I get all 0 values for all objects, so again, function is not returning correct values each cycle.

qjol
3243
qjol  

i noticed that only if x >= 3 price returns something

maybe it's a bug maybe not i don't care

Donald R Isbell Jr
283
Donald R Isbell Jr  

Thanks qjol, that worked!

Thanks again!

Kindest regards,

Don

My AllPairs EA now with horizontal lines

12
To add comments, please log in or register