Vous êtes sur la page 1sur 1

double Lot_Size(int Switch){

static int Saved_His_Total;


int His_Total=OrdersHistoryTotal();
if(His_Total==0){return(0.1);}
if(Saved_His_Total != His_Total){
Saved_His_Total=His_Total;
for(int i=His_Total; i>=0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)
&& OrderMagicNumber()==Magic
&& OrderSymbol()==Symbol()
){
static int Trade_Total; Trade_Total++;
static int Buy_Wins; static int Sel_Wins;
static int Buy_Loss; static int Sel_Loss;
static double Buy_Profit, Buy_Losses;
static double Sel_Profit, Sel_Losses;
if(OrderType()==OP_BUY && OrderProfit()>0){
Buy_Wins++; Buy_Profit+=OrderProfit();}
if(OrderType()==OP_BUY && OrderProfit()<=0){
Buy_Loss++; Buy_Losses+=OrderProfit();}
if(OrderType()==OP_SELL && OrderProfit()>0){
Sel_Wins++; Sel_Profit+=OrderProfit();}
if(OrderType()==OP_SELL && OrderProfit()<=0){
Sel_Loss++; Sel_Losses+=OrderProfit();} break;
} }
double Win_Total = Buy_Wins + Sel_Wins;
double Loss_Total = Buy_Loss + Sel_Loss;
double Profit_Total = Buy_Profit + Sel_Profit;
double Losses_Total = Buy_Losses + Sel_Losses;
if(Win_Total !=0){double Avg_Profit = Profit_Total / Win_Total;}
if(Loss_Total!=0){double Avg_Losses = Losses_Total / Loss_Total;}
if(Trade_Total !=0){double W2L_Ratio = Win_Total / Trade_Total;}
if(Trade_Total !=0){double L2W_Ratio = Loss_Total / Trade_Total;}
if(Avg_Losses !=0){double P2L_Ratio = Avg_Profit / Avg_Losses;}
if(Avg_Losses !=0){double Kd=Avg_Profit/Avg_Losses;}
//~~~~~~~~~~~~~~~~~~~~~
if(W2L_Ratio !=0){double RvRoulette=(0.47/W2L_Ratio)*0.1;}
//~~~~~~~~~~~~~~~~~~~~~
//http://www.trader-soft.com/money-management/index.html
if(Kd !=0){double Kelly=(W2L_Ratio-L2W_Ratio)/(Avg_Profit/Avg_Losses);}
if(P2L_Ratio!=0){double Optimal_f=((P2L_Ratio + 1)*W2L_Ratio-1)/P2L_Ratio;}
//~~~~~~~~~~~~~~~~~~~~~
if(Trade_Total==0){return(0.1);}
if(Switch=='R'){return(RvRoulette);}
if(Switch=='K'){return(Kelly);}
if(Switch=='F'){return(Optimal_f);}

Vous aimerez peut-être aussi