How to increment lot size when Equity drops

 

Hi Everyone


I'm stuck.  I'm trying to write a simple EA that would increase the lot size incrementally by 1 microlot every time that the equity drops incrementally by $200.  So if my starting equity is $1000 and it drops to $800, the lot size of the next trade should go from 0.01 to 0.02.  Then if the equity rise to say $1200 and drops for a second time by $200, the lot size should go to 0.03.  So, both the value of the highest equity (in increments of $200) and the value of the highest lot size (in increments of 0.01 lots) must be saved as a variable.  I have tried different ways to accomplish this, but do not get it to work properly.  This is what I have at the moment:

Global variables (above Start function):
extern int EquityRise=200;
extern int EquityDrop=200;
double Equityhigh=0.0; 

void Lotscalc(){
   double Equity=NormalizeDouble(AccountEquity(),2);
   int LotsD=0;
   
   if(Equityhigh==0.0){
        Equityhigh=StartEquity;
       }
   
   if(Equity>Equityhigh+EquityRise){
      Equityhigh=Equity;
     }
   
   if(Equity<Equityhigh-EquityDrop){
      LotsD++;
     }
      
      if(LotsD==1) Lots=0.02;
      else if(LotsD==2) Lots=0.03;
      else if(LotsD==3) Lots=0.04;
      else if(LotsD==4) Lots=0.05;
      else if(LotsD==5) Lots=0.06;
      else if(LotsD==6) Lots=0.07;
      else if(LotsD==7) Lots=0.08;
      else if(LotsD==8) Lots=0.09;
      else if(LotsD==9) Lots=0.1;
      else if(LotsD==10) Lots=0.11;
 
trader3000: increase the lot size incrementally by 1 microlot every time that the equity drops incrementally by $200.  So if my starting equity is $1000 and it drops to $800, the lot size of the next trade should go from 0.01 to 0.02.  Then if the equity rise to say $1200 and drops for a second time by $200, the lot size should go to 0.03. 
Lots = NormalizeLots( (Equityhigh - AccountEquity() ) /10000); // (1000-600)/10000 = 400/10000 = 4/100 = 0.04