How to apply EA to one symbol only

 

I have a simple EA that closes my orders at a time that I specify with inputs.

At the moment it closes ALL my orders but I'd like to update this EA to only apply to the symbol NZDCHF.

Something to note is that I trade multiple accounts that have different names for the same symbol, such as "NZDCHF.i" or "NZDCHF.raw" and I'd like to apply this EA across all accounts.

How can I implement a rule so that the EA only closes trades when the order is for a symbol containing "NZDCHF", while keeping orders for all other symbols open?


My code is attached as a file and also down below:

#include <Trade/Trade.mqh>

input int CloseTimeHour = 23;
input int CloseTimeMin = 58;

int OnInit(){

   return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason){
   
}

void OnTick(){
   MqlDateTime structTime;
   TimeCurrent(structTime);
   
   structTime.hour = CloseTimeHour;
   structTime.min = CloseTimeMin;
   
   datetime timeClose = StructToTime(structTime);

   if(TimeCurrent() > timeClose){
      CTrade trade;
      for(int i = PositionsTotal()-1; i >= 0; i--){
         ulong posTicket = PositionGetTicket(i);
         if(PositionSelectByTicket(posTicket)){
            if(trade.PositionClose(posTicket)){
               Print(__FUNCTION__," > Pos #",posTicket," was closed because of close time.");
            }
         }
      }
   }
   
   Comment("\nServer Time: ",TimeCurrent(),
           "\nClose Time: ",timeClose);   
}
NZDCHF - New Zealand Dollar vs Swiss Franc - Today's currency exchange rates — Forex exchange rates
NZDCHF - New Zealand Dollar vs Swiss Franc - Today's currency exchange rates — Forex exchange rates
  • 2024.12.05
  • www.mql5.com
NZDCHF - New Zealand Dollar vs Swiss Franc - Most popular currency pair charts. Use the filter below to select the exchange rates you need. Each chart features Bid/Ask prices, as well as daily growth.
Files:
MQL5_code.txt  1 kb
 

When you post code please use the CODE button (Alt-S) !

NOTE: Traders and coders are working for free:

  • if it is interesting for them personally, or
  • if it is interesting for many members on this forum.

Freelance section of the forum should be used in most of the cases.


Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.12.06
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Thank you for the feedback @Oleksandr Medviediev. Should I move this to the Freelance section?
 
rpouwels94 #:
Thank you for the feedback @Oleksandr Medviediev. Should I move this to the Freelance section?

Yes, that's your best bet - go to https://www.mql5.com/en/job and follow the procedure.

NOTE: use of AI for coding is a waste of time at the moment.

Good luck!
🙂

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.12.06
  • www.mql5.com
The largest freelance service with MQL5 application developers
 

You might use SymbolInfoString with SYMBOL_CURRENCY_PROFIT and SYMBOL_CURRENCY_BASE to extract base and profit currency from you symbol, then check for "NZD" and "CHF"  correspondence.

That works no matter the symbol suffix or prefix.

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893