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

 

a multicurrency EA and everything is working as planned except for opening orders. I am looking for error messages.

      if((USDTP<=0)&&(JPYTP>=3)&&(z_USDJPY!=2))
        {
         Alert("Продавай USDJPY. USD=", USDTP, ", JPY=", JPYTP);
         z_USDJPY=2; //
         text_massage="Продавай USDJPY";
         SendNotification(text_massage);
         RefreshRates();
         Ask1=MarketInfo("USDJPY",MODE_ASK);
         Bid1=MarketInfo("USDJPY",MODE_BID);
         Point1=MarketInfo("USDJPY",MODE_POINT);
         OrderSend("USDJPY", OP_BUY, 0.1, Bid1, 3, NormalizeDouble((Ask1+StopLoss*Point1),2), NormalizeDouble((Ask1-TakeProfit*Point1),2), NULL, 0, 0, 0);
        }

It is not giving out any error, it is just not opening an order.

Did you notice where the error is?

       if((USDTP<=0)&&(JPYTP>=3)&&(z_USDJPY!=2))
        {
         Alert("Продавай USDJPY. USD=", USDTP, ", JPY=", JPYTP);
         z_USDJPY=2; //
         text_massage="Продавай USDJPY";
         SendNotification(text_massage);
         RefreshRates();
         Ask1=MarketInfo("USDJPY",MODE_ASK);
         Bid1=MarketInfo("USDJPY",MODE_BID);
         Point1=MarketInfo("USDJPY",MODE_POINT);
         int nDigits = (int)MarketInfo("USDJPY", MODE_DIGITS);
         OrderSend("USDJPY", OP_SELL, 0.1, NormalizeDouble(Bid1, nDigits), 3, NormalizeDouble((Ask1-StopLoss*Point1), nDigits), NormalizeDouble((Ask1+TakeProfit*Point1), nDigits), NULL, magic, 0, 0);
        }

https://docs.mql4.com/ru/trading/ordersend

Примечание

When opening a market order (OP_SELL or OP_BUY), only the latest Bid (for selling) or Ask (for buying) prices may be used as the opening price. If the operation is performed for a financial instrument, different from the current one, then to get the latest quotes for this instrument, one should use theMarketInfo() function with the MODE_BID or MODE_ASK parameter.

You cannot use an estimated or non-normalized price. If the requested opening price was not in the price flow, or the requested price is not normalized according to the number of decimal places, error 129 (ERR_INVALID_PRICE) will be generated. If the requested opening price is severely out of date, an error 138 (ERR_REQUOTE) will be generated regardless of the value of the slippage parameter. If, on the other hand, the requested price is out of date but is still present in the price flow, the order will be opened at the current price and only if the current price falls within the price+-slippage range.

...

It is also desirable to set a unique magic for the robot.

OrderSend - Торговые функции - Справочник MQL4
OrderSend - Торговые функции - Справочник MQL4
  • docs.mql4.com
OrderSend - Торговые функции - Справочник MQL4
 
Mihail Matkovskij #:

the opening price was not in the price flow or the requested priceis not normalized according tothe number of digits after the decimal point, then

.

As far as I know, Ask and Bid are already normalised. A similar question has already been raised and there has been no contradiction.

The magik and digits of stoploss and profit may be appropriate, but the author's intention is not known.

 
Andrey Sokolov #:

As far as I know, Ask and Bid are already normalised. A similar question has already been raised and there has been no contradiction.

Perhaps it is appropriate to mention magik and digits of stop-loss and profit, but I don't know what the author's idea is.

As far as I know, the documentation doesn't say a word about it. So, you'd better take precautions. It won't make it worse.

Regarding the SL and TP, they are calculated. And therefore they should definitely be normalized according to the digits value.

 

Hello friends.

 
Can you tell me if the profit on the story is circled in blue, does this include commission and swap?
 

Good afternoon.

How do I get the opening time of the second and subsequent orders, because OpenOrderTime() gives out only the first one, and also how do I get the opening price of the second and subsequent orders, because the OpenOrderPrice() analogue also gives out the price of the first one?

 
Порт-моне тв get the opening time of the second and subsequent orders since OpenOrderTime() only gives out the first one, and also how do I get the opening price of the second and subsequent orders since OpenOrderPrice() also gives out the price of the first one?

collect (or remember/know) everything, sort by open time. That's what, but the open time doesn't change :-)

If the EA logic contains more than 1 order (e.g. grid), then you will have to remember them all. Or you will have to slow down trying to remember them all at every sneeze

 
Mykhailo Turovskyi #:
Can you tell me if the profit in the history is circled in blue, does this include commission and swap?
No.
 
Порт-моне тв get the opening time of the second and subsequent orders? OpenOrderTime() gives out only the first order and also how do I get the opening price of the second and subsequent orders, because the OpenOrderPrice() analog also gives out the price of the first order?

The time and price of the order to be selected using the function OrderSelect() will be obtained.

 
Mihail Matkovskij #:

As far as I know there is no mention of this in the documentation. So it's better to play it safe. It won't make things worse.

There have been complaints that this procedure takes a lot of CPU time.

Mihail Matkovskij#:

As far as SL and TP are concerned, they are calculated. And therefore they should definitely be normalised according to the digits value.

Here, in any case, it is necessary to find out the author's intention.

Reason: