Metatrader Default Functions Improvements suggestions

 

Hi, i have been creating a multicurrency EA, i noticed if Metatrader would include a simple line code would make this easier, from the Trade.mqh include file, code line:

 bool CTrade::Buy(...)---   line code number  820

bool CTrade::Sell(....)----- line code number  838

however this would mean the sl and tp not be const type.

the moment price is not passed one can enter a set stop loss and take profit in terms of pips (_Points). this would automatically set the values.


be something like

//+------------------------------------------------------------------+
//| Buy operation                                                    |
//+------------------------------------------------------------------+
bool CTrade::Buy(const double volume,const string symbol=NULL,double price=0.0,double sl=0.0, double tp=0.0,const string comment="")
  {
//--- check volume
   if(volume<=0.0)
     {
      m_result.retcode=TRADE_RETCODE_INVALID_VOLUME;
      return(false);
     }
//--- check symbol
   string symbol_name=(symbol==NULL) ? _Symbol : symbol;
//--- check price
    if(price==0.0){
    price=SymbolInfoDouble(symbol_name,SYMBOL_ASK);
/////////CUSTOMIZATION
    if(tp!=0){
    tp=price+tp;
    }
    if(sl!=0){
    sl=price-sl;
    }
////END CUSTOMIZATION
   }
//---
   return(PositionOpen(symbol_name,ORDER_TYPE_BUY,volume,price,sl,tp,comment));
  }
//+------------------------------------------------------------------+
//| Sell operation                                                   |
//+------------------------------------------------------------------+
bool CTrade::Sell(const double volume,const string symbol=NULL,double price=0.0, double sl=0.0,double tp=0.0,const string comment="")
  {
//--- check volume
   if(volume<=0.0)
     {
      m_result.retcode=TRADE_RETCODE_INVALID_VOLUME;
      return(false);
     }
//--- check symbol
   string symbol_name=(symbol==NULL) ? _Symbol : symbol;
//--- check price
   if(price==0.0){
    price=SymbolInfoDouble(symbol_name,SYMBOL_BID);
/////////CUSTOMIZATION
    if(tp!=0){
    tp=price-tp;
    }
    if(sl!=0){
    sl=price+sl;
    }
////END CUSTOMIZATION

   }
return(PositionOpen(symbol_name,ORDER_TYPE_SELL,volume,price,sl,tp,comment));
  }
 
Mathai Njihia: Hi, i have been creating a multicurrency EA, i noticed if Metatrader would include a simple line code would make this easier, from the Trade.mqh include file, code line: bool CTrade::Buy(...)---   line code number  820, bool CTrade::Sell(....)----- line code number  838, however this would mean the sl and tp not be const type. the moment price is not passed one can enter a set stop loss and take profit in terms of pips (_Points). this would automatically set the values. be something like

Such a suggestion would not be useful for those that don't want that functionality.

Instead, given that this is object oriented programming, just create your own custom class, either from scratch, or by inheriting CTrade and customising it to your own liking.

 
Fernando Carreiro #:

Such a suggestion would not be useful for those that don't want that functionality.

Instead, given that this is object oriented programming, just create your own custom class, either from scratch, or by inheriting CTrade and customising it to your own liking.

sure one can do that, however it doesn't affect if you use it the usual way. it's just more dynamic,  it would save me an extra file..

 
Mathai Njihia #: sure one can do that, however it doesn't affect if you use it the usual way. it's just more dynamic,  it would save me an extra file..

If Metaquotes were to apply your suggestion it would affect those that wish to use absolute stops and they would be forced to use relative stops, not to mention that it would break all existing EAs using the library.

So, MetaQuotes will not make such a change and it is up to you to make your own adaptations. And having an extra or embedded #include is of no consequence.

Reason: