Optimizing Your EA Template for MetaTrader 4: A Practical Approach

Mike 2008.05.31 17:53 20 0 0
Attachments

Enhance Your Trading Experience with a Revised EA Template

If you're looking to streamline your trading process, I've got a handy revised EA template for you. This template is designed to work seamlessly with MetaTrader 4, and it's all about minimizing redundancy and optimizing performance.

Check out the attached template in my article MetaEditor: Templates as a Spot to Stand On. The goal here was to cut down on unnecessary size definitions for service arrays and to make dynamic changes to these arrays more efficient. With this update, service arrays are pre-allocated to handle up to 100 orders right off the bat.

Key Features of the Revised Template

  • Order Counters: We’ve included counters to track the size of different arrays:
int OurTicketsCounter;   // Tracks friendly orders, limits for arrays Tickets[100][9], CommentsTicket[100][2]
int SL_TP_Counter;       // Tracks orders to be modified: for array newSL_and_TP[100][5]
int OrdersToCloseCounter;// Tracks orders to be closed: for arrays ticketsToClose[100][2] and lotsToClose[100]
int OrdersToDeleteCounter;// Tracks orders to be deleted: for arrays ticketsToDelete[100]

Each of these counters is initialized to zero every time the start() function is launched, thanks to a dedicated function called InitCounters():

//+------------------------------------------------------------------+
//| Reset all service array counters                                   |
//+------------------------------------------------------------------+
void InitCounters()
   {
//----
   OurTicketsCounter = 0;
   SL_TP_Counter = 0;
   OrdersToCloseCounter = 0;
   OrdersToDeleteCounter = 0;
//----
   return;
   }

After making these modifications, the EA created using this template has only a slight performance gap—losing out just two times compared to a manually crafted EA. I’d say that’s a pretty solid outcome!

Be sure to save your revised template in the experts/templates folder for easy access.


List
Comments 0