Features of the mql5 language, subtleties and tricks - page 68

 
Quick implementation of multisymbol OnTick

Forum on trading, automated trading systems and trading strategies testing

Analysis of test results and optimization in the MetaTrader 5 strategy tester

fxsaber, 2018.01.28 12:25

Indicator

#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);
}


Expert Advisor

input int AmountSymbols = 1;

const string Symbols[] = {"EURUSD", "GBPUSD", "AUDUSD", "USDJPY", "USDCAD"};

void OnInit()
{
  for (int i = 0; i < AmountSymbols; i++)
    if (Symbols[i] != _Symbol)
      iCustom(Symbols[i], PERIOD_W1, "Spy.ex5", ChartID(), i); // MQL5\Indicators\Spy.ex5
}

void OnTick()
{
  OnTick(_Symbol); 
}

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

// Мультисимвольный OnTick
void OnTick( const string &Symb )
{
}
 
fxsaber:
Quick implementation of a multisymbol OnTick
Can I use it instead of a timer? See
 
Vladislav Andruschenko:
Can I use it instead of a timer? Let's see

Yes, OnInit is subscribing to symbols from an array

Forum on trading, automated trading systems and trading strategies testing

The sequence of Init() and DeInit() execution

Slava, 2017.04.14 10:21

The services will have OnTick(string symbol). But for the ticks from a particular symbol will have to be subscribed
 

Forum on trading, automated trading systems and trading strategies testing

Analysis of test results and optimization in MetaTrader 5 strategy tester

fxsaber, 2018.01.29 15:24

The speed of Optimize depends on the sequence of passes. If first there are single-character passes, and then - multisymbol passes, the execution time will be less than in the reverse sequence of Optimization passes.
After the mandatory MQL5 Code Optimization to raise the productivity, try to save on the Cloud in this manner as well.


ZS Probably 90% of cloud money could be saved by normal code writing. But that's the last thing the authors are thinking about.

 
fxsaber:
Quick implementation of multisymbol OnTick

Cool!!!
This really works even without the long-awaited services.

Thank you very much!

I tried my best in MQL4, but it did not work. The iCustom indicator still simulates user messages for about 10 milliseconds after the last iCustom request, and keeps "silent" after that.

 
Nikolai Semko:

I tried to use it in MQL4, but it did not work. The iCustom indicator simulates the user messages for about 10 milliseconds after the last call of iCustom, and then it "stops".

In MT4, the Terminal itself tracks the life of indicator "handles". Therefore, this solution is not suitable.


This method was described more than 7 years ago.

Реализация мультивалютного режима в MetaTrader 5
Реализация мультивалютного режима в MetaTrader 5
  • 2011.01.10
  • Konstantin Gruzdev
  • www.mql5.com
В настоящее время мультивалютных торговых систем, индикаторов и экспертов разработано огромное количество. Тем не менее, до сих пор создатели этого "огромного количества" сталкивались со специфическими для мультивалютных систем трудностями. С выпуском в свет терминала MetaTrader 5 и языка программирования MQL5 появилась возможность  реализации...
 
When sending orders manually, OrderCheck is always called first. And if it is not passed, the trade order is not sent.
 
OnTradeTransaction allows you to write a non-trading Expert Advisor (Service) tracking the presence of a running trading "clone" on your account. Such situations sometimes happen due to inattention.
 
In MT5, even when deleting orders, you need to consider its peculiarities. Example on SB.

Forum on trading, automated trading systems and trading strategies testing

Expert Advisors: VR---ZVER v.2

fxsaber, 2018.02.06 11:29

void DeleteAllOrders()
  {
   for(int i=OrdersTotal()-1;i>=0;i--)
      if(m_order.SelectByIndex(i) && (m_order.State() == ORDER_STATE_PLACED))
         if(m_order.Symbol()==m_symbol.Name() && m_order.Magic()==m_magic)
            m_trade.OrderDelete(m_order.Ticket());
  }
And, of course, it is desirable to re-run the cycle after OrderDelete.
 
fxsaber:
Quick implementation of multisymbol OnTick
there can be tick skips
Reason: