Questions from Beginners MQL5 MT5 MetaTrader 5 - page 98

 

Boris.45:

Yedelkin : What does Time_H1[1][0] return?

I do not use this element of the array, because I immediately proceed to the algorithm for searching fractals at the last 5 bars. While Time_H1[1][0] is the open time of the zero bar where parameters of this bar have not been formed yet.Maybe I am mistaken, but from my own experience, I have seen that using parameters of a zero bar to form time series leads to their distortion

Ok, let me clarify the question:

If "Time_H1[nomer_instr][i]=Time_buf[i];" and "Time_H1[1][1]=2011.01.03 11:00:00", what does Time_buf[0] return?

 

Please send me a link to close a certain (specific) position.


That is, at a certain point, when conditions to close a position are fulfilled, say BUY, the Expert Advisor (at the moment) closes any open BUY position. Now I face a problem, when I need to close a certain (specific) BUY position.

For example, when an BUY position is opened, you can give it a specific designation, but when it is closed, you have to specify 'BUY' as a condition.
 
Lester: Please send me a link to close a certain (specific) position, i.e. at a certain point, when conditions to close a position are fulfilled, say BUY, the advisor (at the moment) closes any open BUY position. I am now facing a problem, when I need to close a certain (specific) BUY position.

For example, when opening a BUY position, you can give it a specific designation, but when closing it, you need to specify its "existence".
And how do you close "any open position"? Essentially, each open position corresponds to one single symbol. So, when closing, you must use the name of that symbol, instead of assigning a "specific symbol" to the open position.
 
Here is an example. The first Buy Buy in the flat, the second Buy to close the Sell in the flat and Buy in the trend. The closing of the Buy also takes place for all open BAYs - which is not good, because the second closing only refers to the trend.
if(Buy_Condition_1 || Buy_Condition_2)
     { 
       if(Buy_Condition_3 && Buy_Condition_10)
        {
         // есть ли в данный момент открытая позиция на покупку?
         if(Buy_opened)
           {
            Alert("Позиция на покупку имеется");
            return;    // не добавлять к открытой позиции на покупку
           }        
         mrequest.action = TRADE_ACTION_DEAL;    // немедленное исполнение
         mrequest.symbol = _Symbol;              // символ
         mrequest.magic = EA_Magic;              // Magic Number
         mrequest.volume = Lot;                  // количество лотов для торговли
         mrequest.type = ORDER_TYPE_BUY;         // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;   // тип исполнения ордера - все или ничего

         //--- отсылаем ордер
         OrderSend(mrequest,mresult);         
                 
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {
            Alert("Buy успешно помещен, тикет ордера #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера Buy не выполнен - код ошибки:",GetLastError());
            return;
           }
         }
      }
 if(Buy_Condition_4 || Buy_Condition_5)
     { 
       if(Buy_Condition_6)
        {
         // есть ли в данный момент открытая позиция на покупку?
  if(Buy_opened)
      {
      Alert("Позиция на покупку во Флэте есть");
      return;    // не добавлять к открытой позиции на покупку
      }   
    if(PositionSelect(_Symbol)==true) // есть открытая позиция
      {
       if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)
       {
        Alert("Закрываю ордер Sell флэт!!!");                  
                                  
         mrequest.action = TRADE_ACTION_DEAL;// немедленное исполнение
         mrequest.symbol = _Symbol;         // символ
         mrequest.magic = EA_Magic;        // Magic Number
         mrequest.volume = Lot;           // количество лотов для торговли
         mrequest.type = ORDER_TYPE_BUY; // ордер на продажу      
         mrequest.type_filling = ORDER_FILLING_FOK;  // тип исполнения ордера - все или ничего
        //--- отсылаем ордер
         OrderSend(mrequest,mresult);
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {
          Alert("тикет закрытия Sell флэт #:",mresult.order,"!!");
           }
         else
           {
          Alert("Запрос на установку ордера закрытия Sell флэт не выполнен - код ошибки:",GetLastError());
          return;
           }
         }
       }
   
         mrequest.action = TRADE_ACTION_DEAL;    // немедленное исполнение
         mrequest.symbol = _Symbol;              // символ
         mrequest.magic = EA_Magic;              // Magic Number
         mrequest.volume = Lot;                  // количество лотов для торговли
         mrequest.type = ORDER_TYPE_BUY;         // ордер на покупку
         mrequest.type_filling = ORDER_FILLING_FOK;   // тип исполнения ордера - все или ничего

         //--- отсылаем ордер
         OrderSend(mrequest,mresult);         
                 
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {
            Alert("Buy на тренд успешно помещен, тикет ордера #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера Buy тренд не выполнен - код ошибки:",GetLastError());
            return;
           }         
         }
      }
