Discussion of article "Library for easy and quick development of MetaTrader programs (part IV): Trading events" - page 3

 

It's like a very interesting lecture in terms of content. I will definitely follow the whole series.

Unfortunately, there may even be small mistakes on purpose - the content is very complex and perhaps you should stay on the ball.

In the "

CMarketCollection::Refresh

" the field total_market is not found - this already happened before with ORDER_STATUS_MARKET. The changeover from simple to complex is very impressive.

At the refresh point, I couldn't go any further, as the next object didn't want to run straight away either. So I was happy to use the download.

mfG

Marc Tolkmitt

 

Strange, I can't realise the simplest logic with your methods...

Here I need to get the closing time of the last trade. It seems that the library has a mechanism for working with abstract orders a la MT4, but I don't see any methods for working with them.

I request Deals, but ORDER_PROP_TIME_CLOSE is not supported:

bool last_trade_time_filter=true;
   CArrayObj *all_trades=engine.GetListDeals();
   if(all_trades!=NULL && all_trades.Total()>0)
     {
      CArrayObj *sym_all_trades=CSelect::ByOrderProperty(all_trades,ORDER_PROP_SYMBOL,Symbol(),EQUAL);
      if(sym_all_trades!=NULL && sym_all_trades.Total()>0)
        {
         CArrayObj *sym_all_trades_recent=CSelect::ByOrderProperty(sym_all_trades,ORDER_PROP_TIME_CLOSE,iTime(NULL,PERIOD_CURRENT,1),EQUAL_OR_MORE);
         if(sym_all_trades_recent.Total()>0)
           {
            // it doesn't come here
            last_trade_time_filter=false;
           }
            
        }
     }
 
leonerd get the closing time of the last trade. It seems that the library has a mechanism for working with abstract orders a la MT4, but I don't see any methods for working with them.

I request Deals, but ORDER_PROP_TIME_CLOSE is not supported:

ok, it is somehow incorrect to request the closing time for a trade. But it doesn't work with GetListHistoryOrders() either...

 
leonerd get the closing time of the last trade. It seems that the library has a mechanism for working with abstract orders a la MT4, but I don't see any methods for working with them.

I request Deals, but ORDER_PROP_TIME_CLOSE is not supported:

In the test Expert Advisor, in the button press handler.

//+------------------------------------------------------------------+
//| Handling button presses|
//+------------------------------------------------------------------+
void PressButtonEvents(const string button_name)

(and this is just an example of how to handle events and get data).

There are code blocks there that are responsible for closing positions. You can see how it is implemented there. For example, a code block for closing a purchase by the current symbol with maximum profit:

      //--- If the BUTT_CLOSE_BUY button is pressed: Close Buy with maximum profit
      else if(button==EnumToString(BUTT_CLOSE_BUY))
        {
         //--- Get the list of all open positions
         CArrayObj* list=engine.GetListMarketPosition();
         //--- Select from the list only Buy positions and only by the current symbol
         list=CSelect::ByOrderProperty(list,ORDER_PROP_SYMBOL,Symbol(),EQUAL);
         list=CSelect::ByOrderProperty(list,ORDER_PROP_TYPE,POSITION_TYPE_BUY,EQUAL);
         //--- Sort the list by profit with commission and swap taken into account
         list.Sort(SORT_BY_ORDER_PROFIT_FULL);
         //--- Get the index of the Buy position with the highest profit
         int index=CSelect::FindOrderMax(list,ORDER_PROP_PROFIT_FULL);
         if(index>WRONG_VALUE)
           {
            //--- Get Buy position object and close the ticket position
            COrder* position=list.At(index);
            if(position!=NULL)
              {
               //--- If the buttons for creating a pending request are not pressed - close the position
               if(!pressed_pending_close_buy)
                  engine.ClosePosition((ulong)position.Ticket());
               //--- Otherwise - create a pending request to close a position on a ticket
               //--- and set conditions depending on active buttons
               else
                 {
                  int id=engine.ClosePositionPending(position.Ticket());
                  if(id>0)
                    {
                     //--- set the price and activation time of the pending request and set the activation parameters
                     double bid=SymbolInfoDouble(NULL,SYMBOL_BID);
                     double price_activation=NormalizeDouble(bid+distance_pending_request*g_point,g_digits);
                     ulong  time_activation=TimeCurrent()+bars_delay_pending_request*PeriodSeconds();
                     SetPReqCriterion((uchar)id,price_activation,time_activation,BUTT_CLOSE_BUY,EQUAL_OR_MORE,bid,TimeCurrent());
                    }
                 }
              }
           }
        }

About closed positions - I did it a long time ago, now I can't tell you how to get what you need at a glance. I'll take a look later and write - I'm very busy at the moment.

 
Artyom Trishkin #:

In the test Expert Advisor, in the button press handler

(and this is just an example of how to process events and get data).

There are code blocks there that are responsible for closing positions. You can see how it is implemented there. For example, a code block for closing a purchase on the current symbol with maximum profit:

About closed positions - I did it a long time ago, now I can't tell you how to get what you need at a glance. I'll take a look later and write - I'm very busy at the moment.

Thanks, but there is no need to catch the event.

 
ORDER_STATUS_MARKET_ORDER gives error : undeclared identifier. looks like things changed in recent versions for MQL 5, it shows up both in COrder::OrderMagicNumber and CMarketOrder Constructor!
 
theonementor # :
ORDER_STATUS_MARKET_ORDER gives error : undeclared identifier. looks like things changed in recent versions for MQL 5, it shows up both in COrder::OrderMagicNumber and CMarketOrder Constructor!

I downloaded the MQL5.zip archive file attached to the article - each file individually and all together (when compiling Engine.mqh or TestDoEasyPart04.mq5) are compiled without errors.

What exactly are you doing that you are getting a compilation error?

 
Artyom Trishkin #:

I downloaded the MQL5.zip archive file attached to the article - each file individually and all together (when compiling Engine.mqh or TestDoEasyPart04.mq5) are compiled without errors.

What exactly are you doing that you are getting a compilation error?

Figured it out, there was one entry missing from the define enum. somehow It was missing (although I copy paste the code from the tutorial into the editor)
 
theonementor # :
Figured it out, there was one entry missing from the define enum. somehow It was missing (although I copy paste the code from the tutorial into the editor)

The codes in the article do not always match the codes in the attached files. Sometimes I may miss something during the description, and sometimes something is added after writing the article. The article is not a step-by-step guide in the “read-copy-use” style, but only a detailed explanation in the form of training material. And small errors and omissions make you think, and that’s good)