CHARTEVENT_OBJECT_DRAG

 

Hi,

I'm trying to retrieve the new price property from a object (horizontal line) after it's dragged, but it returns the old value and not the new one.

Am I doing something wrong? How to get new new value (price to where it was dragged to)?

    virtual void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
     {
      if(id==CHARTEVENT_OBJECT_DRAG)
        {
         double value;
         ObjectGetDouble(0,sparam,OBJPROP_PRICE,0,value);
         Print(value); // Old Value
        }
     }
 
Henrique Vilela:

Hi,

I'm trying to retrieve the new price property from a object (horizontal line) after it's dragged, but it returns the old value and not the new one.

Am I doing something wrong? How to get new new value (price to where it was dragged to)?

I have the code working correctly - I get new price value.

MetaTrader 5 x64 build 1210 started (MetaQuotes Software Corp.)
 
Henrique Vilela:

Hi,

I'm trying to retrieve the new price property from a object (horizontal line) after it's dragged, but it returns the old value and not the new one.

Am I doing something wrong? How to get new new value (price to where it was dragged to)?

you have to redraw object after drag-drop, that mean repeat the code of drawing after ObjectDelete of first previous object location.

 
void OnChartEvent(const int id, 
                  const long &lparam, 
                  const double &dparam, 
                  const string &sparam) 
  { 
//--- Show the event parameters on the chart 
   Comment(__FUNCTION__,": id=",id," lparam=",lparam," dparam=",dparam," sparam=",sparam); 
//--- If this is an event of a mouse click on the chart 
   if(id==CHARTEVENT_CLICK) 
     { 
      //--- Prepare variables 
      int      x     =(int)lparam; 
      int      y     =(int)dparam; 
      datetime dt    =0; 
      double   price =0; 
      int      window=0; 
      //--- Convert the X and Y coordinates in terms of date/time 
      if(ChartXYToTimePrice(0,x,y,window,dt,price)) 
        { 
         PrintFormat("Window=%d X=%d  Y=%d  =>  Time=%s  Price=%G",window,x,y,TimeToString(dt),price); 
         //--- Perform reverse conversion: (X,Y) => (Time,Price) 
         if(ChartTimePriceToXY(0,window,dt,price,x,y)) 
            PrintFormat("Time=%s  Price=%G  =>  X=%d  Y=%d",TimeToString(dt),price,x,y); 
         else 
            Print("ChartTimePriceToXY return error code: ",GetLastError()); 
         //--- delete lines 
         ObjectDelete(0,"V Line"); 
         ObjectDelete(0,"H Line"); 
         //--- create horizontal and vertical lines of the crosshair 
         ObjectCreate(0,"H Line",OBJ_HLINE,window,dt,price); 
         ObjectCreate(0,"V Line",OBJ_VLINE,window,dt,price); 
         ChartRedraw(0); 
        } 
      else 
         Print("ChartXYToTimePrice return error code: ",GetLastError()); 
      Print("+--------------------------------------------------------------+"); 
     } 
  }
this code is an exsample --  ObjectDelete(0,"H Line"); necessary to delete old value--then draw object again then get new value.