• Sign up >>

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

To add comments, please log in or register
Marco vd Heijden
Moderator
12770
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
DasUnding
61
DasUnding  
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

Keith Watford
Moderator
21012
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.

DasUnding
61
DasUnding  
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

Marco vd Heijden
Moderator
12770
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.

//+------------------------------------------------------------------+
//|                                                         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.
DasUnding
61
DasUnding  
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

Marco vd Heijden
Moderator
12770
Marco vd Heijden  
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.

DasUnding
61
DasUnding  
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

12
To add comments, please log in or register