Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1356

 
Lerchik:

So what you are saying is that opening a market order at Ask will equal opening a BuyLimit order.

Something is not right here. Suppose the Bid price is equal to 1.4500. So, when we open a Buy order from the market, it will stand at the Ask price and ask price of Bid is, let's say, 10 points.

Then the order will stand at 1.4510.

Now BuyLimit order is equal to 1.4500. And the price falls 10 points lower than the Ask price on Ask will open an order. Not by Bid but by Ask.

It does not fit together a bit. They are different things and cannot be compared like that.

Maybe, I am wrong?

All buy orders are opened by Ask and closed by Bid, and vice versa for sell orders.

If you are too lazy to read it, open a demo account and practice.

 
Сергей Таболин:

Why don't you start by reading the documentation?

Here's what's in the documentation:

Pending order

A pending order is an instruction from a brokerage company to buy or sell a financial instrument at a future date at specified conditions. There are the following types of pending orders:

  • Buy Limit- trade request to buy at the Ask price that is equal to or lower than that specified in the order. The current price level is higher than the value in the order. Usually this type of orders is placed in the expectation that the security price will start to grow when falling to a certain level;

But I do not understand what is written here and how it works.

That is, the price will fall below the bylimit and an Askom will open an order. But at the same time the order will be opened at the same price or higher?

There is nothing about this anywhere. There are only rules. No one here wants to explain why.

So I am trying to achieve something.

 
Lerchik:

Here's what's in the documentation:

Pending order

A pending order is an instruction from a brokerage company to buy or sell a financial instrument at specified conditions in the future. There are the following types of pending orders:

  • Buy Limit- trade request to buy at the Ask price that is equal to or lower than that specified in the order. The current price level is higher than the value in the order. Usually this type of orders is placed in the expectation that the instrument price will start to grow when falling to a certain level;

But I do not understand what is written here and how it works.

That is, the price will fall below the bylimit and an Askom will open an order. But at the same time the order will be opened at the same price or higher?

There is nothing about this anywhere. There are only rules. No one here wants to explain why.

So, I want to achieve something.

BuyLimit may be set ONLY below the Ask price. SellLimit can ONLY be set higher than the Bid price.

BuyStop can ONLY be set above Ask price. SellStop can ONLY be set below the Bid price.

When the corresponding price reaches the corresponding order, it will be activated and the corresponding position will be created.

 
Lerchik:

Here's what's in the documentation:

Pending order

A pending order is an instruction from a brokerage company to buy or sell a financial instrument at specified conditions in the future. There are the following types of pending orders:

  • Buy Limit- trade request to buy at the Ask price that is equal to or lower than that specified in the order. The current price level is higher than the value in the order. Usually this type of orders is placed in the expectation that the instrument price will start to grow when falling to a certain level;

But I do not understand what is written here and how it works.

That is, the price will fall below the bylimit and an Askom will open an order. But at the same time the order will be opened at the same price or higher?

There is nothing about this anywhere. There are only rules. No one here wants to explain why.

So I am reaching for something.

Open a demo account and try it out.

TheBuy Limit is set below the current Ask price and will be opened when theAsk is lower

Buy Stop is set above the current Ask price and will open whenAsk rises

Buy opens at the current Ask price

 
MakarFX:

Open a demo account and practice.

Buy Limit is set below the current Ask price and will open whenAsk drops

The Buy Stop is set above the current Ask price and will open whenthe Ask rises

Buy opens at the current Ask price

That is something.

Moving on...

Ok, the Bid price has fallen below the Ask price and the Ask opens the order. But will the order price remain the same as it was set in the order or will it be different?

 
Lerchik:

That's something.

Moving on...

OK, the bid price has fallen below the price of the order and the Ascom has opened the order. But will the order price stay the same as it was set in the order or will it be different?

1 The Ask price should fall to the "Odds" price

2 Price remains

 
MakarFX:

1 Ascending price should fall to the price of the pause.

2 Price remains

Thank you very much for the clarification.

I was wondering why it wasn't working the way I wanted it to.

 

Good afternoon everyone.

As far as I understood from the answers to my previous question, I just need to handle errors, which may occur when opening orders, that is the first thing. Second, I need to protect the EA from crashing the server with every tick in case of an error.

First question, please tell me how to do the error handling?

Second question - how to protect yourself from the server's pounding?

Now my trades are opened like this

   /*УСЛОВИЕ 1*/
   if(flag_screen1==en_vbIkl_screen1 &&flag_screen2==en_vbIkl_screen2)
   { // НАЧАЛО УСЛОВИЕ 1
   if(ao_buy!=EMPTY_VALUE && count_orders_market_buy ==0)
   {
    if(OrderSend(Symbol(),OP_BUY,lot,Ask,slippages,Bid-sl,Bid+tp ,comment_ao_market_buy)) Print("Buy Open"); // ОТКРЫВАЕМ БАЙ ОРДЕР
   }
   } // КОНЕЦ УСЛОВИЕ1

