SendMail() in OnInit(): I receive full of mails and other problem

 

Hello,


I have an EA which sends me by email all the currencies which have a spread lower than 10, but the problem is that I receive full of mail and that the spread is worth 0 in the mail.


https://www.casimages.com/i/200424103317382606.png.html


//+------------------------------------------------------------------+
//|                                                         TEST.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"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int spread; 
string symb; 
int OnInit()
  {
  string str = "";
   for (int i=SymbolsTotal(false)-1; i>=0; --i) {
   symb = SymbolName(i, false);
   spread = SymbolInfoInteger(symb,SYMBOL_SPREAD);
    if(spread < 10){
       // Open the chart 
       str = symb + " - " + spread + "\n" + str; 
       ChartOpen(symb, PERIOD_H1);
    }
   }
   SendMail("devises", str);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
 
vbdfgdg egefe:

Hello,


I have an EA which sends me by email all the currencies which have a spread lower than 10, but the problem is that I receive full of mail and that the spread is worth 0 in the mail.


https://www.casimages.com/i/200424103317382606.png.html


This is not a problem, the spread might be floating and sometimes might be 0, you can check it at Market Watch.
But aggregating in OnInit and for multiple symbols is not a good idea, the price might be off quotes, and you might need to call RefreshRates().
There might be commission as well.
 
don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
  1. Terminal starts.
  2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
  3. OnInit is called.
  4. For indicators OnCalculate is called with any existing history.
  5. Human may have to enter password, connection to server begins.
  6. New history is received, OnCalculate called again.
  7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
 

Hello,

What I don't understand is that I have so much currency in the mail while the number of open charts is much lower, there are only 6 charts which have opened.

Reason: