Learning and writing together in MQL5 - page 12

 
When global variables are declared in the EA and then it is tested, the global variables do not appear in /Service/ -> /Global Variables/ of the terminal?
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
Документация по MQL5: Основы языка / Переменные / Глобальные переменные
  • www.mql5.com
Основы языка / Переменные / Глобальные переменные - Документация по MQL5
 

m_a_sim:
Когда объявляются глобальные переменные в советнике, а потом он тестируется, то глобальные переменные не появляются в /Сервис/ -> /Глобальные переменные/ терминала?

In your question there is a direct link to the 'Global Variables' section. See the Note for this section.
 
Yedelkin:
In your question there is a direct link to the'Global Variables' section. Look at the Note to this section.
there is a reference to global variables that are declared globally, i.e. not locally, and I mean GlobalVariableSet() variables
 
Can anyone give you a good code to calculate the lot, which depends on the risk, i.e. if you close at a given lot, 5% of the balance will be lost (for example). 5% is the risk
 

m_a_sim:
там сылка на глобальные переменные, которые объявлены глобально, т.е. не локально, а я имею ввиду переменные  GlobalVariableSet()

Unfortunately, I can't say anything about the case when GlobalVariableSet() variables are declared in the EA.
 
m_a_sim:
If you can give a competent code for calculating the lot, which depends on the risk, i.e. when closing on the L for a given lot will be lost (for example) 5% of the balance. 5% is the risk.

Such a question has been raised several times on the forum. If I remember correctly, one of the solutions was suggested in this thread in the spring.

 
Yedelkin:

This question has been raised several times in the forum. Have a look through the search engine. If I remember correctly, in the spring one of the solutions was suggested in this thread.

I found the code I need but it is for mql4, can someone help me to modify it to mql5?

extern double ExtMaximumRisk=0.05;             // 5% by default
 
//--- calculate current volume
double CalculateVolume()
  {
   double lot_min =MarketInfo(Symbol(),MODE_MINLOT);
   double lot_max =MarketInfo(Symbol(),MODE_MAXLOT);
   double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP);
   double contract=MarketInfo(Symbol(),MODE_LOTSIZE);
   double vol;
//--- check data
   if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0) 
     {
      Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
      return(0);
     }
   if(AccountLeverage()<=0)
     {
      Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
      return(0);
     }
//--- basic formula
   vol=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract,2);
//--- additional calculation
//   ...
//--- check min, max and step
   vol=NormalizeDouble(vol/lot_step,0)*lot_step;
   if(vol<lot_min) vol=lot_min;
   if(vol>lot_max) vol=lot_max;
//---
   return(vol);
  }
 
m_a_sim:

Yes I found the code I need, but it is in mql4, can someone help me to modify it to mql5?

No, on mql5.com website all the codes were designed in MQL5.
 
Yedelkin:
No, at mql5.com all the codes were designed in MQL5.
that's not what we're talking about
 
m_a_sim:
That's not what we're talking about.

Strange. You need code for MQL5, which should already be on the website. All you have to do is look it up. That's exactly what I'm talking about.

However, it is up to you.