Multi-Currency EA

 

Hi all,

I wonder if someone can shed light on the possible disadvantages of using an EA on one chart to manage a portfolio of instruments.

Attached is a basic EA which allows the user to select which pairs they want to trade, and the EA will then trade the portfolio regardless of which chart the EA is initialized on.

What are your thoughts?

input ENUM_TIMEFRAMES      Timeframe = PERIOD_CURRENT;  
input ENUM_APPLIED_PRICE   Source = PRICE_OPEN;

input    bool              EURUSD = false,
                           GBPUSD = false,
                           USDCAD = false,
                           USDJPY = false;


//+-----------------------------------------------------------------------------------------------------------------------------------------------------+
void OnTick()
  {
   if (EURUSD)
   Trade("EURUSD"); 
   
   if (GBPUSD)
   Trade("GBPUSD"); 
   
   if (USDCAD)
   Trade("USDCAD"); 
   
   if (USDJPY)
   Trade("USDJPY");  
  } 

//+-----------------------------------------------------------------------------------------------------------------------------------------------------+
double Pips(string symbol)
   {                                                                                
    double TickSize = MarketInfo(symbol, MODE_TICKSIZE);  
    if( TickSize == 0.00001 || TickSize == 0.001)                                                                    
    double Pips = TickSize * 10;                                                                                            
    else Pips = TickSize;                                                                                             
    return Pips;
   }

//+-----------------------------------------------------------------------------------------------------------------------------------------------------+
void Trade(string symbol)
   {
    if(OrdersTotal()==0 && EntryCriteria(symbol) == "Buy")
    OrderSend(
              symbol,
              OP_BUY,
              0.10,
              SymbolInfoDouble(symbol,SYMBOL_ASK),
              3,
              SymbolInfoDouble(symbol,SYMBOL_BID) - (10 * Pips(symbol)),
              SymbolInfoDouble(symbol,SYMBOL_ASK) + (50 * Pips(symbol)),
              "Test",
              0,
              0,
              clrNONE);

    if(OrdersTotal()==0 && EntryCriteria(symbol) == "Buy")
    OrderSend(symbol,
              OP_SELL,
              0.10,
              SymbolInfoDouble(symbol,SYMBOL_BID),
              3,
              SymbolInfoDouble(symbol,SYMBOL_ASK) + (10 * Pips(symbol)),
              SymbolInfoDouble(symbol,SYMBOL_BID) - (50 * Pips(symbol)),
              "Test",
              0,
              0,
              clrNONE);
   }
   
//+------------------------------------------------------------------+
string EntryCriteria(string symbol)
   {
    string Signal = "";
    
    double RSI = iRSI(symbol,Timeframe,14,Source,0);
    
    if(RSI > 70)
    Signal = "Sell";
    
    if (RSI < 30)
    Signal = "Buy";
    
    return Signal;
   }
 
TraderH1: I wonder if someone can shed light on the possible disadvantages of using an EA on one chart to manage a portfolio of instruments. Attached is a basic EA which allows the user to select which pairs they want to trade, and the EA will then trade the portfolio regardless of which chart the EA is initialized on. What are your thoughts?

You are assuming that OnTick will be called for the symbol irrespective of the symbol selected, but unfortunately for your EA code, its OnTick() event handler is only called when a new tick arrives for that chart's symbol on which the EA is placed and not the symbol select by the EA.

If the chart on which the EA is running receives a low frequency of ticks or no ticks at all during the period that the symbol selected for the EA has a higher frequency of tick activity, then the EA will not process the data in a timely fashion.

If your intention is only to trade one symbol per EA, then place the EA on the Chart with the symbol (without the user having to select the symbol via the EA). This will be the most efficient way.

