Code_-_Money_Management.mq4

```//+------------------------------------------------------------------+
//|                                      Code - Money Management.mq4 |
//|                                           [email protected] |
//+------------------------------------------------------------------+

//---- Include
#include
#include

//---- Money Management
extern bool    MoneyManagement   = true;
extern bool    StrictManagement  = true;
extern bool    AcountIsMini      = false;
bool           Allowed           = false;

//---- Optimisation des Lots
extern double  Lots              = 0.1;
//extern double  MaximumRisk       = 0.02;
extern double  DecreaseFactor    = 3;
double         lot;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
Margin = AccountMargin();
PF = AccountBalance();
PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);
//----
return(0);
}

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----

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

//+------------------------------------------------------------------+
//| Calculs preliminaires de l'expert                                |
//+------------------------------------------------------------------+
//**************** Calcul de la posibilitй de trade ****************//
{
if (StrictManagement)
{
Allowed = True;
else
Allowed = True;
}
else
if (
)
{
Allowed = True;
}
else
Allowed = False;
}
//----
return(Allowed)
}

//************** Calcul de la taille optimale du lot ***************//
double LotsOptimized()
{
if (AcountIsMini)
Lots = 0.01;
lot=Lots;
orders=HistoryTotal();     // Historique des ordres
losses=0;                  // Nombre de trade perdants consйcutif
/* Selection de la taille du lot */
//lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000,1);
if (AcountIsMini)
else
/* Calcul du nombre de perte consecutive */
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==False)
{
Print("Erreur dans l historique!");
break;
}
if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
continue;
//----
if(OrderProfit()>0)
break;
if(OrderProfit()<0)
losses++;
}
if(losses>1)
lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
}
/* Retour de la taille du lot */
if (AcountIsMini)
if(lot<0.01)
lot=0.01;
else
if(lot<0.1)
lot=0.1;
//----
return(lot);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----

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