Questions from Beginners MQL5 MT5 MetaTrader 5 - page 117

 
Yedelkin:

And without "if"? ...

There's no such thing as an "if". )))
 
tol64: There's no such thing as an "if". )))
:)
 

Hello, I can't understand why the stops aren't showing?

input int         StopLoss=499;      // Stop Loss
input int         TakeProfit=999;   // Take Profit
input int         EA_Magic=12345;   // Magic Number советника
input double      Lot=0.1;          // Количество лотов для торговли

int OnInit()
  {
//--- Для работы с брокерами, использующими 5-ти значные котировки,
//--- умножаем на 10 значения SL и TP
   STP = StopLoss;
   TKP = TakeProfit;
   if(_Digits==5 || _Digits==3)
     {
      STP = STP*10;
      TKP = TKP*10;
     }
   return(0);
  }
void OnTick()
  {
//---
  
   MqlTick         latest_price;       // Будет использоваться для текущих котировок
   SymbolInfoTick(Symbol(),latest_price); // Получаем текущие цены
   MqlTradeRequest mrequest;   // Будет использоваться для отсылки торговых запросов
   MqlTradeResult  mresult;     // Будет использоваться для получения результатов выполнения торговых запросов
  
         mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
         mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // последняя цена ask
         mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
         mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
         mrequest.symbol = _Symbol;                                            // символ
         mrequest.volume = Lot;                                                // количество лотов для торговли
         mrequest.magic = EA_Magic;                                            // Magic Number
         mrequest.type = ORDER_TYPE_BUY;                                       // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;                            // тип исполнения ордера - все или ничего
         mrequest.deviation=100;                                               // проскальзывание от текущей цены
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);

 
Top2n: Hello, I can't understand why no stops are being placed?

Firstly, initialisation is required:

MqlTradeRequest mrequest={0};   // Будет использоваться для отсылки торговых запросов
MqlTradeResult  mresult={0};    // Будет использоваться для получения результатов выполнения торговых запросов

Secondly, the ability to place sl and tp depends on the market order execution mode set by the broker. Look up how many of these modes there are in the Handbook and check which mode is set by the broker.

 
Yedelkin:

Firstly, initialisation is required:

Secondly, the ability to place sl and tp depends on the market order execution mode set by the broker. Look up how many such modes there are in the Handbook and check which mode is set by the broker.

I have zeroed out via ZeroMemory(mrequest);

I don't really understand about the order execution modes, alpari broker, i think everything is standard. Damn nonsense, doesn't want to and that's it. I have already tried to use sl and tp, it shows the current price + sl. I guess it is Ok!

Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
Документация по MQL5: Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров
  • www.mql5.com
Стандартные константы, перечисления и структуры / Торговые константы / Свойства ордеров - Документация по MQL5
 
Top2n:

I zeroed out via ZeroMemory(mrequest);

I don't really understand the order execution modes, alpari broker, i think everything is standard. Damn, it's not working, I just don't want to do it. I have already tried to use sl and tp, it shows the current price + sl. I guess it is Ok!

Do you have any messages in the log?
 
Top2n I don't really understand the order execution modes, I am an alpari broker, I think it is all standard. I do not know what to do with this kind of forex broker, I still do not know what to do with this kind of forex. I do not know what to do if I try to go back to the comment sl and tp?

I don't follow Alpari, but I think all the issues with not setting the levels you mentioned were related to Alpari. Try placing your order on the MQ demo account and you will be fine.

About order execution modes. You are using the https://www.mql5.com/ru/docs/trading/ordersend function. Please read carefully this section of the Guide: https://www.mql5.com/ru/docs/constants/structures/mqltraderequest and answer the question for yourself: "how many execution modes are available for market orders". If you can't answer this question, please ask.

Документация по MQL5: Торговые функции / OrderSend
Документация по MQL5: Торговые функции / OrderSend
  • www.mql5.com
Торговые функции / OrderSend - Документация по MQL5
 
tol64: Are there any messages in the log?
The developers have not yet provided a possibility to reflect in the log messages about the inability to set sl and tp levels in Market Execution and Exchange Execution modes. And there is no reason to do it. The programmer should determine the mode set by the broker.
 
Yedelkin:
The developers have not yet provided the possibility of reflecting in the log messages about the inability to set sl and tp levels in Market Execution and Exchange Execution modes. And there is no need for that. The programmer should determine the mode set by the broker.
Anyway, not to guess, you should analyze all the errors and return codes. It is easier and faster to analyze what to do next. ))
 
tol64: You still need to analyse all the errors and return codes to avoid guesswork. It's easier and quicker to figure out what to do next. ))
...Especially when you know that "errors and return codes" are simply not provided in this particular case :) No doubt, the question itself is correct, but in this particular case, it won't help :/