The only reason to use such a setup (as your example), is if your EA is trading multiple symbols at the same time, and for those cases only, the recommended solution is as follows:

  1. Place the EA always on a symbol with the highest tick frequency possible (to maximise the OnTick call frequency).
  2. Supplement the OnTick() event activity, with OnTimer() events at a reasonable frequency to compensate when tick activity is low.

    EDIT: Alternatively, only use the OnTimer() event without the OnTick() event and process data at a regular interval (aka "heart-beat"), for example if you are only processing data on the bar's opening.


     
    Fernando Carreiro:

    You are assuming that OnTick will be called for the symbol irrespective of the symbol selected, but unfortunately for your EA code, its OnTick() event handler is only called when a new tick arrives for that chart's symbol on which the EA is placed and not the symbol select by the EA.

    If the chart on which the EA is running receives a low frequency of ticks or no ticks at all during the period that the symbol selected for the EA has a higher frequency of tick activity, then the EA will not process the data in a timely fashion.

    If your intention is only to trade one symbol per EA, then place the EA on the Chart with the symbol (without the user having to select the symbol via the EA). This will be the most efficient way.

    The only reason to use such a setup (as your example), is if your EA is trading multiple symbols at the same time, and for those cases only, the recommended solution is as follows:

    1. Place the EA always on a symbol with the highest tick frequency possible (to maximise the OnTick call frequency).
    2. Supplement the OnTick() event activity, with OnTimer() events at a reasonable frequency to compensate when tick activity is low.

      EDIT: Alternatively, only use the OnTimer() event without the OnTick() event and process data at a regular interval (aka "heart-beat"), for example if you are only processing data on the bar's opening.


      Hi Fernando,


      Thanks for your response.

      Yes so my idea would be to use the one EA to trade multiple symbols at the same time by selecting which symbols to trade within the EA settings. This way i could trade multiple trading strategies on different pairs with minimal charts open.


      Good advice about the OnTick potential issues - I hadn't thought of that. I will look into the OnTimer events to try and improve the timing of the EA!.

      Thanks again

       
      TraderH1: Thanks for your response. Yes so my idea would be to use the one EA to trade multiple symbols at the same time by selecting which symbols to trade within the EA settings. This way i could trade multiple trading strategies on different pairs with minimal charts open. Good advice about the OnTick potential issues - I hadn't thought of that. I will look into the OnTimer events to try and improve the timing of the EA!. Thanks again
      You are welcome!
       

      Copy and paste can save a lot of time, but it can also lead to many problems when you don't check it carefully.

         if(OrdersTotal()==0 && EntryCriteria(symbol) == "Buy")
          OrderSend(symbol,
                    OP_SELL,
                    0.10,
                    SymbolInfoDouble(symbol,SYMBOL_BID),
                    3,
                    SymbolInfoDouble(symbol,SYMBOL_ASK) + (10 * Pips(symbol)),
                    SymbolInfoDouble(symbol,SYMBOL_BID) - (50 * Pips(symbol)),
                    "Test",
                    0,
                    0,
                    clrNONE);

      Topics concerning MT4 and MQL4 have their own section.

      In future please post in the correct section.

      I have moved your topic to the MQL4 and Metatrader 4 section.

       
      TraderH1:

      Hi all,

      I wonder if someone can shed light on the possible disadvantages of using an EA on one chart to manage a portfolio of instruments.

      Attached is a basic EA which allows the user to select which pairs they want to trade, and the EA will then trade the portfolio regardless of which chart the EA is initialized on.

      What are your thoughts?

      arrays could act better in my opinion


      Files:
      just_buy.mq4  2 kb
       
      Keith Watford:

      Copy and paste can save a lot of time, but it can also lead to many problems when you don't check it carefully.

      Topics concerning MT4 and MQL4 have their own section.

      In future please post in the correct section.

      I have moved your topic to the MQL4 and Metatrader 4 section.

      Thanks Keith!


      Well spotted - it was just a quick example put together rather than an EA I plan to use!

      Ah okay, thanks for moving it to the correct topic; I will be sure to post in the correct section in future.

       
      Mohsen Bjp:

      arrays could act better in my opinion


      Yes that would work much better for a larger choice of instruments! Thanks!

      Reason: