Mt4 and memory

 

Hi, I created a complicated indicator.

It contains a structure with a 3 variables, and 2 three-dimensional arrays of these structures.

struct COORD
{
   double Price_;
   double Close_;
   datetime Time_;
};

In this buffer I got: 
First dim - timeframe (5,15,60,240)

Second dim - Depth parametr for zigzag (10,15,25...)

Third dim - time,close and zigzag value for 5 last candles

For example: Array1[0][0][0].Close_ - contains close price for the last candle that had non-zero zigzag(10,5,3) for tf M5

Array1[1][3][0].Time_ - contains close time for the last candle that had non-zero zigzag(25,5,3) for tf M15

Second array is a copy, I need it to check some conditions.

In OnTick() func I use 4 conditions:

if (iCustom(NULL,5,"ZigZag",StartDepth,InpDeviation,InpBackstep,0,1)!=0)
  refill array and some actions
if (iCustom(NULL,15,"ZigZag",StartDepth,InpDeviation,InpBackstep,0,1)!=0)
    refill array and some actions
if (iCustom(NULL,60,"ZigZag",StartDepth,InpDeviation,InpBackstep,0,1)!=0)
  refill array and some actions
if (iCustom(NULL,240,"ZigZag",StartDepth,InpDeviation,InpBackstep,0,1)!=0)
  refill array and some actions

These arrays are being refilled completely for the timeframe, that have a non-zero zigzag on the last candle

So when I put this indicator on chart it works a little bit, but then "Metatrader 4 not responding".

I tried to put these conditions in OnTimer() and check conditions once in 1 minute, but unsuccessfully.

So can you give me any tips here, how to make that work? Will VPS help here? Or maybe I should not keep all data in memory using arrays and re-calculate everything on tick or timer?

 
RomanRott:

Hi, I created a complicated indicator.

It contains a structure with a 3 variables, and 2 three-dimensional arrays of these structures.

In this buffer I got: 
First dim - timeframe (5,15,60,240)

Second dim - Depth parametr for zigzag (10,15,25...)

Third dim - time,close and zigzag value for 5 last candles

For example: Array1[0][0][0].Close_ - contains close price for the last candle that had non-zero zigzag(10,5,3) for tf M5

Array1[1][3][0].Time_ - contains close time for the last candle that had non-zero zigzag(25,5,3) for tf M15

Second array is a copy, I need it to check some conditions.

In OnTick() func I use 4 conditions:

These arrays are being refilled completely for the timeframe, that have a non-zero zigzag on the last candle

So when I put this indicator on chart it works a little bit, but then "Metatrader 4 not responding".

I tried to put these conditions in OnTimer() and check conditions once in 1 minute, but unsuccessfully.

So can you give me any tips here, how to make that work? Will VPS help here? Or maybe I should not keep all data in memory using arrays and re-calculate everything on tick or timer?


If you want help here you're going to have to post more code because the snippet you posted doesn't mean anything to anyone without any context. All I can tell from this snippet is that you have to follow Alain's advice and seriously rethink your strategy. I hope this doesn't offend, but there is never a programming scenario that requires the use of a three-dimensional array of structs. You are using the wrong design-pattern(s) and data structures.

 
nicholishen:
...You are using the wrong design-pattern(s) and data structures...

Exactly. To add imho the probability is high that the slowdown you observe is related to the use of 4 custom indicators. If a single custom indicator is not well designed it can bring the whole app to a halt. Now you have even four of them. Simplify your logic. The optimal solution is to use built-in indicators instead of custom ones. The second best approach (if built-in indicators are not sufficient) is to move the indicator logic into the EA itself and don't use custom indicators at all.

 
alphatrading:
nicholishen:

Exactly. To add imho the probability is high that the slowdown you observe is related to the use of 4 custom indicators. If a single custom indicator is not well designed it can bring the whole app to a halt. Now you have even four of them. Simplify your logic. The optimal solution is to use built-in indicators instead of custom ones. The second best approach (if built-in indicators are not sufficient) is to move the indicator logic into the EA itself and don't use custom indicators at all.


His snippet implies the use of the Metaquotes pre-packaged "ZigZag" which is as close to built-in as you're going to get for zigzag. I know from personal experience that there aren't any issues with running multiple instances of these within an EA. He's got another issue, but no way to possibly tell unless he wants to share his code...

 
nicholishen:

His snippet implies the use of the Metaquotes pre-packaged "ZigZag" which is as close to built-in as you're going to get for zigzag. I know from personal experience that there aren't any issues with running multiple instances of these within an EA. He's got another issue, but no way to possibly tell unless he wants to share his code...


I can "translate" my indicator from "memory based" into "calculation based" roughly speaking. Instead of these enormoius arrays I may have only one of size 5, but it lead to many similar calculations every tick, can you tell what is more preferable?


 
RomanRott:

I can "translate" my indicator from "memory based" into "calculation based" roughly speaking. Instead of these enormoius arrays I may have only one of size 5, but it lead to many similar calculations every tick, can you tell what is more preferable?



Please post your code or stop asking for help. These super vague posts of yours won't help anyone help you. 

 
RomanRott:

I can "translate" my indicator from "memory based" into "calculation based" roughly speaking. Instead of these enormoius arrays I may have only one of size 5, but it lead to many similar calculations every tick, can you tell what is more preferable?


I second nicholishen advice. There is no way to provide you a more useful answer. Nothing is preferable, using iCustom, or building all inside the EA with arrays or any other method can be used and all are working correctly with some SLIGHT difference if coded/designed properly, the problem you mentioned is of an other nature.

Reason: