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

 
Константин:
@Artyom Trishkin

Can you give me some business tips?

I can give you a lot of different information about turkeys.

For starters, it's a pheasant bird. It's dietary meat. I feed it to my cat. He says it's delicious...

 
Константин:

Can you give me a clue as to the point?

And to the point, why would you want to run the script from an indicator?

 
Mihail Matkovskij:

As for the point, who told you to be so stupid as to run scripts from an indicator? :)

And most importantly, why?

I want to make a button on the chart so that I can run a script by pressing a button with a parameter taken from the indicator

 
Константин:

I want to make a button on the chart so that I can run the script by pressing the button, with the parameter taken from the indicator

You write the code of the button in the indicator code and integrate the script code as a function in the indicator code. Press the button - call the function, in which you pass the indicator parameter.

 
Константин:

I want to make a button on the chart, so that I can run the script by pressing the button, with the parameter taken from the indicator

If the problem is in creating the button itself, here it is:

//+------------------------------------------------------------------+
//|                                                  ClickButton.mq5 |
//|                                      Copyright 2020, © Cyberdev. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, © Cyberdev."
#property version   "1.00"
#property indicator_chart_window

#property indicator_plots 0

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
#include <ChartObjects\ChartObjectsTxtControls.mqh>

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
CChartObjectButton button;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {
  button.Create(0, "pushBtn", 0, 30, 30, 80, 21);
  button.SetString(OBJPROP_TEXT, "Push my");
  button.SetInteger(OBJPROP_BGCOLOR, clrDodgerBlue);
  button.Color(clrWhite);
  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]) {
//---
//--- 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
) {
  if(id == CHARTEVENT_OBJECT_CLICK) {
    if(sparam == button.Name()) {
      Alert("Button \""+sparam+"\" clicked!"); // Вместо этого функция с кодом...
      button.State(0);
      ChartRedraw(0);
    }
  }
}
//+------------------------------------------------------------------+
 
Mihail Matkovskij:

If the problem is in creating the button itself, here it is:

Thanks, I think I've got the button figured out, but I haven't figured out how to attach the script. The script is at C:\Users\...\MQL4\Scripts\Order.ex4

 
Another question. I use a small tablet on Windows without a mouse, the buttons on the graph is a convenient solution for me. Is it possible to have the keyboard command Ctrl+F5 executed when pressing the button on the graph, it would be more convenient for me to view the following profile.
 
Константин:

Thanks, I think I've figured out the button, but I haven't figured out how to attach the script. The script is located at C:\Users\...\MQL4\Scripts\Order.ex4

Assign a shortcut to the script and simulate it using WinAPI. But I haven't done anything like that inMQL programs. So try googling"SendInput User32.dll WinAPI".

 

Good afternoon!

I am struggling with one question. Could you please tell me how to solve it?

The idea is the following: I draw a line at the previous maximum of the candle. I want the line to be shifted depending on the previous maximum.

void OnTick()
  {
//---
   double   o1 = iOpen(Symbol(),Period(),1);
   double   h1 = iHigh(Symbol(),Period(),1);
   double   l1 = iLow(Symbol(),Period(),1);
   double   c1 = iClose(Symbol(),Period(),1);
   double   c0 = iClose(Symbol(),Period(),0);
   double   rt = 0;
   double   rs1 = 0;


rt=MathAbs(c1-o1)/_Point; //размер тела свечи
rs1=MathAbs(h1-c1)/_Point;// размер верхней тени свечи


if (rs1>=rt) // условие для построения уровней (если верхняя тень предыдущей свечи, больше, или равна телу этой же всечи, то...   
{
double PRH=iHigh(Symbol(),_Period,1); // то это будет максимум
ObjectCreate(0,"HL",OBJ_HLINE,0,_Period,PRH); // и строим по этому максимуму, горизонтальную линию
Comment("ЦЕНА МАКС =======",PRH,"\n"); // комментарий пред. максимума
}
}
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Стили рисования
Документация по MQL5: Константы, перечисления и структуры / Константы индикаторов / Стили рисования
  • www.mql5.com
При создании пользовательского индикатора можно указать один из 18 типов графического построения (способа отображения на главном окне графика или в подокне графика), значения которых указаны в перечислении ENUM_DRAW_TYPE. В зависимости от стиля рисования, может потребоваться от одного до четырех буферов значений (отмеченных как INDICATOR_DATA...
 
Alexey Belyakov:

Good afternoon!

I am struggling with one question. Please tell me how to solve it.

The idea is the following: I draw a line at the previous maximum of the candle. I want the line to be shifted depending on the previous maximum.

There are 2 options
1. You have to delete the object before drawing it.
2. Set the price after creating the object