Need help

 

The problem is
I practically don't know the language, I need to automate the opening of orders for a few vp, I put out this simple code (file attached), but it turned out to be clumsy,
According to the plan should open 6 vp, but opens only 3 vp, but sometimes opens all 6, but then again no longer works as it should (I think this may be due to the number of digits after the decimal point, as in the block, where there is no JPY, all works fine.
Please help solve this problem.
If i'm not hard i need help to write it so i can switch trades to Buy or Sell only.

file: DANGER FILE DELETED

Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Информация об инструменте - Состояние окружения - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Sergey Korsunov:

The problem is
I practically don't know the language, I need to automate the opening of orders for a few vp, I put out this simple code (file attached), but it turned out to be clumsy,
According to the plan should open 6 vp, but opens only 3 vp, but sometimes opens all 6, but then again no longer works as it should (I think this may be due to the number of digits after the decimal point, as in the block, where there is no JPY, all works fine.
Please help solve this problem.
If i'm not hard i need help to write it so i can switch trades to Buy or Sell only.

file: DANGER FILE REMOVED

The file should be attached using the button Attach file.

 
ok
Files:
Test_3.mq4  7 kb
 
Sergey Korsunov:

The problem is
I practically don't know the language, I need to automate the opening of orders for a few vp, I put out this simple code (file attached), but it turned out to be clumsy,
According to the plan should open 6 vp, but opens only 3 vp, but sometimes opens all 6, but then again stops working as it should (I think this may be due to the number of decimal places in the price, as in a block with no JPY, all works fine.
Please help solve this problem.
And also, if it's not difficult prompt how to prescribe, that it was possible to switch the opening of trades only Buy or Sell.

There are a number of reasons that prevent you from opening an order. Suppose, on the first tick, 3 orders are opened

On the next tick, at the very beginning of the program, if(OrdersTotal() >= OrderCount) return; this will be returned since the number of orders is greater than OrderCount, which = 1.

The rest of the program will be ignored.

Judging by these lines:

//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"

The program was developed by MetaQuotes Software Corp. Ask them for advice!

Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
Открой новые возможности в MetaTrader 5 с сообществом и сервисами MQL5
  • www.mql5.com
MQL5: язык торговых стратегий для MetaTrader 5, позволяет писать собственные торговые роботы, технические индикаторы, скрипты и библиотеки функций
 
a007 #:

There are a number of reasons that prevent an order from opening. Suppose that on the first tick, 3 orders are opened

On the next tick, at the very beginning of the program, if(OrdersTotal() >= OrderCount) return; this will be returned since the number of orders is higher than OrderCount, which = 1.

The rest of the program will be ignored.

Judging by these lines:

The program was developed by MetaQuotes Software Corp. Please consult them!

Do you mean that extra orders are opened?

 
Fast235 #:

do you mean that extra orders are opened?

No, on the contrary, you need 6 different currency pairs and only 3 are opened

And by the way, where there is no yen bullion, all 6 pairs open, both main and crosses, where there is a yen bullion, only 3 open

 
Sergey Korsunov #:

No, on the contrary, you need 6 different currency pairs and only 3 are opened

The easiest way is to put Sleep() after each order opening, the terminal does not have time to update the quantity (for performance reasons apparently)

 
Fast235 #:

the easiest way is to put Sleep() after each order is opened, the terminal has no time to update the quantity

I practically do not understand the language (
I wrote my code purely on the examples on the web
Help me put Sleep() in my code

 
Sergey Korsunov #:

I have almost no knowledge of the language (
wrote the code purely from examples on the web
Help insert Sleep() in my code

After OrderSend and put Sleep(50);

if it doesn't help 50 increase to 100-200

 
Fast235 #:

after OrderSend and put Sleep(50);

If it doesn't work 50 increase to 100-200

did not help ((

 
Sergey Korsunov #:

didn't help ((

Try it this way - Shorter and more precise. If you figure it out on your own, you'll be a coryphaeus of programming. Put your cursor on the word and press F1

//+------------------------------------------------------------------+
//|                                                       Test 3.mq4 |
//+------------------------------------------------------------------+
#property strict

extern double Lot   = 0.01;
extern int    Slip  = 3;
extern int    Magic = 777;

string name[10]={"AUDJPY","CHFJPY","CADJPY","AUDCAD","AUDCHF","CADCHF"};
int    cnt[6];

void OnTick()
{
   ArrayInitialize(cnt, 0); // Обнуление счетчиков

   // Подсчет ордеров по каждому торговому инструменту
   for(int n=OrdersTotal()-1; n>=0; n--)
   {
     if(!OrderSelect(n,SELECT_BY_POS))continue;
     for(int k=0; k<6; k++) if(OrderSymbol()==name[k]) cnt[k]++;
   }

   // Открытие ордеров по каждому торговому инструменту
   for(int k=0; k<6; k++) if(!cnt[k]) int ticket = OrderSend(name[k],OP_BUY, Lot, MarketInfo(name[k],MODE_ASK), Slip, 0, 0, "", Magic);
}