....
...
if(Buy_Close_1 || Buy_Close_2)
     {
      if(Buy_Close_3)
        {
         if(PositionSelect(_Symbol)==true) // есть открытая позиция
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
                {
           Alert("Закрываю ордер BUY!!!");                  
                                  
         mrequest.action = TRADE_ACTION_DEAL; // немедленное исполнение
         mrequest.symbol = _Symbol;           // символ
         mrequest.magic = EA_Magic;           // Magic Number
         mrequest.volume = Lot;               // количество лотов для торговли
         mrequest.type = ORDER_TYPE_SELL; // ордер на продажу      
         mrequest.type_filling = ORDER_FILLING_FOK; // тип исполнения ордера - все или ничего
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {            
            Alert("тикет закрытия Buy #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера закрытия Buy не выполнен - код ошибки:",GetLastError());
            return;
           }
        }
      }
    }
  }

if(Buy_Close_4 || Buy_Close_5)
        {
         if(PositionSelect(_Symbol)==true) // есть открытая позиция
           {
            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)
                {
           Alert("Закрываю ордер BUY!!!");                  
                                  
         mrequest.action = TRADE_ACTION_DEAL; // немедленное исполнение
         mrequest.symbol = _Symbol;           // символ
         mrequest.magic = EA_Magic;           // Magic Number
         mrequest.volume = Lot;               // количество лотов для торговли
         mrequest.type = ORDER_TYPE_SELL; // ордер на продажу      
         mrequest.type_filling = ORDER_FILLING_FOK; // тип исполнения ордера - все или ничего
         //--- отсылаем ордер
         OrderSend(mrequest,mresult);
         // анализируем код возврата торгового сервера
         if(mresult.retcode==10009 || mresult.retcode==10008) //запрос выполнен или ордер успешно помещен
           {            
            Alert("тикет закрытия Buy #:",mresult.order,"!!");
           }
         else
           {
            Alert("Запрос на установку ордера закрытия Buy не выполнен - код ошибки:",GetLastError());
            return;
           }
        }
      }
    }
 
Lester: Here is an example. The first Buy Buy in the flat, the second Buy to close the Sell in the flat and Buy in the trend. However, this is not good, because the second closing is only related to the trend.
So you are going to close different "positions" on one symbol?
 
Yedelkin:
So you are going to close different "positions" on the same symbol?

Not really.

If a buy-flat is open, I cannot close a buy-trend. And vice versa.

That is, to close certain positions on the same symbol - either a flat (if a flat is open) or a trend (if a trend is open).

 
Lester: Not exactly. If a buy-flat is open, then I cannot close a buy-trend. And vice versa.

That is, to close certain positions on a single symbol - either a flat (subject to opening flat) or a trend (subject to opening trend).

I see. Unfortunately, I was misled due to terminological inaccuracies and cannot help you further. In MQL5 only one position on each symbol may exist. The two positions of"buy-flat and buy-trend" typecannot exist on one symbol at a time . In fact, your question is not about mql5-positions, but about the tracking of trade orders you have placed. If you search the forums, three years ago there was an article about the "virtual orders" for MT5. And later on this topic was repeatedly raised on the forum.
 
Yedelkin:

OK, I'll clarify the question:

If "Time_H1[nomer_instr][i]=Time_buf[i];" and "Time_H1[1][1]=2011.01.03 11:00:00", what does Time_buf[0] return?

I'll try to explain the idea I'm trying to implement in the EA.

There are standard functions CopyTime(), CopyOpen(), CopyHigh(), etc., using the corresponding arrays Time_buf[], Open_buf[], High_buf[], etc.

Using these functions, we can get the historical data for different timeframes and different currencies. In this case, Time_buf[0]is the time of the zero bar opening,

High_buf[0] is the maximum price value of the specified currency on the zero bar at the moment of the last arriving tick.

Then I create two-dimensional arrays for each timeframe for each parameter Time, Open, etc. Then I have the following arrays for timeframe H1

Time_H1[i][j], Open_H1[i][j], High_H1[i][j], etc. In these arrays each row is dedicated to the historical data of a certain currency. Thus,

using the loop by currency number for( i=1; i<=nomer_instr; i++ ) I overwrite the historical data Time_buf[j], High_buf[j] etc. with the corresponding rows of the arrays

Time_H1[i][j], High_H1[i][j] etc.

If you trade using ticks, you can use the current parameters from the zero bar. Naturally, the current parameters of the zero bar at the moment of

I have an Expert Advisor that uses bars instead of ticks. I have found out that when the EA is operating on bars

the values High_buf[0] and Low_buf[0] are not historical values at the moment of zero bar closing, they are some random values. Therefore if we include

parameters of the zero bar in a history sequence, the whole history sequence of the parameter will be distorted. That is why I do not use parameters of the zero bar.

Sorry it's so long.


 

Boris.45:

Yedelkin : Ok, let me clarify my question: if "Time_H1[nomer_instr][i]=Time_buf[i];" and "Time_H1[1][1]=2011.01.03 11:00:00", what does Time_buf[0] return?

I will try to explain the idea I'm trying to implement in my Expert Advisor.

I wasn't asking about the idea :)

Boris.45: Time_buf[0]- it is time of opening of the zero bar,

That's what I'm asking, what value returns the array element you mention?

 

Please advise!

How to change the background colour of currency pairs in the market overview

Or remove the colour altogether!

Thanks in advance!

Reason: