Finding out the balance after each deal, after EA backtesting finished.

 

Hi,
Is there a way to find what the balance was after a deal finished in the OnTester method at the end of a backtesting pass?


I noticed when we traverse through the deal and their properties, in the documentation  ENUM_DEAL_PROPERTY_DOUBLE doesnt have a resulting balance property. 

1. Is there another property we can fetch to get the resulting balance after a deal , from OnTester method?
Or do we have to manually keep track of balance after every deal from onTick method?
2. in ENUM_DEAL_TYPE , what does  DEAL_TYPE_BALANCE do? I didnt really understand the documentation description.

 
Varun Maithani:

Hi,
Is there a way to find what the balance was after a deal finished in the OnTester method at the end of a backtesting pass?


I noticed when we traverse through the deal and their properties, in the documentation  ENUM_DEAL_PROPERTY_DOUBLE doesnt have a resulting balance property. 

1. Is there another property we can fetch to get the resulting balance after a deal , from OnTester method?
Or do we have to manually keep track of balance after every deal from onTick method?
2. in ENUM_DEAL_TYPE , what does  DEAL_TYPE_BALANCE do? I didnt really understand the documentation description.

The documentation says "balance"

and there is also a credit enum which is described as "credit".

The tester says balance type for the :

  • starting balance (Which simulates a deposit)
  • our own deposit simulated in the tester
  • the withdrawal too
bool DEPOSITED=false,TESTING=false;
int OnInit()
  {
  DEPOSITED=false;
  TESTING=(bool)MQLInfoInteger(MQL_TESTER);
  return(INIT_SUCCEEDED);
  }
void OnDeinit(const int reason)
  {
  }
void OnTick()
  {
  if(TESTING){
    if(!DEPOSITED){
      DEPOSITED=true;
      TesterDeposit(1000000);
      TesterWithdrawal(100);
      //loop into the deals
        HistorySelect(0,TimeTradeServer());
        Print("Deals to Scan "+IntegerToString(HistoryDealsTotal()));
        for(int i=0;i<HistoryDealsTotal();i++){
        ulong T=HistoryDealGetTicket(i);
        if(T>0){
          Print("Deal ["+IntegerToString(T)+"] ["+EnumToString((ENUM_DEAL_TYPE)HistoryDealGetInteger(T,DEAL_TYPE))+"] ["+DoubleToString(HistoryDealGetDouble(T,DEAL_PROFIT),2)+"]");
          }
        }
      TesterStop();
      }
    }
  }


Also if you want the final balance 

      double balance_read=(double)AccountInfoDouble(ACCOUNT_BALANCE);
      Print("Final binance "+DoubleToString(balance_read,2));
 
Lorentzos Roussos #:

The documentation says "balance"

and there is also a credit enum which is described as "credit".

The tester says balance type for the :

  • starting balance (Which simulates a deposit)
  • our own deposit simulated in the tester
  • the withdrawal too


Also if you want the final balance 

okay i see. 
So there is no straightforward way to get resulting balance after a deal occured in the past. 

thanks for sharing the example that makes it very clear to understand. 
 
Varun Maithani #:
okay i see. 
So there is no straightforward way to get resulting balance after a deal occured in the past. 

thanks for sharing the example that makes it very clear to understand. 

a list of how each deal changed the balance or something ? that is in the graph i think

 
Lorentzos Roussos #:

a list of how each deal changed the balance or something ? that is in the graph i think

what do u mean by "that is in the graph"

yeah i guess we can pull all deals and calculate the changes to the initial balanc
 
Varun Maithani #:
what do u mean by "that is in the graph"

yeah i guess we can pull all deals and calculate the changes to the initial balanc

i don't understand this part actually : 

So there is no straightforward way to get resulting balance after a deal occured in the past. 
 
Lorentzos Roussos #:

i don't understand this part actually : 

i meant to say that there is no function that directly fetches the resulting balance after a deal took place. we have to manually to do the calculations 
 
Varun Maithani #:
i meant to say that there is no function that directly fetches the resulting balance after a deal took place. we have to manually to do the calculations 

there is 

double balance_read=(double)AccountInfoDouble(ACCOUNT_BALANCE);

if you want to control the behavior based on balance and equity of the system.

There is also

AccountInfoDouble(ACCOUNT_EQUITY);
 
Lorentzos Roussos #:

there is 

if you want to control the behavior based on balance and equity of the system.

There is also

i think you misunderstood me. I meant balance at end of a deal that occured many deals ago in the past. For example 10 deals ago what was the balance?
you cant get that using the ticket of that deal , u will need to calculate its profit or loss and then keep track of the balance from beginning and account for any other profit losses that occured in the past .
 
Varun Maithani #:
i think you misunderstood me. I meant balance at end of a deal that occured many deals ago in the past. For example 10 deals ago what was the balance?
you cant get that using the ticket of that deal , u will need to calculate its profit or loss and then keep track of the balance from beginning and account for any other profit losses that occured in the past .

for machine learning?

you will have to log and track the deals yeah . (and then export it to files)

 
You can also maybe define a buffer in the global space which records the new balances only after deal (close deal). As OnTick updates every tick, you need to be careful that it doesn't keep adding to the buffer. The buffer should add the new balance only after the closing deal.