Download MetaTrader 5

Lots auto calculation based on account and Martingale Transactions

To add comments, please log in or register
cape1354
183
cape1354  
Lots will increase automatically according to the balance of account balances, and
if the transaction is lost, the next transaction launcher increase by multiplying by the external input variables multiplied by the external input variable.

If I follow the coding below, it is printed " "invalid lots amount for OrderSend function"

Where is wrong?

Please do not write the Preference Address.

Please explain it based on the code below, instead of an abstract explanation.


extern double Martingale = 3;

extern double AmountSet = 10000;
extern double LotIncreaseSet = 0.1;

//+------------------------------------------------------------------+
int start(){

if(total<1)                 
 {
      
    if( /*Entry condition*/ ){
    OrderSend(NULL,OP_BUY, Martingale_Function(),Ask,3,0,0,"ma sample",MagicNo,0,Green);
    }
 }

return(0);
}
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|  Martin Gale                                          |
//+------------------------------------------------------------------+

double Martingale_Function()
  {
   
   double Lots,Calcul_Lot;
   if(AccountEquity() < AmountSet)
      {
         Lots = LotIncreaseSet;
      }
   if(AccountEquity() >= AmountSet)
      {
      Lots = NormalizeDouble((AccountEquity() / AmountSet) * LotIncreaseSet,2);
      }  
 
   datetime order_close_time=0;
   for(i=OrdersHistoryTotal()-1;i>=0;i--) //Find Last Order
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNo && (OrderType()==OP_BUY || OrderType()==OP_SELL))
        {
         if(OrderCloseTime()>order_close_time)
           {
            order_close_time=OrderCloseTime();
            
            if(OrderProfit()<0){
               Calcul_Lot=OrderLots()*Martingale;}
            else
               Calcul_Lot=Lots;
           }
          
        }
     }
   
   return(Calcul_Lot);                          
  }


Fernando Carreiro
2960
Fernando Carreiro  
cape1354:
Lots will increase automatically according to the balance of account balances, and
if the transaction is lost, the next transaction launcher increase by multiplying by the external input variables multiplied by the external input variable.

If I follow the coding below, it is printed " "invalid lots amount for OrderSend function"

Where is wrong?

Please do not write the Preference Address.

Please explain it based on the code below, instead of an abstract explanation.

Please understand that we don't always have time to deeply analyse everyone's code in great detail.

As a developer, it is also your responsibility do use your own head and research and apply the knowledge gained.

Here is a link that will answer some of the details. In essence, you need to check broker conditions for Minimum, Maximum and Step-values for Lots/Volumes.

Forum on trading, automated trading systems and testing trading strategies

How to calculate lots using multiplier according to number of opened orders?

Fernando Carreiro, 2017.09.01 21:57

Don't use NormalizeDouble(). Here is some guidance (code is untested, just serves as example):

// Variables for Symbol Volume Conditions
double
   dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
   dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
   dblLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
   
// Variables for Geometric Progression
double
   dblGeoRatio = 2.8,
   dblGeoInit  = dblLotsMinimum;
   
// Calculate Next Geometric Element
double
   dblGeoNext  = dblGeoInit * pow( dblGeoRatio, intOrderCount + 1 );
   
// Adjust Volume for allowable conditions
double
   dblLotsNext = fmin( dblLotsMaximum,                                     // Prevent too greater volume
                   fmax( dblLotsMinimum,                                   // Prevent too smaller volume
                     round( dblGeoNext / dblLotsStep ) * dblLotsStep ) );  // Align to Step value
To add comments, please log in or register