can't move the button with price

 

hi 

i want to move button with price i am unable to make it work can someone please help. sorry i am new to mql oncalculate i am calling objectmove but its not working.

Thanks!!


//+------------------------------------------------------------------+
//|                                                     moveable.mq4 |
//|                        Copyright 2022, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
extern string             button_note1          = "------------------------------";
extern int                btn_Subwindow = 0;
extern ENUM_BASE_CORNER   btn_corner            = CORNER_LEFT_UPPER; 
extern string             btn_text              = "test";
extern string             btn_Font              = "Arial";
extern int                btn_FontSize          = 10;                            
extern color              btn_text_ON_color     = clrLime;
extern color              btn_text_OFF_color    = clrRed;
extern string             btn_pressed           = "OFF";            
extern string             btn_unpressed         = "ON";
extern color              btn_background_color  = clrDimGray;
extern color              btn_border_color      = clrBlack;
extern int                button_x              = 850;                                 
extern int                button_y              = 0;                                   
extern int                btn_Width             = 75;                                 
extern int                btn_Height            = 20;                                
extern string             soundBT               = "tick.wav";  
extern string             button_note2          = "------------------------------";

string buttonId="";

int OnInit()
  {
//--- indicator buffers mapping
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);
  buttonId = "test";
   createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {

    ObjectMove(buttonId, 0, Time[0],0);

   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+

 void createButton(string buttonID,string buttonText,int width,int height,string font,int fontSize,color bgColor,color borderColor,color txtColor)
{
      ObjectDelete    (ChartID(),buttonID);
       ObjectCreate(ChartID(),buttonID,OBJ_BUTTON,btn_Subwindow,0,0);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_COLOR,txtColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BGCOLOR,bgColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_BORDER_COLOR,borderColor);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_XSIZE,width);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_YSIZE,height);
      ObjectSetString (ChartID(),buttonID,OBJPROP_FONT,font);
      ObjectSetString (ChartID(),buttonID,OBJPROP_TEXT,buttonText);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_FONTSIZE,fontSize);
      ObjectSetInteger(ChartID(),buttonID,OBJPROP_SELECTABLE,true);
      
     
}
 
best trader: i want to move button with price i am unable to make it work can someone please help. sorry i am new to mql oncalculate i am calling objectmove but its not working.
  1. Buttons are fixed to (x,y) pixel coordinates, not to prices. That is why your move does not work.

    //  ObjectMove(buttonId, 0, Time[0],0);
    
        int x,y; ChartTimePriceToXY(0,0, Time[0], Open[0], x, y);
        ObjectSetInteger(0, buttonID, OBJPROP_CORNER, CORNER_LEFT_UPPER);
        ObjectSetInteger(0, buttonID, OBJPROP_XDISTANCE,    x);
        ObjectSetInteger(0, buttonID, OBJPROP_YDISTANCE,    y);
    
  2. You don't have to continuously move the button. Place it in the upper right/lower right of the chart and just leave it there.
         How To Ask Questions The Smart Way. (2004)
              The XY Problem

 
William Roeder #:
  1. Buttons are fixed to (x,y) pixel coordinates, not to prices. That is why your move does not work.

  2. You don't have to continuously move the button. Place it in the upper right/lower right of the chart and just leave it there.
         How To Ask Questions The Smart Way. (2004)
              The XY Problem

Thankyou!!!! i got it.....