Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1785

 
Nerd Trader #:
do not see

But others can see(CHARTEVENT_OBJECT_CLICK)

 
Nerd Trader #:

Everything brilliant is simple.

I would have done so

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
  {    
   if(ObjectGetInteger(0,"button_bs",OBJPROP_STATE))
     {
      int      x     =(int)lparam;
      int      y     =(int)dparam;
      datetime dt    =0;
      double   price =0;
      int      window=0;
     
      if(id == CHARTEVENT_MOUSE_MOVE)
        {
         if(ChartXYToTimePrice(0,x,y,window,dt,price))
           {
            if(ObjectFind(0,"H Line")!=window)
              {
               ObjectCreate(0,"H Line",OBJ_HLINE,window,dt,price);
              }
            else
            if(ObjectMove(0,"H Line",window,dt,price))
              {
               ChartRedraw(0);
              }
           }
        }
     }
   else
     {
      ObjectDelete(0,"H Line");
     }
  }
 
MakarFX #:

I would do that.

Same solution. But that would not work for me, because after clicking on that line, I need to delete the first line, create another one, and have it follow the cursor and be deleted after clicking on it too. I did this:

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
    datetime static dt        = 0;
    double   static price     = 0;
    int      static window    = 0;
    string   static line_name;


  if(id==CHARTEVENT_OBJECT_CLICK){
    }
    //Нажатие кнопки создаёт line 1 
    if(sparam=="button"){
      line_name = "line 1";
      CreateLine(line_name, clrGreen);
    }
    //Нажатие на line 1 удаляет line 1 и создаёт line 2 
    if(sparam=="line 1"){
      ObjectDelete(0,line_name);
      line_name = "line 2";
      CreateLine(line_name, clrRed);
    }
    //Нажатие на line 2 удаляет line 2
    if(sparam=="line 2"){
      ObjectDelete(0,line_name);
    }
  }

  if(ObjectGetInteger(0,"button",OBJPROP_STATE)){
    int x = (int)lparam;
    int y = (int)dparam;
    if(ChartXYToTimePrice(0,x,y,window,dt,price)){
      if(id == CHARTEVENT_MOUSE_MOVE){
        if(ObjectMove(line_name,0,0,price))
          ChartRedraw(ChartID());
      }
    }
  }
}
 

Button pressed - create a line. Button pressed - delete. Is it that hard to guess?

Also, you can show and hide, so you don't have to create and delete them all the time.

 
Nerd Trader #:

Also a solution. But this won't work for me, because after clicking on this line, I need to delete the first line, create another one, and have it follow the cursor and be deleted after clicking on it too. I did so:

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
{
    datetime static dt        = 0;
    double   static price     = 0;
    int      static window    = 0;
    string   static line_name;


  if(id==CHARTEVENT_OBJECT_CLICK){
    }
    //Нажатие кнопки создаёт line 1 
    if(sparam=="button"){
      line_name = "line 1";
      CreateLine(line_name, clrGreen);
    }
    //Нажатие на line 1 удаляет line 1 и создаёт line 2 
    if(sparam=="line 1"){
      line_name = "line 2";
      ObjectSetString(0,"line 1",OBJPROP_NAME,line_name);
      ObjectSetInteger(0,line_name,OBJPROP_COLOR,clrRed);
    }
    //Нажатие на line 2 удаляет line 2
    if(sparam=="line 2"){
      ObjectDelete(0,line_name);
    }
  }

  if(ObjectGetInteger(0,"button",OBJPROP_STATE)){
    int x = (int)lparam;
    int y = (int)dparam;
    if(ChartXYToTimePrice(0,x,y,window,dt,price)){
      if(id == CHARTEVENT_MOUSE_MOVE){
        if(ObjectMove(line_name,0,0,price))
          ChartRedraw(ChartID());
      }
    }
  }
}

And I would leave a check for the object before creating and deleting

 
MakarFX #:

something has gone wrong) the signal is not coming at all. 0 trades.

why with double ?

my variables look like this:

// Параметры советника
input string  sParametersEA = "";     // Параметры советника
input double  Lot           = 0.01;   // Количество лотов
input double  LotControl    = 0.01;   // Контрольная лотность
input int     StopLoss      = 30;     // Уровень убытка
input int     TakeProfit    = 30;     // Уровень прибыли
input int     Deviation     = 20;     // Отступ цены входа
input int     Slippage      = 3;      // Проскальзование (в пунктах)
input int     Magic         = 1;      // Индентификатор советника
input double  K_Martin1     = 2.0;    // Множитель мартин 1
input double  K_Martin2     = 2.0;    // Множитель мартин 2
input double  K_Martin3     = 2.0;    // Множитель мартин 3
input int     OrdersClose   = 5;      // Ограничение лотности мартин1
input int     OrdersClose2  = 5;      // Ограничение лотности мартин2
input int     DigitsLot     = 2;      // Точность лотности
// Параметры индикатора
input string  ParametersMA  = "";     // Параметры индикатора
input int     PeriodMA      = 14;     // Период мувинга
input int     MovingShift   = 1;      // Сдвиг мувинга
// Глобальные переменные
string AC;
datetime Start;
double dMA;
double MaxMartinLot;
double MaxMartinLot2;
double openPrice;   // цена открытия позиции
//+-----------------------------------------------

maybe that's the problem ?

 
законопослушный гражданин #:

something has gone wrong) the signal is not coming at all. 0 trades.

why with double ?

my variables look like this:

maybe that's the problem?

Delete that.

double openPrice;   // цена открытия позиции
and in the code, use
openPrice();
 
законопослушный гражданин #:


Why double?


double - decimal numbers

int - integers

 
MakarFX #:

Delete that!

And in the code, use

Thank you! The signal has gone!

 
MakarFX #:

double - decimal numbers

int - integers

clearly