indicator is too slow, 3016 ms. rewrite the indicator, please.

 

I need an EA that can track multiple symbols' prices (around 10) , and open/close positions when certain prices meet certain conditions. 

I know that if the EA is attached to one symbol, then the OnTick() function will notify the EA when the bid/ask price of the symbol changes. I basically need the EA to get notified when the price of any of the symbols I'm tracking changes, with minimum delay of course. I am not interested in past prices and history data, only the current bid/ask prices.

At first my approach was to set a timer to tick every 1 millisecond using:

EventSetMillisecondTimer(1);

And then in the OnTimer function I get the tick for ALL the symbols I'm tracking and store bid/ask values in corresponding arrays:

string symbolsList[] = {"EURUSD","USDCHF","EURGBP","GBPUSD","USDCAD","EURAUD","EURCAD","EURCHF","GBPCAD","GBPCHF","GBPAUD"};

void OnTimer() {
        for (int i = 0; i < numSymbols; i++){
                MqlTick latestPrice;
                SymbolInfoTick(symbolsList[i],Latest_Price);
                bids[i] = latestPrice.bid;
                asks[i] = latestPrice.ask;
        }
        analyzePrices(); // this function will loop through the bids and asks arrays and will decide if it's time to open/close positions based on the prices
}

The problem with this approach is that:

1) As described in MQL documentation, even when you pass 1 to EventSetMillisecondTimer, it still does not call onTimer every 1 ms, because of software limitation. Based on my tests, EventSetMillisecondTimer(1) calls OnTimer every ~15 ms on average. That means if a symbol changes its price shortly after OnTimer is called, the EA will not get notified of the price change and will need to wait around 15 ms for the next OnTimer call to fetch the new prices. Although 15 ms does not sound like a long time, I'm modelling an HFT EA, so it is a big problem.

2) With this approach, every time OnTimer is called, ALL symbols prices are fetched, even those who have not had a price change since the last OnTimer call. This is inefficient for the purpose of HFT.

---

I then saw this comment, and therefore I implemented the following solution (this is the solution that gives me "indicator is too slow" error").


EA Code:

int OnInit(){
    for(int i = 0 ; i <NUMSYMBOLS; i++) {
        if (symbolsList[i]==_Symbol) continue;
        iCustom(symbolsList[i], PERIOD_CURRENT, "tickTracker.ex5", ChartID(), i);
    }
}

void OnChartEvent(const int id, const long &lparam, const double&, const string&) {
    if(id == CHARTEVENT_CUSTOM)
        OnTick(lparam);
}

void OnTick(long lparam) {
    MqlTick tick;
    int i = (int) lparam;
    string symbol = symbolsList[i];
    if(!SymbolInfoTick(symbol,tick)) {
        Print("Failed to fetch tick info for ", symbol);
        return;
    }
    asks[i] = tick.ask;
    bids[i] = tick.bid;
    analyzePrices();
    
}

void OnTick() {
    OnTick(_Symbol);
}


Indicator code (TickTracker.mq5):

#property indicator_chart_window
#property indicator_plots 0

input long Chart = 0;
input int Index = 0;

int OnCalculate( const int rates_total, const int prev_calculated, const int, const double &[] )
{
  if (prev_calculated)
    EventChartCustom(Chart, 0, Index, 0, NULL);  
  return(rates_total);
}


This solution gives me "indicator is too slow" error, especially when symbolsList contains 4+ symbols. I doubt that the problem is caused due to lack of resources, the computer I'm running this on has the following specs:

CPU: Xeon EP-2699 QuadCore @ 2.2 GHz

16 GB RAM

All other applications are closed and Metatrader is the only application running.

Any suggestions?

Thanks

Multi symbol tick event
Multi symbol tick event
  • 2018.04.12
  • www.mql5.com
Hi, I'm working on an indicator which makes the same calculation process for each symbol of an internal list selected by the user (for exemple : E...
 
afshin_j:

This solution gives me "indicator is too slow" error, especially when symbolsList contains 4+ symbols. I doubt that the problem is caused due to lack of resources, the computer I'm running this on has the following specs:

CPU: Xeon EP-2699 QuadCore @ 2.2 GHz

16 GB RAM

All other applications are closed and Metatrader is the only application running.

Any suggestions?

Thanks

You are on the right track but missing the prize.

The agent is already aware of a new tick and it's value as that is what triggers it to send the event. So just send the new tick value with the event notification, this will save you looking up the new price in the EA when it has already been delivered to the terminal once.

 
afshin_j:

I need an EA that can track multiple symbols' prices (around 10) , and open/close positions when certain prices meet certain conditions. 

I know that if the EA is attached to one symbol, then the OnTick() function will notify the EA when the bid/ask price of the symbol changes. I basically need the EA to get notified when the price of any of the symbols I'm tracking changes, with minimum delay of course. I am not interested in past prices and history data, only the current bid/ask prices.

At first my approach was to set a timer to tick every 1 millisecond using:

And then in the OnTimer function I get the tick for ALL the symbols I'm tracking and store bid/ask values in corresponding arrays:

The problem with this approach is that:

1) As described in MQL documentation, even when you pass 1 to EventSetMillisecondTimer, it still does not call onTimer every 1 ms, because of software limitation. Based on my tests, EventSetMillisecondTimer(1) calls OnTimer every ~15 ms on average. That means if a symbol changes its price shortly after OnTimer is called, the EA will not get notified of the price change and will need to wait around 15 ms for the next OnTimer call to fetch the new prices. Although 15 ms does not sound like a long time, I'm modelling an HFT EA, so it is a big problem.

2) With this approach, every time OnTimer is called, ALL symbols prices are fetched, even those who have not had a price change since the last OnTimer call. This is inefficient for the purpose of HFT.

---

I then saw this comment, and therefore I implemented the following solution (this is the solution that gives me "indicator is too slow" error").


EA Code:


Indicator code (TickTracker.mq5):


This solution gives me "indicator is too slow" error, especially when symbolsList contains 4+ symbols. I doubt that the problem is caused due to lack of resources, the computer I'm running this on has the following specs:

CPU: Xeon EP-2699 QuadCore @ 2.2 GHz

16 GB RAM

All other applications are closed and Metatrader is the only application running.

Any suggestions?

Thanks

Did you solved? I have the same problem

 
afshin_j: 2) With this approach, every time OnTimer is called, ALL symbols prices are fetched, even those who have not had a price change since the last OnTimer call. This is inefficient for the purpose of HFT.

So stop polling and get called only when a price changes.
          The Implementation of a Multi-currency Mode in MetaTrader 5 - MQL5 Articles (2011)