This great bit of code was posted in a separate thread to Increase lots with each consecutive trade (if DecreaseFactor is changed to IncreaseFactor, of course) - what is needed to make the EA revert to the initial lot amount after a positive trade, if the progression is used say only during a run of negative trades?
Tx in advance
Thatchman
extern double Lots = 1.0;
extern bool UseMoneyManagement = false;
extern bool AccountIsMicro = false;
extern int Risk = 0;
extern double DecreaseFactor = 0;
//double subLotSize()
double CalcolaLot(int Risk)
{
if(UseMoneyManagement==false) return(Lots);
double lot=Lots;
int orders=HistoryTotal();
int losses=0;
int decimalPlaces=1;
if(AccountIsMicro==true) decimalPlaces=2;
lot=NormalizeDouble((AccountFreeMargin()*Risk/1000.0)/100,decimalPlaces);
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); 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,decimalPlaces);
}
if(lot<0.1 && AccountIsMicro==false) lot=0.1;
if(lot<0.01 && AccountIsMicro==true) lot=0.01;
if(lot>99) lot=99;
return(lot);
}
Thatchman
Tx in advance
Thatchman
extern double Lots = 1.0;
extern bool UseMoneyManagement = false;
extern bool AccountIsMicro = false;
extern int Risk = 0;
extern double DecreaseFactor = 0;
//double subLotSize()
double CalcolaLot(int Risk)
{
if(UseMoneyManagement==false) return(Lots);
double lot=Lots;
int orders=HistoryTotal();
int losses=0;
int decimalPlaces=1;
if(AccountIsMicro==true) decimalPlaces=2;
lot=NormalizeDouble((AccountFreeMargin()*Risk/1000.0)/100,decimalPlaces);
if(DecreaseFactor>0)
{
for(int i=orders-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); 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,decimalPlaces);
}
if(lot<0.1 && AccountIsMicro==false) lot=0.1;
if(lot<0.01 && AccountIsMicro==true) lot=0.01;
if(lot>99) lot=99;
return(lot);
}
Thatchman
Understanding is a three-edged sword