In the extern parameters, add : Code: extern double lots=0.1; extern bool martingale=false; extern double multiplier=2.0; extern double minlot=0.01; extern double maxlot=10; After the extern parameters, add : Code: double lotsfactor=1,ilots; double initiallotsfactor=1; In the init() function, before return(), add : Code: //|---------martingale initialization int tempfactor,total=OrdersTotal(); if(tempfactor==0 && total>0) { for(int cnt=0;cnt0) { for(cnt=0;cnt0) lotsfactor=tempfactor; Before each ordersend() function, add : Code: if(martingale)ilots=NormalizeDouble(lots*martingalefactor(),2);else ilots=lots; if(ilotsmaxlot)ilots=maxlot; In the ordersend() function, replace lots by : Code: ilots At the end of the code, add : Code: //|---------martingale int martingalefactor() { int histotal=OrdersHistoryTotal(); if (histotal>0) { for(int cnt=histotal-1;cnt>=0;cnt--) { if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic) { if(OrderProfit()<0) { lotsfactor=lotsfactor*multiplier; return(lotsfactor); } else { lotsfactor=initiallotsfactor; if(lotsfactor<=0) { lotsfactor=1; } return(lotsfactor); } } } } } return(lotsfactor); }