Very slow calculation time for LWMA, I need help optimising MA on Array - page 2

 
winGou- #:

Sorry I realised my first post wasn't clear enough, i'm not writing an indicator, i'm working on an EA and directly putting the calculation inside the EA code. So i don't have any 'prev_calculated' variable :/

It means that I'm loosing every data on new candle, except if I create arrays outside of the OnTick and OnInit functions, is that what you suggest to do ? 

Yes. You should maintain the data somehow.

That will not be very nice, but to work properly, you should at least keep the value from the last call, as this is crucial to performance.

If you look at the loop in lwma (), you can see, if you pass an init_val other than NULL, the loop will only run one calculation. And it will not call the avg() function.

These are only called for the first value, as you can calculate all subsequent values from that initial value.

This is also where your approach is loosing it's time.

I'll write up some more specific code for you to show you what I mean and how to do what you want. Not today. It's late here already.
 
Dominik Christian Egert #:
Yes. You should maintain the data somehow.

That will not be very nice, but to work properly, you should at least keep the value from the last call, as this is crucial to performance.

If you look at the loop in lwma (), you can see, if you pass an init_val other than NULL, the loop will only run one calculation. And it will not call the avg() function.

These are only called for the first value, as you can calculate all subsequent values from that initial value.

This is also where your approach is loosing it's time.

I'll write up some more specific code for you to show you what I mean and how to do what you want. Not today. It's late here already.

Ok, thank you very much for your quick answer already ! Your help is really appreciated !

During this time I will try to understand the rest of the code you provided. 

I'm looking forward to reading you. 

 
winGou- #:

Not sure to understand what should be in "prev_calculated" value as i'm working directly on an EA with all my arrays as series.

I know this is used mostly in indicators but how should I define it ?   

EDIT : Sorry I realised my first post wasn't clear enough, i'm not writing an indicator, i'm working on an EA and directly putting the calculation inside the EA code. So i don't have any 'prev_calculated' variable :/

Why are you reinventing the wheel ?

Use an indicator and get the values in your EA. LWMA or indicator is not the problem, the original problem about slowness is bad code and/or bad algorithm. iMAOnArray() on mql5 is just an horror, for sure it's slow.

Use a good one.

 
Alain Verleyen #:

Why are you reinventing the wheel ?

Use an indicator and get the values in your EA. LWMA or indicator is not the problem, the original problem about slowness is bad code and/or bad algorithm. iMAOnArray() on mql5 is just an horror, for sure it's slow.

Use a good one.

I never learned how to code Indicator in mql5 or managing buffers, so it's not very clear how it works for me yet :/ 

 
winGou- #:

I never learned how to code Indicator in mql5 or managing buffers, so it's not very clear how it works for me yet :/ 

You don't need to code an indicator to use it. Pick one that exists and works well, and use it on your EA.

Of course we can also learn to code all yourself, just want to be sure we know you have this choice.

But if you are not experimented yet, I would say embedding all the code in the EA is not an easy solution., so my suggestion to search for a good one and use it (see iCustom).

 
Alain Verleyen #:

You don't need to code an indicator to use it. Pick one that exists and works well, and use it on your EA.

Of course we can also learn to code all yourself, just want to be sure we know you have this choice.

But if you are not experimented yet, I would say embedding all the code in the EA is not an easy solution., so my suggestion to search for a good one and use it (see iCustom).


That would require him to build a cascade of indicators.

Also a good solution. And probably a bit easier to handle, for sure.


 
Dominik Christian Egert #:

That would require him to build a cascade of indicators.

Also a good solution. And probably a bit easier to handle, for sure.


I will try to understand the OnCalculate function, and try to code an indicator, probably using the code you provided me (and thanks again !). If you have any piece of material or anything that could help me learning quicker I'll take it :)

Regarding Alain's suggestion, I don't know how to get what I want with existing indicators given the fact that I'm trying to calcule LWMA of LWMA of LWMA of LWMA [...] of LWMA (of price).  

 
winGou- #:

I will try to understand the OnCalculate function, and try to code an indicator, probably using the code you provided me (and thanks again !). If you have any piece of material or anything that could help me learning quicker I'll take it :)

Regarding Alain's suggestion, I don't know how to get what I want with existing indicators given the fact that I'm trying to calcule LWMA of LWMA of LWMA of LWMA [...] of LWMA (of price).  


What you do is you open/create an iMA with the parameters you need.It will give you a handle.

Then you open another iMA and you give it the handle of the first iMA. And so on.

At least in theory, this should work.



 
Dominik Christian Egert #:

What you do is you open/create an iMA with the parameters you need.It will give you a handle.

Then you open another iMA and you give it the handle of the first iMA. And so on.

At least in theory, this should work.

Do you mean directly in the EA ? using IMa of iMa of iMa ? I didn't know that the handle will pass the result of the previous calculation. If confirmed I will give it a try !

EDIT : Just to be sure, I will need to create the handle outside of the OnTick function to hold the previous calculated result ? and manually shifting it on every candle ? How ?  
 
winGou- #:

Do you mean directly in the EA ? using IMa of iMa of iMa ? I didn't know that the handle will pass the result of the previous calculation. If confirmed I will give it a try !

EDIT : Just to be sure, I will need to create the handle outside of the OnTick function to hold the previous calculated result ? and manually shifting it on every candle ? How ?  
I suppose you need to do some more research...

Handle creation goes into OnInit()

The last handle of your iMA-chain is the one you use in OnTick with CopyBuffer..

Beyond that, it's easier for me to post code as I have offered yesterday.


Reason: