Questions from Beginners MQL5 MT5 MetaTrader 5 - page 90

 
WindSW:
All options are listed except closing. That's why I ask.

you have already been told.

Yedelkin:

"Closing a position" is just the result of a trade request, whose rules are the same.

I.e. take the "open" request and change the order type.

Fill the unnecessary mandatory fields with zeros.

 

Yedelkin:
Для каждого вида торгового запроса предусмотрены обязательные поля. Они должны быть заполнены. "Открытие позиции" или "Закрытие позиции" - это всего лишь результат выполнения конкретного торгового запроса, правила заполнения которого - одни и те же. Т.е. берите свой работающий вариант запроса "на открытие" и меняйте тип ордера. Ненужные обязательные поля заполняйте нулями.

sergeev:

you have already been answered!

Thank you!

I have one more question: the request below is sent and a position is opened, but stop and profit is not set. I have already twisted them in different ways, but nothing helped. What is the problem, what am I doing wrong?

   MqlTick latest_price;       // Будет использоваться для текущих котировок
   if(!SymbolInfoTick(_Symbol,latest_price)) return;        // получить текущее значение котировки в структуру типа MqlTick
   ...
   if(uBuy && opSell==false)    
     {
      if(opBuy) return;                                                // при наличии позиции не добавлять к открытой позиции на покупку
      mrequest.action = TRADE_ACTION_DEAL;                                  // немедленное исполнение
      mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // последняя цена ask
      mrequest.sl = NormalizeDouble(latest_price.ask - StopLoss*_Point,_Digits); // Stop Loss
      mrequest.tp = NormalizeDouble(latest_price.ask + TakeProfit*_Point,_Digits); // Take Profit
      mrequest.symbol = _Symbol;                                            // символ
      mrequest.volume = WorkLot;                                                // количество лотов для торговли
      mrequest.magic = EA_Magic;                                            // Magic Number
      mrequest.type = ORDER_TYPE_BUY;                                       // ордер на покупку
      mrequest.type_filling = ORDER_FILLING_FOK;                            // тип исполнения ордера - все или ничего
      mrequest.deviation=Slippage;                                               // проскальзывание от текущей цены
      OrderSend(mrequest,mresult);                                          // отсылаем ордер
      if(mresult.retcode==10009 || mresult.retcode==10008)                  //запрос выполнен или ордер успешно помещен
        {
         Alert("Ордер Buy успешно помещен, тикет ордера #:",mresult.order,"!!");
        }
      else
        {
         return;
        }
     }
 

how do I add up the last 3 ZigZag values?

        double summ=0;//переменная, в которую все суммируется
        int w=0;//счетчик 3 удачных сумирований
        int count_for_buf=0;//Счетчик переходов по буферу ZigZag
        while (w<=3)
         {
         summ=summ+ZigzagBuffer[rates_total-count_for_buf];
         count_for_buf++;
         if (ZigzagBuffer[rates_total-count_for_buf]!=0)//Увеличиваем счетчик, если используемое значение индикатора не равно нулю
          {
          w++;
          }
         }
This way for some reason it hangs or something else happens
 
WindSW: The request below is sent and a position is opened, but no stop and profit is placed. I've already tried different settings, but nothing helped. What is the problem, what am I doing wrong?

Remember that trade requests "to open a position" have several options to fill? Some of these options involve sl/tp, others do not. In other words, what trading mode does your broker have?

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

Remember that trade requests "to open a position" have several options to fill? Some of these options involve sl/tp, others do not. In other words, what is your broker's trading mode?

Alpari broker. In the manual mode only a new order is placed in the exchange execution. There is no other option to enter from the market. I understand that this is an Exchange Execution request. Thank you, I have sorted it out. Can you tell me why the compiler processes the following code:

if(CopyBuffer(ema,0,0,3,emaVal)<0) return; // copy the new values of the indicator buffers into arrays

и

IndicatorRelease(ema);

A "possible loss of data due to type conversion" warning appears. I can't figure out what's wrong here, I can't fix it since yesterday evening.

 
WindSW: Can you tell me why the compiler swears at the following strings:

if(CopyBuffer(ema,0,0,3,emaVal)<0) return; // copy new indicator buffer values into arrays

и

IndicatorRelease(ema);

A "possible loss of data due to type conversion" warning appears. I can't figure out what's wrong here, I haven't managed to fix it since yesterday evening.

And what type of variable ema?
 
Yedelkin:
What type of variable is ema?
double
 
WindSW double
Got it. See what type the variable should be to store the indicator handles and match it.
 
Yedelkin:
Got it. See what type of variable should be used to store indicator handles, and match it.
And I'm out of habit of writing it as in 4. Thanks again for the tips!
 
lazarev-d-m:

how do you add up the last 3 ZigZag values?

This way for some reason it hangs or something else happens

I'll give you my suggestion:

   double   summ=0;  //переменная, в которую все суммируется
   int      w=0;     //счетчик 3 удачных сумирований
   for(int i=0; i<rates_total; i++)
     {
      if(ZigzagBuffer[rates_total]!=0 && w<3)//Увеличиваем счетчик, если используемое значение индикатора не равно нулю
        {
         summ+=ZigzagBuffer[i];
         w++;
        }
      if(w>2) break;
     } 
Reason: