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

 
Hello dear programmers!

There is a need for the following analysis - the program should analyse the parameters given to it and output the result in a separate window in the form of a table with a set of dates. It means the program should analyze the history and display the necessary dates.

Is it possible to do this in MQL4 or it's better to export the history and analyze the data using a program written in another language?

Thank you in advance!
 
GygaByte:


Correct, but as practice has shown - not always.

If the fifth decimal point = 5 (1.xxxx5), the value is still distorted:

the question is still valid...

P.S. In general, I need to assign a price value to MagicNumber... And type MagicNumber - int, here and try to convert by

Who else can give me advice?

Thank you.

You're outputting with different rounding - so you don't see the full number - and you think something is distorted. By default, when outputting real numbers, the output is rounded to the 4th digit. For 5-digit numbers, you must round the output explicitly:

Alert ("bid= ",bid," bid_minus= ",DoubleToStr(bid_minus,Digits)," bid_plus= ",DoubleToStr(bid_plus,Digits), " Bid = ",DoubleToStr(Bid,Digits));

Look at your own picture - output bid without DoubleToStr() and with DoubleToStr().

 
hoz:

Artyom and Boris, thank you for "chewing up" my question. I have periods when I can get stuck on fairly simple things, as was the case this time...

Now there's a new question.

I have added to the function that calculates the amount of open orders t, searches for orders of a specified type with specified profits and compares their profits with some specified value (currently 0). Furthermore, if there are no open orders, 2 flags with value True are returned with function FindOrders() parameters, it means you can send an order, but if there are orders, profit is checked to make sure it is higher than the set value, if it is lower than the set value, 2 flags with value False are returned with function FindOrders() parameters, so when there are losing orders in some direction, there is no investments into the losing direction.

After that I call the FindOrders() function in the signal function:

Orders have moved open at all. The logic seems to be correct. Maybe, can you see where I have made a mistake?

I understand that everything can be done easier with a separate function and I can do it. But I want to understand why it doesn't work in this version.

Victor, I can't fully understand your algorithm, but I can give you some advice! It happens to me too, when there is an error in the logic. The program stalls if it turns out to be ambiguous or mutually exclusive in your conditions. Maybe you know what you want, but can't build the logic of the code correctly. Look for these glitches, and write down the whole order in which you want the conditions to be executed, one by one on a piece of paper with arrows for clarity! Good luck!
 
borilunad:
Victor, I can't fully understand your algorithm, but I can give you some advice! This also happens to me when there is an error in logic. The program stalls if it turns out to be ambiguous or mutually exclusive in your conditions. Maybe you know what you want, but can't build the logic of the code correctly. Look for these glitches, and write down the whole order in which you want the conditions to be executed, one by one on a piece of paper with arrows for clarity! Good luck!


So there's a simple logic there. If there are no orders open, the orders will be opened by the signal.

And if there are orders open, then the orders should be opened by a specific signal, if the profit of the orders in a given direction (buy or sell) is higher than a certain value, i.e. at least not in minus. (I have set 0 there for testing).

I have found one logical error. Here is what has come out:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     if (OrderProfit() < 0)        // Если профит ордера ниже заданного значения,..
                         long = false;              // .. покупка запрещена
                 }

                 if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     if (OrderProfit() < 0)        // Если профит ордера ниже заданного значения,..
                         short = false;             // .. продажа запрещена
                 }
                 t++;
              }
   }
   
   return (t);
}

//+-------------------------------------------------------------------------------------+
//| Получаем общий торговый сигнал                                                      |
//+-------------------------------------------------------------------------------------+
int GetGeneralSignal()
{
   bool short = true,
        long = true;
        
   if (FindOrders(short, long) > 3)
       return (-1);

   if (GetRSI(1) < i_RSIToUpLimit)
      if (GetRSI(0) > i_RSIToUpLimit)
      {
         if (long == true)
             return (SIGNAL_BUY);
      }

   if (GetRSI(1) > i_RSIToDnLimit)
      if (GetRSI(0) < i_RSIToDnLimit)
      {
         if (short == true)
             return (SIGNAL_SELL);
      }
            
   return (-1);
}