// И ОТЛОЖКИ ВОТ ТАК

   /*УСЛОВИЕ 1*/
   if(flag_screen1==en_vbIkl_screen1 &&flag_screen2==en_vbIkl_screen2)
   { // НАЧАЛО УСЛОВИЕ 1
   
   if(ao_buy!=EMPTY_VALUE && count_orders_stop_buy ==0&& max_Price>Bid)
   { //НАЧАЛО ПРОВЕРКИ УСЛОВИЯ 1 НА ОТКРЫТИЕ
   
   Print("БАЙ СТОП AO УСЛОВИЕ 1");
        if( OrderSend(Symbol(),OP_BUYSTOP,lot,max_Price,slippages,max_Price-sl,max_Price+tp ,comment_ao_otloj_buy,Magik_number,TimeCurrent()+order_life_time))Print("BUY_STOP OPEN"); // ОТКРЫВАЕМ ОТЛОЖЕННЫЙ БАЙ ОРДЕР
   
   }  //КОНЕЦ ПРОВЕРКИ УСЛОВИЯ 1 НА ОТКРЫТИЕ
   } // КОНЕЦ УСЛОВИЕ1



The variable Count Market Buy is calculated using this function

         void data_orders(string comment="alt",int magik_number=123)
              {
         int I = 0;
   count_orders_all = 0;   //КОЛИЧЕСТВО ВСЕХ УСТАНОВЛЕННЫХ ОРДЕРОВ
   count_orders_market_all = 0; //КОЛИЧСТВО ВСЕХ РЫНОЧНЫХ ОРДЕРОВ
   count_orders_market_buy = 0;
   
   count_orders_stop_buy = 0;    //КОЛИЧЕСТВО СТОП БАЕВ
   count_orders_limit_buy = 0;   // КОЛИЧЕСТВО ЛИМИТ БАЕВ
   
   count_orders_stop_sell = 0;    //КОЛИЧЕСТВО СТОП СЕЛОВ
   count_orders_limit_sell = 0;   //КОЛИЧЕСТВО ЛИМИТ СЕЛОВ
   
   
  lot_orders_buy = 0;    //ОБЪЁМ ЛОТА ПО БАЙ ОРДЕРАМ
         lot_orders_sell = 0;      //ОБЪЁМ ЛОТА ПО СЕЛЛ ОРДЕРАМ
         balance_all = 0;          // БАЛАНС ПО ВСЕМ ОРДЕРАМ
         balance_buy = 0;         // БАЛАНС ПО ОРДЕРАМ БАЙ
         balance_sell = 0;        // БАЛАНС ПО ОРДЕРАМ СЕЛЛ
         
         
         
          for(int i = 0; i <= OrdersTotal();i ++) // перебор всех ордеров в цикле
          {
  
   if(OrderSelect(I , SELECT_BY_POS, MODE_TRADES))// выбираем ордер по переменной цикла
   {
    if(OrderMagicNumber() != magik_number || OrderSymbol() !=Symbol()) // если ордер не нашь то
    {
    continue; // переходим на следующую итерацию
    
    }
    if(comment== OrderComment() || comment=="alt")// если коментарий нашь то 
    {
    count_orders_all+=1;
    if(OrderType()== OP_BUY)
    {
    count_orders_market_all+=1;
    count_orders_market_buy+=1;
    }
    if(OrderType()== OP_SELL)
    {
    count_orders_market_all+=1;
    count_orders_market_sell+=1;
    }
    if(OrderType()== OP_BUYSTOP)
    {
    count_orders_stop_buy+=1;
    }
    if(OrderType()== OP_BUYLIMIT)
    {
    count_orders_limit_buy+=1;
    
    }
    if(OrderType()== OP_SELLSTOP)
    {
    count_orders_stop_sell+=1;
    
    }
    if(OrderType()== OP_SELLLIMIT)
    {
    count_orders_limit_sell+=1;
    
    }
    
    
    
    }
         
         
              }
              }
              }

If i want to trade in this way, i would like to know how to avoid server chattering in case of errors.

 
DanilaMactep:

Good afternoon, everyone.

Please write to me and tell me how to handle errors correctly and how to avoid the server chiming at every tick when an error occurs?
if (GetLastError()==141){Alert(GetLastError()); ExpertRemove();}
 
MakarFX:

And this request should be written after every line in which there is an attempt to open an order using Ordersend - right?

But I have a question - if the Remove EA has deleted the EA from the chart, how should I make it automatically re-attach to the chart and continue working? Could you please give me a more detailed description of what this is all about - error 141 - too many requests. If there are too many requests, we delete the EA from the chart. What should I do next - wait until I get up in the morning, change everything and come to the PC to attach the EA to the chart again?

Reason: