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
//+------------------------------------------------------------------+ 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 } } //+------------------------------------------------------------------+ }
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
Thanks Samih! Reflect on your code :)
Thank You Samih!
I'll try the code with your indication.
With my best regards Samih
Algo
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));
}
}
}
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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