[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 814

 
Open[1] Close[1]
 

Balance 600-1199 lot 0.1

Balance 1200-1799 lot 0.2

Balance 1800-2399 lot 0.3 etc.

How to organize in the EA? Thank you.

 
Maniac:

Balance 600-1199 lot 0.1

Balance 1200-1799 lot 0.2

Balance 1800-2399 lot 0.3 etc.

How to organize in the EA? Thank you.

double Lot()
{
   double balance=AccountBalance();
   if (balance>600 && balance<1199) return(0.1);
   if (balance>1200 && balance<1799) return(0.2);
   if (balance>1800 && balance<2399) return(0.3);
return(MarketInfo(Symbol(), MODE_MINLOT));
}
 

call: ticket=OrderSend(Symbol(),OP_BUY,Lot(),Ask,3,Bid-25*Point,Ask+25*Point, "My order #",magic,0,CLR_NONE);
 
IgorM:

Call: ticket=OrderSend(Symbol(),OP_BUY,Lot(),Ask,3,Bid-25*Point,Ask+25*Point, "My order #",magic,0,CLR_NONE);

At the same time, the balance may be in the clouds, and equity may be in a big drawdown. Therefore, the lot size may appear to be larger than it can be opened and the whole structure will go overboard...

Before opening it is better to correct the lot for the real possible.

I made a function for this purpose. It was slightly corrected by Viktor(Vinin) - try it:

// ===========================================================================
// --- Функция рассчёта величины лота для открытия позиции. Редакция VininI---
// Если лот превышает возможный для открытия позы, то он корректируется 
// ===========================================================================

double CorrectLots(double lt)
{
   double ltcorr;
   double pnt =      MarketInfo(Symbol(),MODE_POINT);
   double mspr =     MarketInfo(Symbol(),MODE_SPREAD);
   double dig =      MarketInfo(Symbol(),MODE_DIGITS);
   double MaxLot =   MarketInfo(Symbol(),MODE_MAXLOT);
   double MinLot =   MarketInfo(Symbol(),MODE_MINLOT);
   double StpLot =   MarketInfo(Symbol(),MODE_LOTSTEP);
   double OneLot =   MarketInfo(Symbol(),MODE_MARGINREQUIRED);
   double TradeMrg = NormalizeDouble(AccountFreeMargin()/4.0,dig);    // Свободные средства, разрешенные к торговле
   
   
   double Money=lt*OneLot+mspr*pnt;          // Вычисляем стоимость открываемой позы
   if (Money>=TradeMrg)                      // Если цена позиции равна или больше, чем есть свободных средств, то ...
      {
         lt=MathFloor(TradeMrg/OneLot/StpLot)*StpLot;  // ... рассчитаем допустимый лот
         Print("Func CorrectLots: полученный лот ",lt," скорректирован под допустимый ",lt); 
      }
      else 
         Print("Func CorrectLots: лот вернули без изменений");
   lt=MathMin(MaxLot, MathMax(MinLot, lt)); // Проверим превышение допустимых ...
   
   return(lt);                            
}

In the line.

double TradeMrg = NormalizeDouble(AccountFreeMargin()/4.0,dig);    // Свободные средства, разрешенные к торговле

... Free margin is divided by four and only a quarter of the free funds are considered eligible for trading.

You can remove division by 4 and put as much as you want, even use all margin.

But the function will not let you use a lot size larger than allowed.

 
artmedia70:
At the same time, the balance may be in the clouds, while the equity is in the large drawdown. Respectively, the lot size may appear to be larger than it can be opened and the whole structure will go overboard...


Why is everything so sad...

the last return() in my function will give the minimum lot available for the instrument. If the account is a cent one with a big leverage, then when the balance is less than 600, the Expert Advisor may trade some more time :)

SZZY: the problem is specific and the branch is to give direction to the questioner.

 
IgorM:


why is it so sad...

the last return() in my function will give the minimum lot available for the instrument. If the account is a cent one with a big leverage, then when the balance is less than 600, the Expert Advisor may trade some more time :)

SZZY: The problem is specific, and the branch to give direction to the questioner

Well, forgive me generously... :) Don't be angry, sir... :)

