Strategy for obtaining Equity history during optimization

 
Hi, during optimization I need to calculate the Sortino indicator, but for Equity. 

For Balance it is simple: based on the history of deals.

Please suggest strategies on how to collect equity data during optimization, so that the data can be processed in OnTester().

Thx in advance,
Koval
 
create an equity indicator 

good luck
 
Soewono Effendi #:
create an equity indicator 

It's not so easy. We need to ask OP how he would like to calculate equity: per tick -> per second -> per bar -- in the order of lowering accuracy. Indicator will definitely show equity per bars.

Not to mention that there can be a multi-symbol trading strategy which implies more difficulties.

 
Stanislav Korotky #:

It's not so easy. We need to ask OP how he would like to calculate equity: per tick -> per second -> per bar -- in the order of lowering accuracy. Indicator will definitely show equity per bars.

Not to mention that there can be a multi-symbol trading strategy which implies more difficulties.

Hi, Im trying to gather Equity per trade, something like equity drawing during testing, my idea is:

In OnTrade()

1) catch deal in / deal out

2) store current equity in buffer

When test passed, then calculate differences and for them: %return and stdev. 

 
funkykoval #:

Hi, Im trying to gather Equity per trade, something like equity drawing during testing, my idea is:

In OnTrade()

1) catch deal in / deal out

2) store current equity in buffer

When test passed, then calculate differences and for them: %return and stdev. 

This is not accurate calculation of equity - you don't catch possible big price movements during existence of your positions, which is essential for Sortino, not to mention that stopouts can be easily overlooked.

 
Stanislav Korotky #:

This is not accurate calculation of equity - you don't catch possible big price movements during existence of your positions, which is essential for Sortino, not to mention that stopouts can be easily overlooked.

Yes, I agree, it looks I should sample equity at least by bar or minites/second.
 
You might want to check this out:

https://www.mql5.com/en/articles/3046

enjoy
Analyzing Balance/Equity graphs by symbols and EAs' ORDER_MAGIC
Analyzing Balance/Equity graphs by symbols and EAs' ORDER_MAGIC
  • www.mql5.com
With the introduction of hedging, MetaTrader 5 provides an excellent opportunity to trade several Expert Advisors on a single trading account simultaneously. When one strategy is profitable, while the second one is loss-making, the profit graph may hang around zero. In this case, it is useful to build the Balance and Equity graphs for each trading strategy separately.
 
funkykoval #:
Yes, I agree, it looks I should sample equity at least by bar or minites/second.
input group    "Optimisation"
sinput bool fixedRiskOptimisation = true;

bool isTester = false;
double returnsCurve[], startEquity, lastEquity;
int returnsCurveSize = 0;                // Track size of returnsCurve to avoid ArraySize() calls
int returnsCurveCapacity = 1000;    // Pre-allocated capacity
int dayCount = 0;

//+------------------------------------------------------------------+
//| Optimized update return curve function                           |
//+------------------------------------------------------------------+
void updateReturnCurve() {
// Check if we need to resize the array
   if(returnsCurveSize >= returnsCurveCapacity) {
      // Double the capacity for efficient growth (amortized constant time)
      returnsCurveCapacity *= 2;
      ArrayResize(returnsCurve, returnsCurveCapacity);
   }

   double currentEquity = AccountInfoDouble(ACCOUNT_EQUITY);
   if(returnsCurveSize == 0) {
      lastEquity = startEquity;
   }
// Add the new value to the array
   returnsCurve[returnsCurveSize] = fixedRiskOptimisation && isTester ?
                                    currentEquity : // Equity Curve
                                    MathLog(currentEquity); // Returns Curve

// Increment size counter
   returnsCurveSize++;

// Update lastEquity for next calculation
   lastEquity = currentEquity;

}

Then in OnTesterInit do isTester = true;

This gives you updateReturnCurve() to call as frequently as you want to record either Equity if(

fixedRiskOptimisation && isTester

) when your ideal equity curve is exponential rise (ie with dynamic position sizing in live trading, determined in your volume calculation according to

fixedRiskOptimisation

) but you want a straight line for calculation of eg R2 in Tester

or

log(equity) to enable trading with dynamic volume but a straight line returns curve eg for calculation of R2 in live trading.


The curve is, of course, represented by returnsCurve[] - my naming reflects the development of this which is a small portion of my optimisation include file