[Need Advise] Stating initial AccountEquity

 

I have trouble to stating  the initial AccountEquity before any trade opened. Below code is not working because once a trade was opened the initEquity return 0.0 again.

double notradeEquity(){
   double initEquity    = 0.0;
   double nowBalance    = AccountBalance();
   double nowEquity     = AccountEquity();
   if(nowBalance==nowEquity)
     {
      initEquity = AccountEquity();
     }
   return(initEquity);  
}

What i want to achieve is the initEquity = AccountEquity() and no changing after a trade was open. So i can calculate :

double targetEquity = initEquity+(percentTarget*initEquity);
if(nowEquity >= targetEquity) CloseAll();

can anyone give me a clue?

 

You can declare "initEquity" as a static variable:

static double initEquity = 0.0;