Expert Advisor works in the strategy tester as expected, but not on the live account - page 2

 
If you are trying to pull data from a full year on every tick then it's understandable that it will be slow and thats probably your issue so you might try and reduce the size of the requests
 
Marco vd Heijden:
If you are trying to pull data from a full year on every tick then it's understandable that it will be slow and thats probably your issue so you might try and reduce the size of the requests

It also happend on that simple example of code - maybe you can take a look


int OnInit()

  {

   string SymbolNamenArrayI[36]= {   

                                    "AUDCHF","AUDJPY","AUDNZD","AUDUSD","CADCHF","CADJPY","CHFJPY","EURAUD","EURCAD","EURCHF","EURGBP","EURJPY","EURNZD","EURUSD",

                                    "EURPLN","GBPAUD","GBPCAD","GBPNZD","AUDCAD","GBPJPY","GBPUSD","GBPCHF","NZDCAD","NZDCHF","NZDJPY","NZDUSD","USDCAD","USDCHF",

                                    "USDJPY","USDPLN","USDMXN","USDZAR","USDRUB","USDCNH","EURTRY","USDTRY"

                                 };
  

   SymbolSelect(SymbolNamenArrayI[0],true);        

   SymbolSelect(SymbolNamenArrayI[1],true);        

   SymbolSelect(SymbolNamenArrayI[2],true);       

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

  }

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

double Array1[];

void OnTick() //or OnTimer()

  {
        for(int symb=0;symb<3;symb++) // <--- super slow execution?

         {  

            int GleitenderDurchschnittDef=iMA(SymbolName(symb,true),PERIOD_M15,55,0,MODE_EMA,PRICE_CLOSE);

            CopyBuffer(GleitenderDurchschnittDef,0,0,10,Array1);

            Comment(SymbolName(symb,true));  

         }//Ende For
  }//Ende OnTick

The code like this works in the strategy tester like I would expect it, but Live it doesn't

Also a picture of the strategy tester that shows that that kinde of code works in ST

 

Please edit your posts and use the code button (Alt+S) to paste code.

Also please remove all the blank lines so that others can read your code easily.

 
Keith Watford:

Please edit your posts and use the code button (Alt+S) to paste code.

Also please remove all the blank lines so that others can read your code easily.

Ok I think it should be better now

 

Ok i'm not sure why you coded it like that and it seems also incomplete.

It does not make sense to make an array with instrument names and then to call the instruments by the SymbolName() function in the loop.

You can either hardcode the names which is broker specific or you can use SymbolName() function which will retrieve the names from MarketWatch.

//+------------------------------------------------------------------+
//|                                                         Scan.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetMillisecondTimer(1000);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   double Array1[];
//---
   for(int pos=0; pos<SymbolsTotal(1); pos++)
     {
      string symbol = SymbolName(pos,1);
      //Print(symbol+" Found at Position: "+IntegerToString(pos));
      int handle1 =iMA(symbol,PERIOD_M15,55,0,MODE_EMA,PRICE_CLOSE,0);
      int copy = CopyBuffer(handle1,0,0,10,Array1);

      //...
     }
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Market Info / SymbolName
Documentation on MQL5: Market Info / SymbolName
  • www.mql5.com
[in] Request mode. If the value is true, the symbol is taken from the list of symbols selected in MarketWatch. If the value is false, the symbol is taken from the general list.
 
Marco vd Heijden:

Ok i'm not sure why you coded it like that and it seems also incomplete.

It does not make sense to make an array with instrument names and then to call the instruments by the SymbolName() function in the loop.

You can either hardcode the names which is broker specific or you can use SymbolName() function which will retrieve the names from MarketWatch.

It is there to get symbols into the market watch if they are not, especially for the strategytester but its not the part that makes the for loop slow

 
void OnTick() //or OnTimer()

  {
     double Array1[];

        for(int symb=0;symb<3;symb++) // <--- super slow execution?

         {  

            int GleitenderDurchschnittDef=iMA(SymbolName(symb,true),PERIOD_M15,55,0,MODE_EMA,PRICE_CLOSE);

            CopyBuffer(GleitenderDurchschnittDef,0,0,10,Array1);

            Comment(SymbolName(symb,true));  

         }//Ende For
  }//Ende OnTick

But this only loops over the first 3 SymbolNames.

 
Marco vd Heijden:

But this only loops over the first 3 SymbolNames.

Actually there are 36 Symbols but my problems seems to disappear after the first loop is executed which needs more than 32s. After this the code is executed in the expected short time of under 1s

 
            int GleitenderDurchschnittDef=iMA(SymbolName(symb,true),PERIOD_M15,55,0,MODE_EMA,PRICE_CLOSE);

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)

Reason: