MT5 Function that Returns the Maximum Drawdown for Symbol / Side

MQL5 지표 EA

작업 종료됨

실행 시간 9 시간
고객의 피드백
recommended to anyone
피고용인의 피드백
Clear description, quick test. A pleasure this project.

명시

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;
}



응답함

1
개발자 1
등급
(75)
프로젝트
80
6%
중재
46
11% / 54%
기한 초과
7
9%
작업중
2
개발자 2
등급
(9)
프로젝트
19
16%
중재
3
67% / 0%
기한 초과
0
무료
3
개발자 3
등급
(217)
프로젝트
369
33%
중재
34
41% / 29%
기한 초과
108
29%
무료
게재됨: 1 코드
4
개발자 4
등급
(453)
프로젝트
566
26%
중재
24
42% / 38%
기한 초과
85
15%
무료
게재됨: 6 코드
비슷한 주문
Mt5 ea 30+ USD
I have a fast execution ea that need a little touch, it trade on gold and my problem is about the risk ratio the tp is 3pip and stop loss 20 but i cannot get it right to make the average win larger and average loss lower. I would like to know if i can get help to get it right without touching the tragedy and the trade frequency. Those two pictures I attached is the example of what my bot actually do like i explained
hello could you make me same indicator for ninja ? https://www.youtube.com/watch?v=pxs2MuqvH3w if yes for how much and timeline ? thks in advance and please reply me as soon as possible you get my notification
Hello, I want a simple bot for NinjaTrader8. I need a bot that operates automatically on Nasdaq (NQ/MNQ). Requirements: open buys and sells following a simple trend strategy, configurable stop loss and take profit, risk per trade of 1 to 2% of capital, if it loses 3% in a day, stop trading until the next day. Compatible with backtesting, delivery of the source code and the working bot in NinjaTrader 8. My initial
[8/4/2026 4:54 AM] DR.HassaN: AI Gold Analysis Web Platform Requirements Hello, I would like to build a professional AI-powered web platform dedicated exclusively to Gold (XAU/USD) analysis . This is NOT a trading platform or broker . It is an intelligent analysis platform that provides high-quality trading signals and detailed market analysis. The platform should have a modern, premium design with my own branding
Ema100+Fibo 30+ USD
I need a robot that sends me a notification when the price aligns with the EMA and my Fibonacci levels—using specific Fibonacci settings—and then either opens a trade based on the Fibonacci SL and TP or simply sends me a notification. And I want the robot to run in both the Strategy Tester and on a demo account, so I can test it beforehand
I need a custom technical indicator that generates an equidistant channel with two specific structural features: 1. Vertical Multi-Intervals: The ability to plot more than 5 parallel, able to allow me to put intervals 2. Horizontal Angle Input: The ability to manually input geometric angle to strictly define the horizontal slope of the channel or allow me to pick two points manually. i am looking for something like
//+------------------------------------------------------------------+ //| DX_Structure_H1.mq5 | //| Copyright 2026, Seu Nome | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2026" #property link " https://www.mql5.com " #property version "1.00" #property strict // Parâmetros de Entrada input string InpSymbol = "DX.F"; // Nome do Ativo
Hola, traders e inversores: Desarrollamos soluciones de trading algorítmico para MetaTrader 4 y MetaTrader 5. Creamos bots, indicadores y herramientas a medida que convierten estrategias manuales en sistemas automáticos, configurables y orientados a una gestión de riesgo sólida. Hemos trabajado en automatizaciones que integran entradas y salidas por reglas, cálculo de lotaje, control de drawdown, filtros de horario y
> "I am looking for a reliable and profitable Expert Advisor (EA) or trading robot for MetaTrader. The EA should have a proven track record, good risk management, and stable performance in live market conditions. Please share the name of the EA, a brief explanation of how its strategy works, and any relevant performance statistics or backtest reports to help me evaluate it."
I have an MT4 custom indicator (.ex4) that I use regularly, and I would like an identical MT5 version. Important: I do not have the source code (.mq4). I only have the compiled MT4 indicator. I am looking for an experienced MQL developer who can recreate the indicator's functionality and appearance for MT5 by analyzing its behavior. The MT5 version should match the MT4 version as closely as possible, including

프로젝트 정보

예산
40+ USD
기한
 1 일