EA Drawdown extraction mql4

 

Hi, i need to extract draw down per trade from an EA. I've had a go at the program (below), but i am not sure how to extract the high and low values between each trade execution. also how would i extract this directly to csv?


void OnTick()
  {
  int HighestCandle= iHighest(_Symbol,_Period,MODE_HIGH,OrderTicket(),0);
int LoweestCandle= iLowest(_Symbol,_Period,MODE_LOW,OrderTicket(),0);

Comment("High Drawdown =", High[HighestCandle], "\n",
        "Low Drawdown =", Low[LoweestCandle]);

}
 

You can't "extract" the drawdown data. You have to track and calculate it yourself in your code (which may be somewhat complex for a beginner coder).

The correct terminology is Maximum Adverse Excursion (MAE), which you can also seen in MT5 backtest reports.

 

There is an MQL4 example in the CodeBase for calculating the MAE and MFE, but it is somewhat old ...

Code Base

A Script to Calculate MAE and MFE

MetaQuotes, 2008.02.29 09:07

Drawdowns are calculated, too.

There is however an updated version on the Russian CodeBase ...

Code Base

Скрипт для расчета MAE и MFE

MetaQuotes, 2007.12.05 11:09

Рассчитываются также и просадки.
 
Fernando Carreiro #:

You can't "extract" the drawdown data. You have to track and calculate it yourself in your code (which may be somewhat complex for a beginner coder).

The correct terminology is Maximum Adverse Excursion (MAE), which you can also seen in MT5 backtest reports.

but can't you find the drawdown for each trade similar to this coding? Like every new order. I am looking at each trade, not the sum of all traded drawdown figures. The other codes aren't clear to me.


double max_drawdown;

void OnTrade()
{
   if (IsTrade()) {
      // Get the current account equity
      double equity = AccountEquity();

      // Check if this is a new order or a modification
      if (IsNewOrder()) {
         // This is a new order, set the max_drawdown variable
         max_drawdown = equity;
      } else {
         // This is a modification, calculate the drawdown
         double drawdown = (max_drawdown - equity) / max_drawdown;

         // Store the drawdown value in an array or file
         // For example, you can print it to the Experts log
         Print("Drawdown: ", drawdown);

         // Update the max_drawdown variable if necessary
         if (equity > max_drawdown) {
            max_drawdown = equity;
         }
      }
   }
}
 
OTC Australia #:but can't you find the drawdown for each trade similar to this coding? Like every new order. I am looking at each trade, not the sum of all traded drawdown figures.

No! Your example code is analysing equity drawdown for the whole account for all currently open positions as a batch. It is not calculating individual position's "drawdown" or MAE.

Also, MQL4 does not support the "OnTrade" event handler.

OTC Australia #: The other codes aren't clear to me.
That is because calculating MAE and/or MFE is somewhat complex. It can't be achieved in just a few lines of code.