Here is a function in my version:

// ==========================================================================
// ------------ Функция рассчёта величины лота для открытия позиции ---------
// Если лот превышает возможный для открытия позы, то он корректируется 
// ==========================================================================

double CorrectLots(double lt)
{
   double ltcorr;
   double pnt =      MarketInfo(Symbol(),MODE_POINT);
   double mspr =     MarketInfo(Symbol(),MODE_SPREAD);
   double dig =      MarketInfo(Symbol(),MODE_DIGITS);
   double MaxLot =   MarketInfo(Symbol(),MODE_MAXLOT);
   double MinLot =   MarketInfo(Symbol(),MODE_MINLOT);
   double StpLot =   MarketInfo(Symbol(),MODE_LOTSTEP);
   double OneLot =   MarketInfo(Symbol(),MODE_MARGINREQUIRED);
   double TradeMrg = NormalizeDouble(AccountFreeMargin()/4.0,dig);      // Свободные средства, разрешенные к торговле
   
   lt=MathAbs(lt);
   ltcorr=lt;                       // Зададим начальное значением ltcorr равным значению lt
   
   if (lt>=MaxLot) ltcorr=MaxLot;   // Проверим превышение допустимых ...
   if (lt<=MinLot) ltcorr=MinLot;   // ... значений лота
   
   double Money=lt*OneLot+mspr*pnt; // Вычисляем стоимость открываемой позы

   if (Money<TradeMrg)              // Если свободных средств больше, чем цена позиции - 
      {
         return(ltcorr);            // ... возвращаем неизменённый лот
      }
   else if (Money>=TradeMrg)        // Если цена позиции равна или больше, чем есть свободных средств, то ...
      {
         ltcorr=MathAbs(MathFloor(TradeMrg/OneLot/StpLot)*StpLot);       // ... рассчитаем допустимый лот
         double MoneyCorr=ltcorr*OneLot+mspr*pnt;                      
         Print("Func CorrectLots: лот ",lt," скорректирован до ",ltcorr,
               " Стоимость позы до корректировки = ",Money,
               " Стоимость позы после корректировки = ",MoneyCorr
               ); 
         return(ltcorr);                                                 // ... и вернём его значение
      }
   Print("Func CorrectLots: лот вернули без изменений");
   return(ltcorr);                                                       // Возврат изначального лота в непредусмотренных случаях с сообщением
}
 
IgorM:


Why is it so sad...

the last return() in my function will give the minimum lot available for the instrument. If the account is a cent one with a big leverage, then when the balance is less than 600, the Expert Advisor may trade some more time :)

SZZY: the problem is specific, and the branch to give direction to the questioner

You see, Igor, the man asked you a question, you gave him the right answer, and you can kind of forget about it. But dancing on the balance is not good. For the very reason that the balance may be in the sky, and the real situation - it is time to save. And here we are, hr-r-r-r-r-ing... ...and a big lot on top of the order... and he's down... Equity, too, even though it's already
already there... So I told you that it would be better to rely on equity rather than balance... :)

 

Good day!

Can you please advise a newbie, is it possible to writea custom indicator in MQL4 , so it can simultaneously handle all currency pairs? As far as I understand, the maximal number of lines in an indicator chart is 8, but I need only one line. I.e. can I get an array of arrays or variables for all currency pairs simultaneously for this line?

Thanks in advance for the answer.

 
Igor_Sev:

I.e. can I get an array for this line processed from arrays or variables on all currency pairs at the same time?


Theoretically, I don't see any obstacles. Another question is whether you can specifically process this array.
 
Roger:

Theoretically, I do not see any obstacles. Another question is whether you will be able to process this array.


How can I address all currency pairs in the program code when writing a tool? I looked through the examples of writing a tool, there is no reference to a currency pair, the one that is linked to a specific quote chart is processed by default.

The thing is that now Excel and VBA do it all, I get information on 22 currency pairs through DDE server and by using VBA code I mean simultaneous processing, but it is not convenient, because firstly I have to wait 2 hours for data history accumulation to perform analysis by Excel charts. And it's not convenient to jump from one program to another, that's why I think how to transfer it all to MT4.