period limit in iMA function?

 
I did an expert, and optimized it severeal days on historical data, it looks good.
so I decided to test it on real data but nothing happens
after checking, it turned out that CopyBufer hangs when copying data from the iMA function where the period is set to over 100,000
but it only hangs on real data - it worked great on test data - I don't understand it

but I have a question: is there any period limit in the iMA function - is there any way to increase it?

In OnInit() ...

for (int i = 0;i<ile_srednich;i++)
{  
   int p = StringToInteger(sredniear[i]);
   tabSrednich[i].period=p;
   tabSrednich[i].handle = iMA(my_symbol, my_timeframe, p, 0, MODE_EMA, PRICE_CLOSE); // i create handle
   ArraySetAsSeries(tabSrednich[i].array,true);
   sc_indexes.Add(p,i);
   naglowek+=";sc"+sredniear[i];
   ArrayResize(tabSrednich[i].array,11);
}

In OnTick() ...

for (int i = 0;i<ile_srednich;i++)
{
   CopyBuffer(tabSrednich[i].handle, 0, 0, 11, tabSrednich[i].array); // it stop working there if period for this handle
                                                                      // is bigger than 100 000
         
}

Documentation on MQL5: Python Integration / order_calc_margin
Documentation on MQL5: Python Integration / order_calc_margin
  • www.mql5.com
order_calc_margin - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
barpas:
I did an expert, and optimized it severeal days on historical data, it looks good.
so I decided to test it on real data but nothing happens
after checking, it turned out that CopyBufer hangs when copying data from the iMA function where the period is set to over 100,000
but it only hangs on real data - it worked great on test data - I don't understand it

but I have a question: is there any period limit in the iMA function - is there any way to increase it?

In OnInit() ...

In OnTick() ...


The Tester downloads and provides data based on the request of your code.

The terminal has an option setting to specify the amount of data. Check if your chart offers enough bars to calculate your MA. Press "F8" to check your settings.
 
Thank you very much for your help, in fact the chart options were set to 100,000 bars
I changed this setting to 250,000 and expert works, but it takes a few minutes before it even starts calculating the variable values (I see it because after the calculation it puts a comment on the chart)

and now the question is: does he have this delay only in the first calculation? or will it react to each bar change after a few minutes ?

(In fact, the question is whether, after running such a script containing very long averages, it prepares something (and hence such long calculations) and then runs quickly, or whether it will carry out these long calculations after each change of the bar.)

 
barpas #:
Thank you very much for your help, in fact the chart options were set to 100,000 bars
I changed this setting to 250,000 and expert works, but it takes a few minutes before it even starts calculating the variable values (I see it because after the calculation it puts a comment on the chart)

and now the question is: does he have this delay only in the first calculation? or will it react to each bar change after a few minutes ?

(In fact, the question is whether, after running such a script containing very long averages, it prepares something (and hence such long calculations) and then runs quickly, or whether it will carry out these long calculations after each change of the bar.)

I suggest using a ring buffer instead of relying on iMA, if you want high speed with such large period consideration.



 

I understand what you want to say, but I was convinced that MT5 does it itself. How else can you explain that a script that calculates 64 very long averages every minute performs a 3-year test in 1.5 minutes?

if the test performs 11520 cycles every second - how can it not keep up with 1 cycle per minute in real mode???

 
barpas #:

I understand what you want to say, but I was convinced that MT5 does it itself. How else can you explain that a script that calculates 64 very long averages every minute performs a 3-year test in 1.5 minutes?

if the test performs 11520 cycles every second - how can it not keep up with 1 cycle per minute in real mode???

I explain it like this:

Assumption: one-day = 1440 minutes. One week = 5 days. One year = 52 weeks.

Three years = about 1.100.000 bars

64 indicators makes a total of round about, let's say 75 million bars.

1.5 minutes = 90 seconds. Let's be generous, and round up to 100.

This concludes 750.000 bars per second. Now this is our baseline throughput.

Let's say you have a processor with a base frequency of 4 GHz. This means the processor is capable of 1 billion additions per second. Per core. 4 clock cycles per addition.

Let's be generous again and say, we need 100 clock cycles per bar, per value.

This would mean the CPU is capable of processing 40 million bars per second. - OK. Let's assume there are additional things happening, like memory arithmetic and other stuff... Let's say we need 1000 cycles per bar-value. This would still mean, one core is capable of processing 4 million bars per second.

Looking at the calculations above, I would say you manage to get 20% of the "theoretical" throughput of your CPU.

Are you still the opinion, this is efficient?

EDIT:
Depending on your indicator, the tester will precalculate the values of the indicators and use the cached results from there on forward.
 

that's exactly what I mean!!!

tester should be very fast and it is very fast ...

but why, if the tester is so fast, it can't keep up with real data?

(I pasted the variable calculation time in my comment, it is 4-5 minutes late compared to the current bar)