need help writing code in mql5

 

hello every one

I failed to write code that enables me to close all opening orders and pending after achieving a specific profit on a specific symbol and need to make that profit as a variable

 
mmm33hello every one I failed to write code that enables me to close all opening orders and pending after achieving a specific profit on a specific symbol and need to make that profit as a variable

Code Base

Breakout Strategy with Prop Firm Helper Functions

Anh Quan Duong, 2024.05.11 03:45

This is an update of the "Simple Yet Effective Breakout Strategy". In this code, I have added some helper functions for prop firm challenges.

 

this is how I think about it


void OnTick()
{
     if(profitTargetCheck(targetInput){
       DeleteOrders();
     }
}



bool profitTargetCheck(double profitTarget){

   for (int i = PositionsTotal() - 1; i >= 0; i--){
    
      ulong posTicket = PositionGetTicket(i);
      double posProfit = PositionGetDouble(POSITION_PROFIT);
      
      if(posTicket > 0 && posProfit >= profitTarget){
      
         trade.PositionClose(posTicket);
         return (posProfit >= profitTarget); // returning true
      }
   }
   
   return false;
}


void DeleteOrders(){

   for(int i = 0; i < OrdersTotal(); i++){
       ulong order = OrderGetTicket(i);
       if(order > 0){
           trade.OrderDelete(order);
       }
   }  
}