[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 360

 
veti-k:

No, that's too much. What is more volatile from at least 20-50 pips
USDJPY
 

Guys, can you advise:

When testing the advisor on standard indicators included in MT4 delivery on currency pairs - no questions - everything works according to the trading algorithm.

When testing on metals, such as silver and gold, the orders are not opened, in the Strategy Tester Journal they write zero division.

I have the same input parameters, the history for this five-digit brokerage company (forex4yu) has been uploaded for the tested instruments.

What is the possible reason? I do not want to send my EA to a telepath. I wrote the Expert Advisor personally according to the version of the book.

 
Roman.:

Guys, can you advise:

When testing the advisor on standard indicators included in MT4 delivery on currency pairs - no issues - everything works according to the trading algorithm.

When testing on metals, such as silver and gold, the orders are not opened, in the Strategy Tester Journal they write zero division.

I have the same input parameters, the history for this five-digit brokerage company (forex4yu) has been uploaded for the tested instruments.

What is the possible reason? I do not want to send my EA to a telepath. I wrote the Expert Advisor personally according to the version of the book.

Whenever dividing by a variable, you must first check that it is not equal to zero.
 
Roman.:

Guys, can you advise:

When testing the advisor on standard indicators included in MT4 delivery on currency pairs - no issues - everything works according to the trading algorithm.

When testing on metals, such as silver and gold, the orders are not opened, in the Strategy Tester Journal they write zero division.

I have the same input parameters, the history for this five-digit brokerage company (forex4yu) has been uploaded for the tested instruments.

What is the possible reason? I do not want to send my EA to a telepath. I wrote the Expert Advisor personally according to the version of the book.


You should see the code. In general, you can (in Notepad++) automatically mark all places where a division sign occurs in the code and see if division by zero actually occurs in some case.
 
drknn:

I'd love to see the code. And in general, you can (in Notepad++) automatically mark all places where division sign appears in the code and check if in some case division by zero actually occurs.


Yes, I'm already looking at the prints where the unpacking has reached, everything is fine there...

In the function of volume normalisation for metals there was this error (division by zero), now it is not present, there was another 131 - incorrect volume, although set obviously = 0,01 lot, I look in general...

For currencies, this volume normalization function works correctly.... Maybe there is a common for them (for metals and currencies)?

//--------------------------------------------------------------------
// Lot_MM.mqh
// 
//--------------------------------------------------------------- 1 --
// Функция вычисления количества лотов.
// Глобальные переменные:
// double Lots_New - количество лотов для новых ордеров (вычисляется)
// double Lots     - желаемое количество лотов, заданное пользовател.
// double  MaksRisk  - процент риска
// Возвращаемые значения:
// true  - если средств хватает на минимальный лот
// false - если средств не хватает на минимальный лот
//--------------------------------------------------------------- 2 --
bool Lot_MM()                            // Позовательская ф-ия
  {
   int time, ticket;                  // Наибольшее время открытия и номер ордера
   double orderLots;                  // Lots   
   double orderProfit;                // Profit
   double Price;                      // Цена открытия рыночного ордера
   double SL;                         // Значение StopLoss ордера
   double  TP;                        // Значение TakeProfit ордера
   string Symb   =Symbol();                    // Финансовый инструм.
   double One_Lot=MarketInfo(Symb,MODE_MARGINREQUIRED);//Размер свободных средств, необходимых для открытия 1 лота
   double Min_Lot=MarketInfo(Symb,MODE_MINLOT);// Мин. размер. лотов
   double Max_Lot =MarketInfo(Symbol(),MODE_MAXLOT);
   double Step   =MarketInfo(Symb,MODE_LOTSTEP);//Шаг изменен размера
   double Free   =AccountFreeMargin();         // Свободные средства
   double LotVal =MarketInfo(Symbol(),MODE_TICKVALUE);//стоимость 1 пункта для 1 лота
   

//--------------------------------------------------------------- 3 --
   if (Lots>0)                                 // Лоты заданы явно..
{                                              // ..проверим это
      double Money=Lots*One_Lot;               // Стоимость открываемого ордера   
      if(Money<=AccountFreeMargin())             // Средств хватает..     
         {  
          Lots_New=Lots;                           // ..принимаем заданное
            // else                                     // Если не хватает..
            // Lots_New=MathFloor(Free/One_Lot/Step)*Step;// Расчёт лотов 
            Print("Функция Lot_MM: Lots_New  = ", Lots_New);    
...
...
...
...
 // ---------НОРМАЛИЗУЕМ НОВЫЕ РАСЧЕТНЫЕ ЛОТЫ И ОТКРЫВАЕМ ОЧЕРЕДНУЮ ПОЗИЦИЮ...            
                    Lots_New = NormalizeLots(Lots_New);  
   return(true);                               // Выход из польз. ф-ии
  }
//--------------------------------------------------------------- 6 --

//+------------------------------------------------------------------+
//| Нормализация лота                                                |
//+------------------------------------------------------------------+

double NormalizeLots(double lot)
{
   double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
   double lots = NormalizeDouble(lot / lotStep, 0) * lotStep;   
   lots = MathMax(lots, MarketInfo(Symbol(), MODE_MINLOT));
   lots = MathMin(lots, MarketInfo(Symbol(), MODE_MAXLOT));   
   return (lots);
}
 

I can't understand: it prints the top line, but the order doesn't open with error 131 - wrong volume, I've already set 0.1 and 0.01...

 Print ("Функция открытия ордера с рынка - продажа: Teeth = ",  NormalizeDouble(Teeth,Digits), " upfractal = ", upfractal," Цена Bid = ", NormalizeDouble(Bid,Digits), " Lots_New = ", NormalizeDouble(Lots_New,2));                
Ticket=OrderSend(Symbol(),1,0.01,Bid,50,0,0,"Antiunity-start",Magic,0,Red);    

 
Techno:
Whenever dividing by a variable, you must first check that it is not equal to zero.

Thanks, I'll keep that in mind in the future. It's just that this time I took a ready-made volume normalisation function.
 

No use so far... Writes the same error...

 Print ("Функция открытия ордера с рынка - продажа: Teeth = ",  NormalizeDouble(Teeth,Digits), " upfractal = ", upfractal," Цена Bid = ", NormalizeDouble(Bid,Digits), " Lots_New = ", NormalizeDouble(Lots_New,2));                
          Ticket=OrderSend(Symbol(),1,Lots_New,Bid,50,0,0,"Antiunity-start",Magic,0,Red);            
          Print ("Функция открытия ордера с рынка - продажа: старт");      

I opened a position for gold on my account in the tester with 10,000 and 0.01 and 0.1 lots - to no avail.

Perhaps someone had a similar issue? A tip, plz...

 

Add my lot checking function to your custom subroutines. And call it before each OrderSend(). Rounding in my dll is done by the laws of mathematics: If the rounded number ends in fractional part with number >=5, then rounded up. If <=4, then it's rounded down. As far as I understood programming languages have problems with this for some reason - I had to make my own dll-code. Basically, the code is very simple, but I searched the Internet quite a lot at my time, before I found the optimal solution. Do you need the source code of the dll?

// ============ ProverkaLota() =====================================================================
// функция принимает нормализует лот ордера
//-----------------------------------------------------
double ProverkaLota(double LotOrdera,string SMB){
  double SMB_MinLot=MarketInfo(SMB,MODE_MINLOT);
  double SMB_MaxLot=MarketInfo(SMB,MODE_MAXLOT);
  double SMB_LotStep=MarketInfo(SMB,MODE_LOTSTEP);
  LotOrdera=OkruglenieDoSotykh(LotOrdera);// округляем до сотых

 if(SMB_LotStep==0.1){// округляем до десятых
   LotOrdera/=10;
   LotOrdera=OkruglenieDoSotykh(LotOrdera);
   LotOrdera*=10;// возвращаем дробную часть ордера на место
 }
 if(LotOrdera<SMB_MinLot){
   LotOrdera=SMB_MinLot;
 }
 if(LotOrdera>SMB_MaxLot){
   LotOrdera=SMB_MaxLot;
 }
 return(LotOrdera);
}
// =================================================================================================
Files:
basic_dll_1.zip  190 kb