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

 
Artyom Trishkin:

The questions are strange answers complicated by the stream of thought bulging out something impossible to keep in the mush of the stream of thought please...

And in what language are you communicating?

 
Alexey Viktorov:

What language is that in which you are communicating?

In a language the questioner understands, I think :)
 

Good afternoon, could you please tell me where I can get a free SCRIPT for trading a false-break from a level?

 
barmaley1:

Good afternoon, could you please tell me where I can get a free SCRIPT for trading a false-break from a level?

The script will not help.

 

Hello Guys, could you please advise me?

Every time I open an order, I need to remember some of the data of the opened order to work with it later.

I think I need to save it all in a structure:

- entry price

- whether the SL has been moved to Breakeven

- the peak price for calculating a reversal


In every tick you need to perform calculations for each of the open orders

Please advise how to do it correctly.

 
Decromor:

Hello Guys, could you please advise me?

Every time I open an order, I need to remember some of the data of the opened order to work with it later.

I think I need to save it all in a structure:

- entry price

- whether the SL has been moved to Breakeven

- the peak price for calculating a reversal


In every tick you need to perform calculations for each of the open orders

Please advise how to do it correctly.

Basically, you have described it yourself)

In the code, it would look as follows

   for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS))          
         continue;
         
      if (OrderSymbol() != Symbol())
         continue;  
      
      if (m_nMagicNumber != OrderMagicNumber()) 
         continue;

      if (OrderType() == OP_BUY)
         if (!SaveOrderInfo(m_stBuySeries))
            return false;

      if (OrderType() == OP_SELL)
         if (!SaveOrderInfo(m_stSellSeries))
            return false;
   }

m_nMagicNumber - ID of the Expert Advisor's orders,

m_stBuySeries and m_stSellSeries - structures that store data on all orders of the specified type found. For example, you can describe them in the following way:

struct SeriesInfo
{
   int            nLastOrderTicket;                                                                // Тикет последнего открытого ордера
   int            nOrdersCnt;

   double         fSeriesTotalProfit;
   double         fVolumeSumm;
   double         fMinOrdersPrice;
   double         fMaxOrdersPrice;
   datetime       dtLastOrderTime;                                                                 // Время открытия последнего ордера
   OrderInfo      starrOrderInfo[];   
   
   bool           Init()
   {  
      nOrdersCnt = 0;
      nLastOrderTicket = 0;
      fSeriesTotalProfit = 0.0;
      fVolumeSumm = 0.0;
      fMinOrdersPrice = DBL_MAX;
      fMaxOrdersPrice = 0.0;
      dtLastOrderTime = 0;
      return ArrayResize(starrOrderInfo, 0, 100) == 0;
   }
};

SaveOrderInfo function for such structures would be as follows:

bool SaveOrderInfo(SeriesInfo &stSeriesInfo)
{
   // Проверка возможности добавления ордера в серию
   int nTotal = ArraySize(stSeriesInfo.starrOrderInfo);
   if (ArrayResize(stSeriesInfo.starrOrderInfo, nTotal + 1, 100) < 0)
   {
      Alert(MQLInfoString(MQL_PROGRAM_NAME), (TerminalInfoString(TERMINAL_LANGUAGE) == "Russian")? ": нехватка памяти для записи данных об очередном ордере. Эксперт отключен." : 
                                                                                                   ": unable to allocate the memory for next order. Expert is turned off.");
      return false;
   }
   
   // Запись ордера
   stSeriesInfo.starrOrderInfo[nTotal].nType = OrderType();
   stSeriesInfo.starrOrderInfo[nTotal].nTicket = OrderTicket();
   stSeriesInfo.starrOrderInfo[nTotal].fVolume = OrderLots();
   stSeriesInfo.starrOrderInfo[nTotal].fTP = OrderTakeProfit();
   stSeriesInfo.starrOrderInfo[nTotal].fSL = OrderStopLoss();
   stSeriesInfo.starrOrderInfo[nTotal].fOpenPrice = OrderOpenPrice();
   stSeriesInfo.starrOrderInfo[nTotal].fProfit = OrderProfit() + OrderSwap() + OrderCommission();
   stSeriesInfo.starrOrderInfo[nTotal].dtOpenTime = OrderOpenTime();
   
   stSeriesInfo.fSeriesTotalProfit += stSeriesInfo.starrOrderInfo[nTotal].fProfit;
   stSeriesInfo.fVolumeSumm += stSeriesInfo.starrOrderInfo[nTotal].fVolume;
   stSeriesInfo.fMinOrdersPrice = MathMin(stSeriesInfo.fMinOrdersPrice, OrderOpenPrice());
   stSeriesInfo.fMaxOrdersPrice = MathMax(stSeriesInfo.fMaxOrdersPrice, OrderOpenPrice());
   
   if (OrderOpenTime() > stSeriesInfo.dtLastOrderTime)
   {
      stSeriesInfo.dtLastOrderTime = OrderOpenTime();
      stSeriesInfo.nLastOrderTicket = OrderTicket();
   }
   
   return true;
}
 

slightly off topic.

https://www.finam.ru/profile/tovary/aluminum/export/?market=24

got the file.

I'm trying to put it into a symbol.

the result is disappointing.

Thanks.

 
Ihor Herasko:

Basically, you have described it yourself))

In the code, it would look as follows:

m_nMagicNumber - ID of orders of the Expert Advisor,

m_stBuySeries and m_stSellSeries - structures that store data on all orders of the specified type found. For example, you can describe them in the following way:

The SaveOrderInfo function for such structures would be as follows:

Thank you very much for such a detailed help!

 

Good afternoon!

Guys, can you tell me the code on how to link an EA to one account (for the latest update).

Thank you very much.

 
Aleksandr Lishchenko:

Good afternoon!

Guys, can you tell me the code on how to link an EA to one account (for the latest update).

Thank you very much.

Simple:

if (AccountInfoInteger(ACCOUNT_LOGIN) != <номер счета>)
   return;
Reason: