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 코드
비슷한 주문
Please may someone assist me with the indicator attached, it has a SERIOUS BUG issue in the sense that when I load it, and activate the template (attached as well) MT4 ALWAYS freezes and then eventually disconnects automatically, ALL THE TIME. It even gets worse to an extent that after disconnecting a number of times mt4 ends up not loading anymore, UNTIL I remove the indicator. Please I WILL NEED A DEMO (FOR A DAY)
‎A trending candle followed by a smaller trending candle which is the second candle with no 5EMA ‎ ‎The 3rd candle is a reversal candle in which it and it's immidiate previous candle must be at least 70% of each other's body or equal body, with no 5EMA touch ‎ ‎the 3rd candle candle is followed immediately by the 4th candle which is the signal candle in which it and the 1st cabdle must be also at least 70% of
LynxMT5algo 30 - 100 USD
An mt5 add on indicator like gainalgo style to show entrance and exit areas for gold silver and Btc scalping. It will be used to make trading more easy for beginners
I have the Fisher Indicator shown below the chart. I need an alert added for when the Fisher Indicator hits the 50 point at the end of each period. GBPUSD and EURUSD 4H charts are provided and I can provide additional
Hello here, I need someone who can work on pinescript and also with Renko charts. My entries for my strategy would be based on stop orders Kindly let me know if you can work on this for me and i will send necessary file and quote in the chat
Freelance Task — EA Recovery Layer Hello. I have a ready-made MQL5 EA. The signals, SL/TP and lot calculation should essentially not be touched. I need a recovery system added. I am not a programmer — below is how the robot should behave. What stays Entry only from an EA signal. Stop-loss is not a new signal. Trailing is already built into my EA — recovery does not implement its own trailing. If trailing is disabled
# SNRZ BOT — SESSION PROGRESS LOG Last updated: 2026-09-16 (local late-evening session) ## SAN BOT (new — cloned from SNRZ) - `MQL5\Experts\AutomatedOrderBot_SAN.mq5` / `.ex5` — v1.0, compiled 0 errors/0 warnings - Signal source: custom indicator "SAN" (InpSANName, buy buf 0 / sell buf 1, target bar 1), same SNRZ-style read, MA fallback if missing - Magic number 234567 (separate from SNRZ 123456 so both bots can run
Should be as it but no alarms, also we need to add a deep search so he can see all the preves candles and a memory function so its not slowing down the indicator. for higher time frames daily 4h 1h around 365 days and for lower time frames we do up to 20k bars but both flexible so i can change it later. the memory is important so the indicator is not always recalculating everything when a new candle shows especially
Hi, I need an experienced NinjaTrader 8/NinjaScript developer to finish or rebuild an automated futures strategy, ideally by the end of this week. I already have the complete TradingView Pine Script reference strategy, an existing ~2,000-line NinjaScript implementation, Playback logs, and known historical benchmark trades. MOST IMPORTANT REQUIREMENT: TRADINGVIEW ↔ NINJATRADER PARITY. The Pine Script is the reference
I need a custom MQL5 indicator for MetaTrader 5. The indicator must automatically print entry, stop loss, and take profit zones on the chart using dots. A critical requirement is that these dots must be non-lagging and absolutely non-repainting. Additionally, the indicator needs to identify and display current supply and demand zones. Please provide the mq5 source code and the ex5 file upon completion

프로젝트 정보

예산
40+ USD
기한
로 1 일