indicator eating lots of memory while referencing to other timeframe

 

my indicator are eating quite a lot of memory while referencing to other timeframe

like example


int MA_Direction(int TF, string Pair)
{
double F_MA = iMA(Pair, TF, 5, 0, MODE_EMA, PRICE_CLOSE, 0);
double S_MA = iMA(Pair, TF, 5, 0, MODE_EMA, PRICE_CLOSE, 1);

if(F_MA > S_MA) return(1); // UP
if(F_MA < S_MA) return(2); // DW

return(0);
}


int m1 = MA_Direction(1, NULL);

int m5 = MA_Direction(5, NULL);

int m15 = MA_Direction(15, NULL);


any solutions

 

I know this sounds stupid but try declaring the variables first then assugning the values because I have found it more efficient on several occassions. It has speeded up things for me many times maybe because the variable is already allocated the interpreter doesn't have to keep loading the code to make a variable resulting in a better program flow.

int m1,m5,15;

m1 = MA_Direction(1, NULL);

m5 = MA_Direction(5, NULL);

m15 = MA_Direction(15, NULL);

 
Ruptor:

I know this sounds stupid but try declaring the variables first then assugning the values because I have found it more efficient on several occassions. It has speeded up things for me many times maybe because the variable is already allocated the interpreter doesn't have to keep loading the code to make a variable resulting in a better program flow.

int m1,m5,15;

m1 = MA_Direction(1, NULL);

m5 = MA_Direction(5, NULL);

m15 = MA_Direction(15, NULL);



I tried, but did not lower any memory consumption.


:(

 

What about the doubles? The piece of code was just an example. Also do you have any arrays where the boundaries might be wrong that can really slow things down because the interpreter can handle it. Is the code you posted the only code used or just a bit of the total?

If you are doing this every tick it would be a waste of time.

 

I tried your code bits on 1 minute back test with no problem. It consumed 1 meg of memory and ran very fast. As I suspected it is a combination of things not just the code you posted.

 
Ruptor:

I tried your code bits on 1 minute back test with no problem. It consumed 1 meg of memory and ran very fast. As I suspected it is a combination of things not just the code you posted.


actually i code it as a indicator to see multiple time frame

can you try to code it as a indicator and check if it consume much memory.

maybe try m1, m5, m15, m30, h1, h4 and test


thanks a lot

 

Post your indy and I'll try it and/or possibly fix it. I don't really want to reinvent the wheel.

Reason: