I need to memorize the value of the initial account balance in a variable V at the first start of the expert

 

I need help

In my expert I need to memorize the value of the initial account balance in a variable V at the first start of the expert in order to use this value and compare it with the account equity at each tick.

So if the account equity at a certain time t is greater than the value of the initial account balance , previously stored in the variable V, I close all active orders.


Thank you

 
Algo:

I need help

In my expert I need to memorize the value of the initial account balance in a variable V at the first start of the expert in order to use this value and compare it with the account equity at each tick.

So if the account equity at a certain time t is greater than the value of the initial account balance , previously stored in the variable V, I close all active orders.


Thank you


//+------------------------------------------------------------------+
int OnInit()
  {
   GlobalVariableSet("OldBalance",AccountBalance());
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,const int prev_calculated,
                const datetime &time[],const double &open[],
                const double &high[],const double &low[],
                const double &close[],const long &tick_volume[],
                const long &volume[],const int &spread[])
  {
   if(AccountEquity()>=GlobalVariableGet("OldBalance"))
     {
      // some code here
     }
  }
//+------------------------------------------------------------------+

}
 
Samih Abdelli:


Hi Friends,


I have set my Original account balance and Lots Current in GlobalVariable.

The issue is, when I migrate to VPS, my global variable Original account balance or Lots Current or may be both are reset to 0.

Does anyone has this experience or fix of such issue ?

Thanks in advance for your reply and help.


Mandar

 
Samih Abdelli:


Thanks Samih! Reflect on your code :)

 
Samih Abdelli:


Thank You Samih!

I'll try the code with your indication.

With my best regards Samih

Algo

 
Hello everyone.
I want help with this function.
My goal is to have the value of AccountBalance of the last two closed orders and then be able to print the two values of AccountBalance: the value of AccountBalance of the order just closed and the value that the AccountBalance had when the previous one order was closed.
I don't understand where I'm wrong.

Thank you

Here the function:


void   check2LastAccountBalance(){


       double CurrentAccountBalance[100];

       double PreviousAccountBalance;

       

       for(int i=1; i<=OrdersHistoryTotal(); i++){

       

          if(OrderSelect(i-1,SELECT_BY_POS, MODE_HISTORY)){

          

             if(OrderCloseTime() !=0  &&  OrderProfit() >0){

                           

                    CurrentAccountBalance[i] = AccountBalance();

                    PreviousAccountBalance = CurrentAccountBalance[i-1];

                    

                    Print("CurrentAccountBalance[i]: "+DoubleToString(CurrentAccountBalance[i],2));

                    Print("PreviousAccountBalance: "+DoubleToString(PreviousAccountBalance,2));

                                 

             }

          }       

       }

     }