[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 392

 
alexeymosc:

Good evening!

Please advise me on the possible source of the error. I'm just learning the language, so I'm a little stumped.

The task in Expert Advisor code is to read data from .scv file (two values in a line, 400 lines) and write them into an array.

The problem is this: if I throw the EA on a chart, it prints an alert with the correct values from the array, but if I try to test the EA, it prints an alert "No file" in the log. That is, it seems it cannot access the file (although it's unbelievable) and writes values into the array (which is confirmed by another alert), but gets stuck on finding the file, according to the log. Confused. Below is a screenshot.

If a file is open, it should be closed, even if an error is received in working with it. I don't see any more errors so far.

It can be read like this:

signals_array[i][j] = FileReadDouble(Handle);
 
Reshetov:

In the tester and in the chart, the files are written and read in different directories:

  1. MetaTrader 4\tester\experts\files
  2. MetaTrader 4\experts\files

Yuri, respect! I have understood it now and fixed it.

Zhunko, thank you. I tried it that way, but I got an error something like can't read binary data from string file or something like that. Anyway, my construction works.

 
snail09_1:

Imho, I would not create an array of tickets to close, but in the market order enumeration loop check each order by feeding its ticket to the input of the closing function with a check of possible conditions.

Can you show this in the code?

I mean, how can this be implemented?

 

Good afternoon everyone!

Maybe this question is not for the newbies, but I couldn't find another thread where I could ask a question:

How can I unload a detailed report from MetaTrader 4 to have equity on the chart instead of balance? I don't know, if I uploaded it from MT4 or some other convenient way, would it be realistic? I don't know if I have the right balance or not, I just want to know the drawdown results.

I have no idea how to use this brokers.

 
belous:

Can you show it in code?

I mean, how can it be implemented?

Something like this?

int ticket;

for(int z=OrdersTotal()-1;z>=0;z--)
   {
   if(!OrderSelect(z,SELECT_BY_POS))
      {
      _GetLastError=GetLastError();
      Print(" OrderSelect(",z,",SELECT_BY_POS)-Error #",_GetLastError);
      continue;
      }
   if(OrderMagicNumber()==magic && OrderSymbol()==Symbol())
      {
      if((OrderType()==OP_BUY)||(OrderType()==OP_SELL))
          {
          // Проверим условие для закрытия, и если истинно          
              {
              ticket=OrderTicket();
              //Закрываем его
              }
           }
       }
    }
 

help please.

Here's the code


//-----------------Закрытие по истории в безубыток--------------------
   //---------------------расчет по истории ордеров номера очередной итерации----------------------------------------------- 
  Iteration = 0; // зануляем инерации перед их учетом в цикле по истории
  Sum_Loss = 0;  // суммарный убыток по этим итерациям

datetime 
Time_at_History_Current = 0,
Time_at_History_Previos = 0;     
 
 if(OrdersHistoryTotal() != 0)
   {
    for(int counter = OrdersHistoryTotal()-1; counter >= 0; counter--)
      {
       OrderSelect(counter, SELECT_BY_POS, MODE_HISTORY);
       if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         {
          if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            {
             if(OrderProfit() < 0) // если убыток по выбранному ордеру, то считаем суммарный и записываем время закрытия ордера
                                   // для последующего его анализа при подсчете количества итераций
                {
                 double lastLoss = OrderProfit();
                 Sum_Loss=Sum_Loss+lastLoss;  // считаем общий убыток по закрытым подряд убыточным ордерам
                 Time_at_History_Current = OrderCloseTime();
                } 
             
             //Print(" Time_at_History_Current_в цикле = ", TimeToStr(Time_at_History_Current, TIME_DATE|TIME_SECONDS));
             //Print(" Time_at_History_Previos_в цикле = ", TimeToStr(Time_at_History_Previos, TIME_DATE|TIME_SECONDS));
             
             if(Time_at_History_Current != Time_at_History_Previos) // если они не равны, то считаем итерации и делаем их равными
               {
                Time_at_History_Previos = Time_at_History_Current ;
                Iteration++;
                //Print("Iteration at History в условии сравнения  = ",  Iteration);
               }   
             else // они равны, то проверяем, дополнительно, наличие профита по выбранному следующему ордеру и выходим из цикла
               {
                if(OrderProfit() >= 0)
                  break;
               }
            }
         }
      }
   }

if (Sum_Loss < 0.0) { // Имеем убыток по закрытым позам
double money = Lots;
   BuyLots = GetBuyLotsSum();
        SellLots = GetSellLotsSum();
        if(BuyLots  > SellLots)money = BuyLots * 10;
        if(BuyLots  < SellLots)money = SellLots * 10;
  if (((AccountEquity() + Sum_Loss + (Sum_Loss / money)) >= AccountBalance()) && (((totalSell > 0) && (totalBuy < 1)) || ((totalSell < 1) && (totalBuy > 0)))) { // Достигли безубытка
    // Здесь какой-то код, который необходимо выполнить при достижении безубытка
        CloseAllBuy();
           CloseAllSell();
           Sum_Loss = 0.0;
           

I have no way to make a loop open when a deal was closed in minus and if the next order closed above zero, i.e. positive balance, but less than negative, we add plus to negative and get a new negative value, which is already less.

if(OrderProfit() >= 0 && Sum_Loss < 0.0)
                  double lastLoss_two = OrderProfit();
                 Sum_Loss=Sum_Loss+lastLoss_two;  // считаем общий убыток по закрытым подряд убыточным ордерам
                 Time_at_History_Current = OrderCloseTime();
               }

If it is more negative, according to the signal, we close the order and start the cycle from the beginning.


The situation is that when this code closes the deal in loss, then it remembers the minus balance, and when it closes the deal in the plus, and the plus is less than the balance, then it resets Sum_Loss and I need that it would not zeroed, and mowed down.

So this is how it works now:

it checks a closed order, if the profit of closed order is less than zero, then this profit is added to Sum_Loss, and so on until the profit of open trade exceeds (will be more than) Sum_Loss, when reached, the trade is closed, and Sum_Loss is zeroed and the cycle begins again.

I need:

order closed in minus, its minus profit was added to Sum_Loss, then if the next deal closed with a positive profit, Sum_Loss is reduced by the amount derived from the profit, which means that the next open order Sum_Loss is already a smaller amount, and so on until the order profit is greater than Sum_Loss, and then Sum_Loss is cleared and a new cycle starts.

Sum_Loss = 0;

1st closed order: Profit (-50) < 0

Sum_Loss + profit (Sum_Loss + (-50))

Sum_Loss = -50;

2nd closed order: Profit (+40) > 0 and Sum_Loss < 0

Sum_Loss + profit (Sum_Loss + 40)

Sum_Loss = -10


Maybe the Sum_Loss variable should be specified as a negative variable? in general I am confused. I have tried many variants, but I have not got the right result. I have tried a lot of variants and still do not get the right result.
 
How can I test an EA without taking the spread into account? Is this possible?
 
Max79:
How can I test an EA without taking the spread into account? Is it possible?
Google it and you will find it, for example here (set spread ? site:mql4.com) read: https://www.mql5.com/ru/forum/102224/page2
 

Who has such a turkey?

 

Please help.

I put a modifier of pending orders, in the EA, and it gives me an error - 1 when testing in the Journal.

I.e. - "If I pass unchanged values as function parameters, error 1 (ERR_NO_RSULT) will be generated".

I put a check before modification, but it doesn't help. What is the error? The EA is being tested, but how can I sift out orders with unchanged values?