money management and lotoptimize method

 

I try to use these code to manage my money,but an problem is I don't know how to descirbe my initital money(priniciple) .my method is cotrol lot :use priniciple 's maximumrisk+3 times about of profit(or loss)'s maximunrisk as lot,it profit>0,it will enlarge,otherwise,the vise.

double LotsOptimized()
  {
   double b,lot;//=Lots;
   int    orders=HistoryTotal();    
   int    losses=0,wins=0;  
   int    c,e,f,d;
   b=iATR(NULL,0,60,0); 
   c=AccountLeverage(); 
   
   d=AccountFreeMargin();//I wanna use it describe account's principal,but couldn't how to express
   if(orders>=1)
   {e=AccountFreeMargin(); }            
   Print(MarketInfo(Symbol(), MODE_LOTSIZE));
   Print(MarketInfo(Symbol(), MODE_LOTSTEP));
   Print(MarketInfo(Symbol(), MODE_MAXLOT));
   Print("this accountleverage is",c);
   if(d!=0)  
   lot=NormalizeDouble((e*MaximumRisk/2000)*(1+3*(e/d-1)),2);//if profitiable,increase position,otherwise,the vice
   if(lot<0.01) lot=0.01;
   return(lot);
  }

but the first order's position still be 0.01(the mini lot of my MM terminal), these follow will be normal,don't know why. And I know the d==e in my code,so e/d always=1, but I wanna use d stands principal,but how do?TKS!
And have another method of lotoptimize,if solve this,I will list that one here!:p

 
univetsity:

I try to use these code to manage my money,but an problem is I don't know how to descirbe my initital money(priniciple) .my method is cotrol lot :use priniciple 's maximumrisk+3 times about of profit(or loss)'s maximunrisk as lot,it profit>0,it will enlarge,otherwise,the vise.

but the first order's position still be 0.01(the mini lot of my MM terminal), these follow will be normal,don't know why. And I know the d==e in my code,so e/d always=1, but I wanna use d stands principal,but how do?TKS!
And have another method of lotoptimize,if solve this,I will list that one here!:p


nobody care this?:(
 

Not sure if i understood this correctly.

extern double Balance.Start=10000;
double calcLot(){
       double Balance.Current=AccountBalance()
       double Profit=Balance.Current-Balance.Start;
       if(Profit>0){

       }else{

       }
}

the better, solution is to loop trough all your history, and calculate your profit yourself. This works fine unless your broker is deleting some of the older history.

Reason: