Questions from Beginners MQL5 MT5 MetaTrader 5 - page 58

 
teetrinker:

Should Myexpert.Time(10) return the time of the tenth bar on the chart? And how to write it correctly?

Thank you

In theory, yes, it should...

The Time method, according to the documentation, gets the value of Time element by the specified index. It is a method of CExpertBase class, which is a base class for CExpert and all auxiliary classes of trading strategies.

Dear sergeev tells you correctly... it's best to use Debugger to determine the role of Time() method in your EA's life...

 

Thank you, Yedelkin !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

And EnumToString(timeframe), cool function!!! AND I'M BARAN!!!!!!

 
Tell me please, here is a function
 bool  PositionModify( ulong  PositionTicket, double price, double stoploss, double takeprofit, datetime expiration, color arrow_color=CLR_NONE)
      {  MqlTradeRequest request  = {0};
         MqlTradeResult result = {0};
        request.action= TRADE_ACTION_SLTP; 
        request.order= PositionTicket; 
        request.price= price;
        request.symbol= Symbol();
        request.sl= stoploss;
        request.tp= takeprofit;
        return (OrderSend( request,   result    ));   
      }

The function seems to have a ,,side,,- request.symbol= Symbol(); Why Symbol()? This is where the symbol for which we set TP and SL should be transferred. So, can we just remove the string request.symbol= Symbol();, like it is stupid nada?

 

Please advise how to set a rollover order at the stop level of the open main order and then delete it if the main order is closed at TP ?

I set both orders in the code at once:

        
 // основной ордер +++++++++++++++++++++++++++++++++++++++      
        {
         request.action = TRADE_ACTION_PENDING;
         request.magic=magic_number;                  // ORDER_MAGIC
         request.symbol = "EURUSD";
         request.volume = NormalizeDouble(volume()/1,2);
         request.price=NormalizeDouble(Ask+StopLevel*_Point,_Digits);
         request.sl = NormalizeDouble(request.price - SL*_Point,_Digits);
         request.tp = NormalizeDouble(request.price + TP*_Point,_Digits);
         request.deviation=0;
         request.type=ORDER_TYPE_BUY_STOP;
         request.type_filling=ORDER_FILLING_FOK;
         
           {
            OrderSend(request,result);
            if(result.retcode==10009 || result.retcode==10008)
               Print("Установлен ордер BuyStop");
            else
              {
               Print(ResultRetcodeDescription(result.retcode));
                           
              }
           }      
 // переворотный ордер +++++++++++++++++++++++++++++++++++++++
        
         request.action = TRADE_ACTION_PENDING;
         request.magic=magic_number1;                  // ORDER_MAGIC
         request.symbol = "EURUSD";
         request.volume = NormalizeDouble(volume()/2,2);
         request.price=NormalizeDouble(Bid-(SL-45) *_Point,_Digits);
         request.sl = NormalizeDouble(request.price + SL*_Point,_Digits);
         request.tp = NormalizeDouble(request.price - (TP-900)*_Point,_Digits);
         request.deviation=0;
         request.type=ORDER_TYPE_SELL_STOP;
         request.type_filling=ORDER_FILLING_FOK;
         
           {
            OrderSend(request,result);
            if(result.retcode==10009 || result.retcode==10008)
               Print("Установлен ордер SellStop");
            else
              {
               Print(ResultRetcodeDescription(result.retcode));
               return;
              }
           }        
       } } 
}

The main order opens and closes at TP, and the reversal order hangs. If the main order has closed at stop, there would not be any problem )). What is the best function to close?

Should I go through the pending orders and delete them that way?

      {
         request.action = TRADE_ACTION_REMOVE;
         request.magic=magic_number1;                  // ORDER_MAGIC
         request.symbol = "EURUSD";
         request.volume = 0;
         request.price=0;
         request.sl = 0;
         request.tp =0;
         request.deviation=0;
         request.type=0;
         request.type_filling=0;
         
           {
            OrderSend(request,result);
Or is there an easier way?


	          
 
Crucian: The main order opens and closes at TP and the rollover order hangs. If the main order would have closed on stop, there would not have been any problems )). What function would be better to use to close it? Should I go through the pending orders and delete them that way? Or is there an easier way?

So the question comes down to how to delete a pending order that is not an SL or TP order when certain events occur (in particular, when a TP order triggers at an open position).

At present, such a pending order can only be deleted compulsorily by sending the relevant "Delete Pending Order" request. So we have to monitor on the terminal side the occurrence of certain events and send a request. But unlike your variant, there are only two fields to be specified in the request, one of which is request.order.

In the situation you mention, OCO orders ("One Cansels Other(s)") would be helpful: on the TP level, an order would be placed with a volume equal to the open position, on the SL level, an order with the volume needed to "reverse" the position would be placed. If one of these OCO orders triggered, the second one would be automatically removed on the server side. However, throughout the life of this forum, the developers of the platform have been adamant about not introducing any additional order types, including OCO orders.

 
Yedelkin:

However, for as long as this forum has existed, the platform developers have categorically not agreed to introduce any additional order types, including OCO orders.

And why introduce them when it can be implemented programmatically?
 
A100: Why enter them when you can do it programmatically?
Try typing the word 'OCO' in Latin and Cyrillic in a forum search and read it.
 
Yedelkin:
Try typing the word 'OCO' in Latin and Cyrillic in a forum search and read it.
OCO is not a stand-alone warrant and there is no need to enter it
 
A100: The CCA is not a stand-alone warrant and there is no need to introduce it
I see. So you haven't read anything. But you are willing to share your opinion. OK, your opinion is accepted: you do not need this type of order.
 
Yedelkin:
You do not need this type of order.
Some platforms have the ability to bind 1 (sometimes 2) CCA orders. In MT4/5 I programmatically implement a chain of linked orders (sometimes quite complex) and find this a more convenient option
Reason: