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

 
MakarFX:

It does not give out any errors.

Errors can also be algorithmic, not just run-time errors!

You need the code if you want to find the cause.

MakarFX:

With these coordinates the button comes out upside down, because the length of the button is counted +/- from the X point

Why do you need such a weird button...?

 
MakarFX:

I can suggest the option of ExpertRemove() when a profit or loss is reached

thanks

I have read it, but I do not fully understand the logic of actions

When a specified event is reached, the Expert Advisor is disabled and removed from the chart, right?

 
Mihail Matkovskij:

Errors can also be algorithmic, not just run-time errors!

You need a code if you want to find the cause.

Why do you need such a weird button...?

I wrote that I accidentally stumbled upon such a bug

here's the code... if you're interested

//+------------------------------------------------------------------+
//|                                                          BAG.mq4 |
//|                                           Copyright 2020, DrMak. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, DrMak."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   CreateButton(0,"Button_1",0,200,100,100,50,CORNER_RIGHT_UPPER," ","START","Arial Black",10,
   clrWhite,clrGreen,BORDER_SUNKEN,false,false,false,false,false,0);
   CreateButton(0,"Button_2",0,200,100,-100,-50,CORNER_RIGHT_UPPER," ","START","Arial Black",10,
   clrWhite,clrGreen,BORDER_SUNKEN,false,false,false,false,false,0);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,"Button_");
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Создает кнопку                                                   |
//+------------------------------------------------------------------+
bool CreateButton(const long              chart_ID=0,               // ID графика
                  const string            name="Button",            // имя кнопки
                  const int               sub_window=0,             // номер подокна
                  const int               x=0,                      // координата по оси X
                  const int               y=0,                      // координата по оси Y
                  const int               width=50,                 // ширина кнопки
                  const int               height=18,                // высота кнопки
                  const int               corner=0,                 // угол графика для привязки
                  const string            tool="TOOLTIP",           // TOOLTIP
                  const string            text="Button",            // текст
                  const string            font="Arial",             // шрифт
                  const int               font_size=10,             // размер шрифта
                  const color             clr=clrBlack,             // цвет текста
                  const color             back_clr=C'236,233,216',  // цвет фона
                  ENUM_BORDER_TYPE        border_type=BORDER_FLAT,  // тип границы
                  const bool              state=false,              // нажата/отжата
                  const bool              back=false,               // на заднем плане
                  const bool              selection=false,          // выделить для перемещений
                  const bool              selected=false,           // выделить для перемещений
                  const bool              hidden=true,              // скрыт в списке объектов
                  const long              z_order=0)                // приоритет на нажатие мышью
  {
//--- сбросим значение ошибки
   ResetLastError();
//--- создадим кнопку
   if(!ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0))
     {
      Print(__FUNCTION__, ": не удалось создать кнопку! Код ошибки = ",GetLastError()); return(false);
     }
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
   ObjectSetString(chart_ID,name,OBJPROP_TOOLTIP,tool);
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border_type);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
   ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selected);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- успешное выполнение
   return(true);
  }
//+------------------------------------------------------------------+
 
законопослушный гражданин:

thanks

I have read it, but I do not quite understand the logic of action

when a specified event is reached, the EA is deactivated and removed completely from the chart, right?

Yes
 
MakarFX:

I wrote that I accidentally stumbled upon such a bug

here's the code... if you're interested.

So here none of the buttons will respond. TheOnChartEvent handler is empty...

 
Mihail Matkovskij:

So here none of the buttons will respond. TheOnChartEvent handler is empty...

try it) one button will be pressed and the other will not
 
MakarFX:
try it) one button presses and the other doesn't

Who does that anyway, sets negative dimensions and why, I'm embarrassed to ask...?

 
MakarFX:
Yes

got it. that won't work for me.

you could go back to creating a global variable so that when the owl is turned off, the lot is reset to the start

at least like this

you createa global variable

datetime Start;

int OnInit()
{
   Start=TimeCurrent();
.....................
}
void OnTick()
{
   if (!IsTradeAllowed()) 
   {
      DrawLABEL("Торговля",0,0,0,Red,"Торговля запрещена");
      Start=TimeCurrent();
      return;
   } 
.....................
}

and then if there are no open/closed orders later "Start"

Lots=Lot;
but I still don't know how to create it properly
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Глобальные переменные - Переменные - Основы языка - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
законопослушный гражданин:

got it. that won't work for me.

you could go back to creating a global variable so that when the owl is switched off, the lot is reset to the start

at least like this

you createa global variable

and then if there are no open/closed orders later "Start".

but I still don't know how to create it properly

I will make you a button)


 
Mihail Matkovskij:

Who does that anyway, sets negative dimensions and why, I'm embarrassed to ask...?

I stumbled across this bug by accident and wondered