Questions from Beginners MQL5 MT5 MetaTrader 5 - page 714

 
dimnik:

With the use of OnTradeTransaction, the optimisation time has strangely changed. A system on 15M, very simple, annual history, one run occurs in 0.3 - 0.4 seconds.

After optimization start the first 200-300 runs go at less than a second, the next ones slow down up to 15-20 seconds (50 times!);

No processor overheating or trolling, more than half of memory is free (from 16GB).

Before using the OnTradeTransaction handler there was nothing like that - even more complex Expert Advisors on small timeframes were optimized with approximately the same speed.

Does HistoryDealSelect affect the speed so much? How can we eliminate the lags?

void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
   if( trans.type != TRADE_TRANSACTION_DEAL_ADD) return;
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
   long     deal_type         =0;
   double   deal_volume       =0;
   long     deal_magic        =0;
   if(HistoryDealSelect(trans.deal))
     {
      deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
      deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
      deal_magic        =HistoryDealGetInteger(trans.deal,DEAL_MAGIC);
     }
   else
      return;
   if (deal_type == DEAL_TYPE_BUY && deal_magic == MagicNumber) current_position += deal_volume;
   if (deal_type == DEAL_TYPE_SELL && deal_magic == MagicNumber) current_position -= deal_volume;
      
  }


Show me all of the code.
 

Hi!

Who knows - how to display the bars to the right of the zero bar in the indicator and how many max? (price forecast to make)

 
dimnik:

Is it HistoryDealSelect that badly affects the speed? How can the slowdown be eliminated?

The developers recommend to minimize calling History-functions (expensive) - through history caching.

I posted a working solution in kodobase (MT4Orders), but it probably will not suit you.

I haven't seen any lags after using caching.

Although, your OnTradeTransaction should not slow down, even though it is not written optimally.

 
Renat Akhtyamov:

Hi!

Who knows - how to display the bars to the right of the zero bar in the indicator and how many max? (price forecast to make)

Add PeriodSeconds() to the opening time of the last bar and draw a candle there with graphical objects. The maximal amount will be shown on the right. But I haven't checked how it will be displayed if there is an exit. Probably, it should be taken into account by itself.
 
Alexey Viktorov:
Add PeriodSeconds() to the opening time of the last bar and draw a candle there with graphical objects. At most it will be visible on the right. But I haven't checked how it will be displayed if there is an exit. Probably one should take into account.
Thanks, I've got it!
 
Alexey Viktorov:
Add PeriodSeconds() to the open time of the last bar and draw the candlestick there. At most, you will see it on the right. But I haven't checked its appearance. Probably, it is necessary to take into account.

On the chart it draws a continuation, but unfortunately not in the indicator window.

Maybe I'm wrong of course...

What do you think - can I continue the indicator line beyond the zero bar to the right?

 
Who knows - is it possible to continue the indicator line beyond the zero bar to the right?
 
Renat Akhtyamov:
Who knows - can the indicator line be extended beyond the zero bar to the right?
You can. It is possible to set a shift, but it will probably not be possible to calculate by non-existing values, and time is not used in displaying the indicator. This is why I was talking about bar displaying using graphical elements. The ObjectCreate() contains both window number (subwindow) and time. There should not be any problems when creating graphical elements.
 
Alexey Viktorov:
You can. You can shift it, but the calculation will probably not be done using non-existing values and the time is not used in the indicator display. This is why I was talking about bar displaying using graphical elements. The ObjectCreate() contains both window number (subwindow) and time. Therefore, there should be no problems when creating graphical elements.

In the chart window, using the timestamps, you can refer to future intended bars. It has worked.

However I cannot do the same in the indicator window. I.e. I cannot write values in the indicator buffer with the index -1, -2, etc.

The question is this.

It is clear, in principle. The solution is to create an indicator by graphical objects.

 
Renat Akhtyamov:

In the chart window, using the timestamps, you can refer to future intended bars. It has worked.

However I cannot do the same in the indicator window. I.e. I cannot write values in the indicator buffer with the index -1, -2, etc.

The question is this.

In principle, it is clear. The solution is to create the indicator by graphical objects.

Calculate the second buffer on its normal values, for example (if we want to calculate 10 bars to display "future"), then calculate this buffer on the values Buff[9] -- Buff[8] -- Buff[n] -- Buff[0], and then display this buffer with a non-zero offset. Set the buffer offset to the desired number of bars in the future - 10 in this case
Reason: