Mastering Prop Firm Challenges: Breakout Strategy with Handy Helper Functions for MT5

Mike 2024.05.11 12:45 17 0 0
Attachments

Hey traders,

Today, I’m excited to share an update on the Simple Yet Effective Breakout Strategy. I've added some nifty helper functions that are perfect for tackling prop firm challenges.

When it comes to passing a prop firm challenge, there are three key criteria you need to hit:

  • Target Profit
  • Maximum Daily Loss - Don't go over this!
  • Overall Maximum Loss - Stay within your limits!

This script includes two main functions: one to check if you’ve hit your target profit and another to alert you when you're close to violating your maximum daily loss. When this happens, it will automatically exit all open positions and cancel any pending orders. As for the overall maximum loss, that really hinges on your individual strategy and risk management, so it’s not specifically coded into this MQL5 script.

//+------------------------------------------------------------------+
//| Prop Firm Helper Functions                                           |
//+------------------------------------------------------------------+

// Delete all pending orders and exit all positions
void ClearAll(string message)
{
   Comment(message);
   for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
      ulong orderTicket = OrderGetTicket(i);
      if (OrderSelect(orderTicket)) 
      {
         trade.OrderDelete(orderTicket);
      }
   }

   for (int i = PositionsTotal() - 1; i >= 0; i--)
   {
      ulong posTicket = PositionGetTicket(i);
      trade.PositionClose(posTicket);
   }
}

// Check if we have achieved profit target
bool isPassed()
{
   return AccountInfoDouble(ACCOUNT_EQUITY) > PASS_CRITERIA;
}

// Check if we are about to violate maximum daily loss
bool isDailyLimit()
{
   MqlDateTime date_time;
   TimeToStruct(TimeCurrent(), date_time);
   int current_day = date_time.day, current_month = date_time.mon, current_year = date_time.year;
   
   // Current balance
   double current_balance = AccountInfoDouble(ACCOUNT_BALANCE);
   
   // Get today's closed trades PL
   HistorySelect(0, TimeCurrent());
   int orders = HistoryDealsTotal();
   
   double PL = 0.0;
   for (int i = orders - 1; i >= 0; i--)
   {
      ulong ticket=HistoryDealGetTicket(i);
      if(ticket==0)
      {
         Print("HistoryDealGetTicket failed, no trade history");
         break;
      }
      double profit = HistoryDealGetDouble(ticket,DEAL_PROFIT);
      if (profit != 0)
      {
         // Get deal datetime
         MqlDateTime deal_time;
         TimeToStruct(HistoryDealGetInteger(ticket, DEAL_TIME), deal_time);
         // Check deal time
         if (deal_time.day == current_day && deal_time.mon == current_month && deal_time.year == current_year)
         {
            PL += profit;
         }
         else
            break;
      }
   }
   double starting_balance = current_balance - PL;
   double current_equity   = AccountInfoDouble(ACCOUNT_EQUITY);
   return current_equity < starting_balance - DAILY_LOSS_LIMIT;
}

Don’t forget to set the following parameters:

input string dd = "-------------PROP FIRM CHALLENGE-----------------";
input bool   isChallenge = false;
input double PASS_CRITERIA = 110100;
input double DAILY_LOSS_LIMIT = 4500;

I hope you find this script valuable in your trading journey! Let’s make those trades count!

List
Comments 0