Now the sell orders open on the sit correctly, but the longs don't open at all. Although the flag has the value of both variables 1 i.e. true.

 

I have this problem with mt4.

With the launch of the mt4 broker software (namely the 3 I've been using for the last week) on my computer I get a "Run as user" window on my computer (same as using "run as user"). With any action selection mt4 opens normally.

How can i get mt4.eh back to running without this window? Maybe who knows or understands what's wrong...

 

Good afternoon, encountered the need to quickly cancel all pending orders. OrderClose ignores the pending orders. Which operator is more convenient to use, and is this option available?

 
Notter:

Good afternoon, encountered the need to quickly cancel all pending orders. OrderClose ignores the pending orders. Which operator is more convenient to use, and is this option available?


You can close only market orders and you need the OrderDelete operator to delete the pending orders.
 

hoz

Thank you!

 
hoz:


So, everything is simple in its logic. We need that if there are no orders open, the orders will be opened by the signal.

And if there are orders open, then the orders should be opened by a specific signal, if the profit of the orders in a given direction (buy or sell) is higher than a certain value, i.e. at least not in minus. (I have set 0 there for testing).

I have found one logical error. Here is what has come out:

Now the sell orders are opening on the sit correctly, but the longs are not opening at all. Although the flag has value of both variables 1, i.e. true.

Victor, do some checking! By commenting out the long-buy, look in the log to see how the short-sell works! And vice versa, then see what the difference is and find out why it doesn't work!
 
borilunad:
Victor, let's check it! By commenting out the long side, check how the short side works in the log! And vice versa, then see what the difference is and find why it doesn't work!


Boris, if you comment out one of the conditions in int GetGeneralSignal(), the opening is clear.

I have tracked it. The flag does not change its value when the profitability of currently open orders is in deficit. Here is the rewritten function that should set the values of flags short and long to false, i.e. prohibit us from opening a position if there are minus orders:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
int FindOrders(bool& long, bool& short)
{
   int t, total = OrdersTotal() - 1;
   double profitL,               // Профит лонговой позиции
          profitS;               // Профит шортовой позиции
   
   for (int i=total; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
          if (OrderSymbol() != Symbol()) continue;
              if (OrderMagicNumber() != i_magic) continue;
              {
                 if (OrderType() == OP_BUY)        // Найден ордер типа OP_BUY
                 {
                     Print("if (OrderType() == OP_BUY)");
                     profitL = OrderProfit();
                     if (profitL < OrderProfit())
                         if (profitL < 0)
                         long = false;
                 }

                 if (OrderType() == OP_SELL)       // Найден ордер типа OP_SELL
                 {
                     Print("if (OrderType() == OP_SELL)");
                     profitS = OrderProfit();
                     if (profitS < OrderProfit())
                         if (profitS < 0)
                         long = false;
                 }
                 t++;
              }
   }
   
   return (t);
}

Here is the calling function:

//+-------------------------------------------------------------------------------------+
//| Получаем общий торговый сигнал                                                      |
//+-------------------------------------------------------------------------------------+
int GetGeneralSignal()
{
   bool short = true,
        long = true;
        
   if (FindOrders(short, long) > 15)
       return (SIGNAL_NO);

   Print("long = ", long);
   Print("short = ", short);
      
   if (GetRSI(1) < i_RSIToUpLimit)
      if (GetRSI(0) > i_RSIToUpLimit)
      {
         if (long == true)
             return (SIGNAL_BUY);
      }
           
   if (GetRSI(1) > i_RSIToDnLimit)
      if (GetRSI(0) < i_RSIToDnLimit)
      {
         if (short == true)
             return (SIGNAL_SELL);
      }
            
   return (SIGNAL_NO);
}