Last account balance

 

Hello,

I'm blocking on a code.

I wish the ea keeps in memory the last highest balance, here is my code but it does not work, can you help me?

 double  highestbalance()

  {

   double highestbalance1=1000;

    if ( AccountBalance() > (highestbalance1 )) highestbalance1 = AccountBalance();

      return(highestbalance1);     

       }
 
stanlotrading:

Hello,

I'm blocking on a code.

I wish the ea keeps in memory the last highest balance, here is my code but it does not work, can you help me?

double  highestbalance()

  {

   static double highestbalance1=1000;

    if ( AccountBalance() > (highestbalance1 )) highestbalance1 = AccountBalance();

      return(highestbalance1);     

       }
 
Andrey it works, thank you very much
 
what if computer shuts down or crashes and we need to reinstall the MTx?
 
shomonrobie #:
what if computer shuts down or crashes and we need to reinstall the MTx?

Hi, I just read your comment and there are actually a couple of solutions for that:

1) the easiest solution is to use a Global Variable of the client terminal (see this article https://www.mql5.com/en/docs/globals). These are variable that (unlike normal global variables) are kept in the platform for up to 4 weeks, so if the platform shuts down you will  not lose the variable. This is something specific of Mql5.

2) another solution would be to store and retrieve the variable from a file.

Regards

Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global Variables of the Terminal - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5