Learning and writing together in MQL5 - page 20

 

Transferred from Write and earn in MQL5



Khomtchenko 2011.05.07 22:01

Can you tell me how to modify i.e. change stop loss value in mql5. I already know how to do it on 4. I'm trying to modify my robot for 5 version and it got stuck.


 
sergeev:

Transferred from Write and earn in MQL5



Khomtchenko 2011.05.07 22:01

Can you tell me how to modify i.e. change stop loss value in mql5. I already know how to do it on 4. I'm trying to modify my robot for 5 version and it got stuck.



Read this article How to Create a Trailing Stop
 
The tester spits out a graph without the necessary indicators, such as stochastic, etc., then I have to add, how to make it so that they are added automatically?
 
customprogrammi:
The tester spits out a graph without the necessary indicators, such as stochastics, etc., so you have to add them later.

Use the required template, you can read about the templates in the Terminal Help section MetaTrader 5Working with ChartsTemplates and Profiles:

There are several predefined template names in the terminal:

  • default.tpl - basic template that is automatically applied when creating a new chart;
  • tester.tpl - template that is used for the chart, on which test results are displayed;
  • debug.tpl- template that is applied to the chart that is created at start of debugging of MQL5 program from MetaEditor.

In order to create a template with the required parameters (or modify an existing one), set up the chart in a required manner and save the template under the required name using the corresponding command.

 
AUser:

Can anyone suggest some examples, articles on the subject?

http://docs.mql4.com/ru/globals
Глобальные переменные - Документация на MQL4
  • docs.mql4.com
Глобальные переменные - Документация на MQL4
 
AUser:

Global variables of the client terminal.


We should cover the topic. I haven't found any real examples in Help. I'm trying to figure out how to create such a variable. So far, I got errors on my variants.

May someone suggest an example, an article on the subject?


https://www.mql5.com/ru/docs/globals

Let's learn to read a manual, people have written the letters in words, and you ignore them.

GlobalVariableSet("variable_name",set_value)

Sets new valueof global variable. If the variable does not exist, the system creates a new global variable.

 
AUser:

Thanks, that's it:

How could I, an unheated dummy, know about inverted commas?)

There is no example for mql5 Help))

datetime  GlobalVariableSet(
   string  name,      // имя
   double  value      // устанавлимое значение
   );

The manual says that the name of a global variable is specified as a string, the quotes are a normal way to specify a string.

Read the rules, for they are rules.

You can set it this way:

string  name="Глобальная_переменная";
double   value=123.0456;
GlobalVariableSet(name,value);
Документация по MQL5: Глобальные переменные терминала / GlobalVariableName
Документация по MQL5: Глобальные переменные терминала / GlobalVariableName
  • www.mql5.com
Глобальные переменные терминала / GlobalVariableName - Документация по MQL5
 
I have a procedure to detect the start of a new bar in mql4:
void Fun_New_Bar() // A detection fiie .

{ // ...new bar
static datetime New_Time=0; // time of current bar
New_Bar=false; // no new bar
if(New_Time!=Time[0]) // compare time
{
New_Time=Time[0]; // time is now
New_Bar=true; // Caught new bar
}
} Everything
worked like clockwork.

Here I modified it in mql5:
void Fun_New_Bar() // Fun detection ...
{ // ... new bar
static datetime New_Time=0; // Time of the current bar
New_Bar=false; // No new bar
MqlTick last_tick;//The prices of the last tick received
SymbolInfoTick(_Symbol,last_tick);//Fill structure last_tick with the prices of the current symbol.
if(New_Time!=last_tick.time) // Compare time
{
New_Time=last_tick.time; // Now the time is
New_Bar=true; // Caught a new bar
}
}But
something about the New_Bar variable becoming true every tick.

I must be getting the new bar time wrong somehow.
Обработчик события "новый бар"
Обработчик события "новый бар"
  • 2010.10.04
  • Konstantin Gruzdev
  • www.mql5.com
Язык программирования MQL5 позволяет решать задачи на совершенно новом уровне. Даже те задачи, которые уже вроде имеют решения, благодаря объектно-ориентированному программированию могут подняться на качественно новый уровень. В данной статье специально взят простой пример проверки появления нового бара на графике, который был преобразован в достаточно мощный и универсальный инструмент. Какой? Читайте в статье.
 
Khomtchenko:
But the New_Bar variable becomes true every tick.

I must be getting the new bar time wrong.

Because you take a new tick time each time, and of course it is not equal to the previous one.

And in the previous function you took the start time of the bar. So here too you should take the bar time, not the tick time.

 
I don't doubt it, but just to check the box, has anyone created the same EA in mql4 and mql5 and compared the test results? It should be perfect-similar if the code is properly transformed, shouldn't it? Or am I wrong?
Reason: