A new guide, an easier one :
At the beginning of the code, in the extern parameters add :
Code:
extern bool martingale=false; // enable the martingale
extern double multiplier=2.0; // multiplier used for the martingale
extern double lotdigits=2; // 1 for minilot, 2 for microlot
After the extern parameters add :
Code:
double mlots,ilots,lastprofit,lastlot;
int i,history;
In the start body add :
Code:
history=OrdersHistoryTotal();
if(history>0){
for(i=0;i<history;i++){
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic){
lastprofit=OrderProfit();
lastlot=OrderLots();
}
}
}
mlots=0;
if(martingale && lastprofit<0)mlots=NormalizeDouble(lastlot*multiplier,lotdigits);else mlots=lots;
In the mm function (if you have one), add :
Code:
&& (martingale==false || (martingale && lastprofit>=0))
Before each ordersend function, add :
Code:
if(martingale)ilots=mlots;else ilots=lots;
Finally, replace lots in the ordersend function by ilots.