Discussion of article "The Prototype of Trade Robot"

 

New article The Prototype of Trade Robot is published:

This article summarizes and systematizes the principles of creating algorithms and elements of trading systems. The article considers designing of expert algorithm. As an example the CExpertAdvisor class is considered, which can be used for quick and easy development of trading systems.

Author: Алексей Сергеев

 
Good article. Thanks!
 

Really great, people still stuck on MT4 should see "the bigger picture" presented in this article.

This article's author should earn double the pay for all the hard work. :) 

 

Probably one of the best articles so far. The funny thing is that I planned to create such a prototype for a frequent use so it seems that now I will have a much easier task. 

Thanks to the author!

 

Address this in a future article:

  • *robust* (as in server-side) per-trade different-level stop-loss and take-profit orders; these are *required* to avoid issues associated with network and client program outages (prolonged network disconnects, network lag-induced slippage (and requotes), client program or operating system quits, restarts, crashes (prolonged absence of client-side software) etc); so called "virtual" orders just don't cut it and neither do non-OCO substitutes (no, it's *not* negotiable, if robustness is a requirement stop-loss and take-profit orders *must* be server-side, and if one is hit the other one *must* be removed *by the server* at the same time)
  • *robust* per-trade state recovery in case of crash; in other words, if the client/OS crashes (and automatically restarts) I want the EA to know exactly what happened with outstanding individual trades and orders in the meantime: filled, closed, still active, which associated s/l and t/p orders belong to which trade/order etc (no, writing state to disk *doesn't* cut it because there's a race condition between opening a trade and writing state to disk and client program can crash at exactly the inappropriate time; server-side order comments might do, *if* they were modifiable)

As far as I can tell MT5 only supports *1* (one) server-side s/l and t/p order *per instrument* (not per trade) and no OCO orders (OCO orders can be used to simulate per-trade s/l and t/p orders, but there's a race condition there too). Unless the above is addressed I wouldn't commit any more than $100 to trading via MT5 (simplistic single-order single-timeframe single-direction MA cross type EAs). And I'm not even sure about the $100.


 

Compiles but debugger fails.

 loading of C:\Program Files\MetaTrader 5\MQL5\Experts\Examples\eMyEA.ex5 failed

 
Rosh:

New article The Prototype of Trade Robot is published:

Author: Алексей Сергеев


Thanks for the great article! I'm a newbie but I have a question about the code.


In the function void CExpertAdvisor::TrailingPosition(long dir,int TS), there is one line:

sl=NormalSL(dir,apr,apr,TS,StopLvl);                     // calculate Stop Loss


Should we use apr for both the second and the third argument when calling NormalSL? I thought it should be:

sl=NormalSL(dir,op,apr,TS,StopLvl);

since the second argument should be the bid/ask price for "specified" direction (i.e., the variable op) rather than the "reverse" direction (i.e., the variable apr).


Thanks!

 
echostate:


In the function void CExpertAdvisor::TrailingPosition(long dir,int TS), there is one line:

sl=NormalSL(dir,apr,apr,TS,StopLvl);                     // calculate Stop Loss


Should we use apr for both the second and the third argument when calling NormalSL? I thought it should be:

sl=NormalSL(dir,op,apr,TS,StopLvl);

no.
the second and third argument must be apr.

because the calculation of tral is derived from the price at which the position will be closed. Bid for the Buy and Ask for Sell.  function is correct.

since the second argument should be the bid/ask price for "specified" direction (i.e., the variable op) rather than the "reverse" direction (i.e., the variable apr).

should be calculated from the "reverse" direction. In this case, apr.
 
sergeev:

no.
the second and third argument must be apr.

because the calculation of tral is derived from the price at which the position will be closed. Bid for the Buy and Ask for Sell.  function is correct.

should be calculated from the "reverse" direction. In this case, apr.


Thanks for the quick reply! I thought I must be wrong.


Can I also ask in the function

double CExpertAdvisor::CountLotByRisk(int dist,double risk,double lot) // calculate lot by size of risk
  {
   if(dist==0 || risk==0) return(lot);
   m_smbinf.Refresh();
   return(NormalLot(AccountInfoDouble(ACCOUNT_BALANCE)*risk/(dist*10*m_smbinf.TickValue())));
  }

why we have a "10" between "dist" and "m_smbinf.TickValue()" in the return value? I guess "dist" is the stop loss (in terms of pips), and "m_smbinf.TickValue()" is the US dollar value per pip per lot for the currency pair. So I'm not sure why we multiply another "10" in between them.

Thanks!

 
Thanks a million.
 

Very useful article. Thanks a lot!