Multi-currency EA doesn't perform any trades

To add comments, please log in or register
andrw11
66
andrw11  


i'm trying to make EA iterate over number of symbols but it only performs trades on the symbol specified in the strategy tester !

could you help me find the error 

#define EURUSD      "EURUSD"
#define GBPUSD      "GBPUSD"
#define USDJPY      "USDJPY"
#define USDCHF      "USDCHF"
#define USDCAD      "USDCAD"
#define AUDUSD      "AUDUSD"
#define EURGBP      "EURGBP"
#define EURJPY      "EURJPY"
#define EURAUD      "EURAUD"
#define GBPJPY      "GBPJPY"

string  valuta[10]=
  {
   EURUSD,
   GBPUSD,
   USDJPY,
   USDCHF,
   USDCAD,
   AUDUSD,
   EURGBP,
   EURJPY,
   EURAUD,
   GBPJPY
  };
  
int      N;       

int OnInit()
  {
//---
   N=ArraySize(valuta);
   for(int i=0;i<N; i++) {
   if(SymbolSelect(valuta[i] , true)) 
   valuta[i];
   }
   
//---
   return(INIT_SUCCEEDED);
  }

void OnTick()
  {
  
    for(int i=0;i<N; i++) {
    
    MqlRates pricedata [];
    ArraySetAsSeries(pricedata,true);
    int data =CopyRates(valuta[i],PERIOD_M5,0,550,pricedata);
    
    double ask = NormalizeDouble(SymbolInfoDouble(valuta[i],SYMBOL_ASK),_Digits);
    double bid = NormalizeDouble(SymbolInfoDouble(valuta[i],SYMBOL_BID),_Digits);
    
    double spread = SymbolInfoInteger(valuta[i],SYMBOL_SPREAD);
     
    here my logic for sell & buy 

   }
} 
Vladimir Karputov
Moderator
208128
Vladimir Karputov  

A simple example: if there is no position for the specified symbol, a BUY position is opened

//+------------------------------------------------------------------+
//|                                      Simple MultiСurrency EA.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.000"
/*
   barabashkakvn Trading engine 3.137
*/
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
//---
CPositionInfo  m_position;                   // object of CPositionInfo class
CTrade         m_trade;                      // object of CTrade class
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
//--- input parameters
input string   InpSymbol_0    = "EURUSD"; // Symbol name #0 (Invalid name -> OFF)
input string   InpSymbol_1    = "GBPUSD"; // Symbol name #1 (Invalid name -> OFF)
input string   InpSymbol_2    = "USDJPY"; // Symbol name #2 (Invalid name -> OFF)
input string   InpSymbol_3    = "USDCHF"; // Symbol name #3 (Invalid name -> OFF)
input string   InpSymbol_4    = "USDCAD"; // Symbol name #4 (Invalid name -> OFF)
input string   InpSymbol_5    = "AUDUSD"; // Symbol name #5 (Invalid name -> OFF)
input string   InpSymbol_6    = "EURGBP"; // Symbol name #6 (Invalid name -> OFF)
input string   InpSymbol_7    = "EURJPY"; // Symbol name #7 (Invalid name -> OFF)
input string   InpSymbol_8    = "EURAUD"; // Symbol name #8 (Invalid name -> OFF)
input string   InpSymbol_9    = "GBPJPY"; // Symbol name #9 (Invalid name -> OFF)
//---
string   m_arr_symbols[];
datetime m_last_signal              = 0;        // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   InitSymbols(InpSymbol_0);
   InitSymbols(InpSymbol_1);
   InitSymbols(InpSymbol_2);
   InitSymbols(InpSymbol_3);
   InitSymbols(InpSymbol_4);
   InitSymbols(InpSymbol_5);
   InitSymbols(InpSymbol_6);
   InitSymbols(InpSymbol_7);
   InitSymbols(InpSymbol_8);
   InitSymbols(InpSymbol_9);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- search for trading signals no more than once every 10 seconds
   datetime time_current=TimeCurrent();
   if(time_current-m_last_signal>10)
     {
      int size=ArraySize(m_arr_symbols);
      for(int i=0; i<size; i++)
        {
         if(!IsPositionExists(m_arr_symbols[i]))
            m_trade.Buy(0.01,m_arr_symbols[i]);
        }
     }
  }
//+------------------------------------------------------------------+
//| Init Symbols                                                     |
//+------------------------------------------------------------------+
void InitSymbols(const string name)
  {
   if(!m_symbol.Name(name)) // sets symbol name
     {
      Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name");
     }
   else
     {
      int size=ArraySize(m_arr_symbols);
      ArrayResize(m_arr_symbols,size+1,10);
      m_arr_symbols[size]=name;
     }
  }
//+------------------------------------------------------------------+
//| Is position exists                                               |
//+------------------------------------------------------------------+
bool IsPositionExists(const string name)
  {
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==name)
            return(true);
//---
   return(false);
  }
//+------------------------------------------------------------------+
William Roeder
22754
William Roeder  
andrw11: i'm trying to make EA iterate over number of symbols 
#define EURUSD      "EURUSD"
#define GBPUSD      "GBPUSD"

Broker's use a variety of naming patterns: EURUSD, EURUSDc, EURUSDct, EURUSDecn, EURUSDi, EURUSDm, EURUSDme, EURUSDpro, EURUSDt, "EUR.USD", "EUR/USD", "EURUSD!", "EURUSD#", "EURUSD.", "EURUSD..", "EURUSD.c", "EURUSD.cfx", "EURUSD.G", "EURUSD.i", "EURUSD.r", "EURUSD.SBe", "EURUSD.stp", "EURUSD+", "EURUSD-5", "EURUSD-m", "EURUSD-sb", etc., Financial symbols with '-', '=', '_' and '+'

If the naming pattern of your charts isn't exactly "BasQuo" then hard coded symbols fails.
To add comments, please log in or register