MT5 Function that Returns the Maximum Drawdown for Symbol / Side

MQL5 Indicators Experts

Job finished

Execution time 9 hours
Feedback from customer
recommended to anyone
Feedback from employee
Clear description, quick test. A pleasure this project.

Specification

Create a Function that Returns the Maximum Drawdown for a Symbol and Side 

NOTE:

  • I am not looking for the Maximum Daily Drawdown, I am looking for the maximum drawdown for currently open trades of a referenced symbol and side.
  • Function needs to work for multi symbols 

Use this code to Count the Number of Trades for the Symbol & Side;

If number of Trades for the Symbol and side == 0 (then Maximum Drawdown is reset to Zero).

int NumberOfTrades(string symb, int OrderType)
  {
   int val=0;

   for (int cnt = 0; cnt < PositionsTotal(); cnt++) 
     {
      if(!position.SelectByIndex(cnt))
        {
         continue;
        }
      if(position.
Symbol() != symb)
         continue;
      if(position.Symbol()== symb)
         if(position.PositionType() == OrderType)
            val++;
     }
   return (val);
  }


Potentially code to leverage (or use your own).

double CalculateMaxOpenDrawdown(string symbol, ENUM_ORDER_TYPE side)
{
   // Define the variables to store drawdown information
   double maxDrawdown = 0.0;
   double dailyHigh = 0.0;
   double dailyLow = 0.0;
   int lastOrderDay = 0;

   // Iterate through open orders
   for (int i = 0; i < OrdersTotal(); i++)
   {
      // Get order ticket
      ulong ticket = OrderGetTicket(i);

      // Check if the order is for the specified symbol and side
      if (OrderGetString(ORDER_SYMBOL) == symbol && OrderGetInteger(ORDER_TYPE) == side)
      {
         // Get the order's open time and price
         datetime orderOpenTime = OrderGetInteger(ORDER_TIME_SETUP);
         double orderOpenPrice = OrderGetDouble(ORDER_PRICE_OPEN);

         // Extract the day from the order open time
         datetime serverTime = TimeCurrent(); // Use the current server time
         int orderDay = TimeDay(orderOpenTime);
         int currentDay = TimeDay(serverTime);

         // If the order day is different from the last order day, reset dailyHigh and dailyLow
         if (orderDay != lastOrderDay)
         {
            dailyHigh = orderOpenPrice;
            dailyLow = orderOpenPrice;
            lastOrderDay = orderDay;
         }

         // Update dailyHigh and dailyLow if necessary
         if (orderOpenPrice > dailyHigh)
            dailyHigh = orderOpenPrice;
         else if (orderOpenPrice < dailyLow)
            dailyLow = orderOpenPrice;

         // Calculate the drawdown for the current order
         double drawdown = side == OP_BUY ? (orderOpenPrice - dailyLow) : (dailyHigh - orderOpenPrice);

         // Update maxDrawdown if the current drawdown is greater
         if (drawdown > maxDrawdown)
            maxDrawdown = drawdown;
      }
   }

   return maxDrawdown;
}



Responded

1
Developer 1
Rating
(75)
Projects
80
6%
Arbitration
46
11% / 54%
Overdue
7
9%
Working
2
Developer 2
Rating
(9)
Projects
19
16%
Arbitration
3
67% / 0%
Overdue
0
Free
3
Developer 3
Rating
(217)
Projects
369
33%
Arbitration
34
41% / 29%
Overdue
108
29%
Free
Published: 1 code
4
Developer 4
Rating
(453)
Projects
566
26%
Arbitration
24
42% / 38%
Overdue
85
15%
Free
Published: 6 codes
Similar orders
Kenyan Editor 30+ USD
1.a specific robot to earn for a quick and reasonable trade all over. The Idear of being specific makes me perfect, I want this to be clear that make me a high luxurious person will describe me and I will promise to advertise the market both internally and externally
i need the EA same working on trading view Hikin Ashi chart with same specifications and rules on mt5 Rules as per in script is available when applied on chart need to check on Hikin Ashi chart 1. Buy trade when purple candle closed above last any black candle high on Hikin Ashi & avoid long abnormal candle & if market makes more than 20-30 candles without changing the color 2. Buy when purple candle close above its
I’m looking for an experienced developer who can build a Martingale trading bot . I’m willing to pay a fair price for the right developer. I have an example trading account that demonstrates exactly how I want the bot to operate. The strategy is simple: the bot trades continuously using a Martingale system. The only exception is that it should automatically pause trading during high-impact news events or periods of
I have my own strategy in 1min. I want it convert to a bot. Please reach me only coding experts. I dont want bit makers from Ai. Demo version should be provided for confirmation
Code the indicator to MT5 EA, include all the inputs variable and values Enable EA true or false Allow live trading Allow demo trading Allow strategy tester Bar shift 0 adjustable Lot size adjustable Max spread in points (0=disable) Use stop loss true or false Stop loss in points (adjustable) Use stop loss circle true or false Use take profit true or false Use take profit in points (adjustable) Use pending order in
Siraj Durrani 30 - 50 USD
Title: Need MT4 Expert Advisor for XAUUSD (SMC/ICT Strategy) Requirements: I need a professional MT4 Expert Advisor (EA) for XAUUSD based on Smart Money Concepts (SMC) / ICT strategy. Features: - Platform: MetaTrader 4 (MT4) - Symbol: XAUUSD - Automatic Buy and Sell trades. - Detect market trend automatically. - Use Break of Structure (BOS) and Change of Character (CHoCH) for trend confirmation. - Enter trades only
Xauusd to gold 35+ USD
The EA must be fully automated , backtest-friendly , prop-firm-safe , and built with a clean modular architecture . Core Strategy Requirements 1. Higher Timeframe Bias Use D1 and H4 . Use 200 EMA as trend filter: If price is above 200 EMA on both D1 and H4 -> allow BUY only If price is below 200 EMA on both D1 and H4 -> allow SELL only If D1 and H4 are not aligned -> no trade 2. Market Structure Module Detect and
Looking for an experienced MQL5 developer to build a professional, fully automated Multi-Timeframe trend-following Expert Advisor for MT5. The system is asset-agnostic (Forex, Gold, Indices, Crypto, and Deriv Synthetics). Core Technical Logic: Macro Trend (H4 & H1): Direction determined by Candle Close vs. EMA 200, and EMA 50 > EMA 200 crossover state. Market Structure Filter (H1): Algorithmic
Eagoldcent 30 - 200 USD
I need an MT4 & MT5 Expert Advisor for ALL pair support Cent Account. Features: Platform: MT4 & MT5 Pair: All Pair Account Type: Cent Account Buy and Sell Fixed Lot Start (user input) Lot Exponent / Multiplier (user input) PipStep / Grid Distance (user input) Take Profit (user input) Maximum Trades (user input) Magic Number (user input) Inputs: Start Lot = 0.01 Take Profit = 40 Lot Exponent = 1.50 PipStep = 40 Max
50 ( 1s ) 30 - 100 USD
I want a robot to trade volatility 50(1s) only . A robot that can make me about 100usd in less then a hour but it has to take very short entries for example 3/5 entries at the same time with a very tide stop loss and the tp to be about 10usd

Project information

Budget
40+ USD
Deadline
to 1 day(s)