ChartXYToTimePrice returning incorrect time

 

Hello everyone,


I am having issues with the function ChartXYToTimePrice. It is returning the correct price, but it always returns the incorrect time. I have written a script that creates a little red dot at the side of the chart that you move onto the chart and click a button. Once you click a button it's supposed to get the XY coordinates of the dot, replace it with a green one, and then convert the XY coordinates to Time and Price data that I will later do other things with. Here is the code.

   HAX = ObjectGetInteger(0,"Harmonic Point",OBJPROP_XDISTANCE,0);
   HAY = ObjectGetInteger(0,"Harmonic Point",OBJPROP_YDISTANCE,0);

   ObjectDelete(0,"Harmonic Point");
   ObjectCreate("Harmonic Point",OBJ_LABEL,0,0,0);
      ObjectSetInteger(0,"Harmonic Point",OBJPROP_SELECTED,true);
      ObjectSetInteger(0,"Harmonic Point",OBJPROP_CORNER,CORNER_RIGHT_UPPER);
      ObjectSet("Harmonic Point",OBJPROP_XDISTANCE,HAX);
      ObjectSet("Harmonic Point",OBJPROP_YDISTANCE,HAY);
      ObjectSet("Harmonic Point",OBJPROP_ANCHOR,ANCHOR_CENTER);
      ObjectSetText("Harmonic Point","l",7,"WingDings",Lime);

///////////////////////////////////////////////////////////////////////////////
   
   ChartXYToTimePrice(0,HAX,HAY,HAWin,HA_Time,HA_Price);
   
   ObjectCreate("Point Time",OBJ_VLINE,0,HA_Time,0);
     ObjectSet("Point Time",OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("Point Time",OBJPROP_COLOR, clrRed);
     ObjectSet("Point Time",OBJPROP_WIDTH, 1);
     ObjectSet("Point Time",OBJPROP_BACK, true);
     ObjectSetInteger(0,"Point Time",OBJPROP_HIDDEN,false);

   ObjectCreate("Point Price", OBJ_HLINE,0,0,HA_Price);
     ObjectSet("Point Price", OBJPROP_STYLE, STYLE_DOT);
     ObjectSet("Point Price", OBJPROP_COLOR, clrRed);
     ObjectSet("Point Price", OBJPROP_WIDTH, 1);
     ObjectSet("Point Price", OBJPROP_BACK, true);

Everything above the /// line seems to work, however the ChartXYToTimePrice consistently returns an incorrect value. Here is a screenshot of the error.


As you can see the green dot places at the correct XY coordinates, but then when they are converted to Time/Price data the time line places in the wrong place. Any idea why?


Regards,


Nik

 

Because of this

      ObjectSetInteger(0,"Harmonic Point",OBJPROP_CORNER,CORNER_RIGHT_UPPER);
 
Alain Verleyen:

Because of this

I was just coming here to update this because I figured that out. How do I fix it without changing where the initial dot is drawn? I tried resetting the OBJPROP_CORNER after the dot has been drawn, but it doesn't make any difference.

This is where the red dot needs to draw, so it needs to be right-aligned initially.


 
DrBeardface:

I was just coming here to update this because I figured that out. How do I fix it without changing where the initial dot is drawn? I tried resetting the OBJPROP_CORNER after the dot has been drawn, but it doesn't make any difference.

This is where the red dot needs to draw, so it needs to be right-aligned initially.

Seeing your screenshot I don't even understand why you need to convert from X/Y to Time/Price, but anyway :

int width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
ChartXYToTimePrice(0,width-HAX,HAY,HA_Win,HA_Time,HA_Price);
 
Alain Verleyen:

Seeing your screenshot I don't even understand why you need to convert from X/Y to Time/Price, but anyway :

I'm highlighting the highs and lows, inputting them into an array and using it to search for patterns. Thanks very much!!

Reason: