Nonlagging Tools - page 46

 

I don't understand where is my error

pi = 3.1415926535

Cyclee=4

Length=9

Coeff = 3*pi

Phase = Length-1

Len = Length*Cyclee + Phase

for i=0 to Len-1

if i<=Phase-1 then

t = 1.0*i/(Phase-1)

else

t = 1.0 + (i-Phase+1)*(2.0*Cyclee-1.0)/(Cyclee*Length-1.0)

endif

beta = Cos(pi*t)

g = 1.0/(Coeff*t+1)

if t <= 0.5 then

g = 1

endif

alfa = g * beta

next

 
zilliq:
I don't understand where is my error

pi = 3.1415926535

Cyclee=4

Length=9

Coeff = 3*pi

Phase = Length-1

Len = Length*Cyclee + Phase

for i=0 to Len-1

if i<=Phase-1 then

t = 1.0*i/(Phase-1)

else

t = 1.0 + (i-Phase+1)*(2.0*Cyclee-1.0)/(Cyclee*Length-1.0)

endif

beta = Cos(pi*t)

g = 1.0/(Coeff*t+1)

if t <= 0.5 then

g = 1

endif

alfa = g * beta

next

zilliq

You must have an array of alfas

 

Thanks Mladen,

But what means an "array of alfas " ?

Something curious I don't see where I include the price

Thanks for your next answer

Zilliq

 
zilliq:
Thanks Mladen,

But what means an "array of alfas " ?

Something curious I don't see where I include the price

Thanks for your next answer

Zilliq

Zilliq

Take a look at this part of the code :

double sum = 0, sumw = 0;

for (k=0; k =0; k++) { sum += nlmalphas[k]*nlmprices[r-k]; sumw += nlmalphas[k]; }

if (sumw!=0)

return(sum/sumw);

else return(price);

That is where the prices are used (each with its own alhpa - every price in the len array of prices is applied it's own alpha as a weighting coefficient - that is why you are storing an array of different value alphas in an array - to be able to apply it to corresponding price)

 

Always so fast to answer

Ok I think I will understand, it will not be easy to code, but I will try

Thanks for all and have a nice day

Zilliq

 
zilliq:
Always so fast to answer

Ok I think I will understand, it will not be easy to code, but I will try

Thanks for all and have a nice day

Zilliq

Happy coding

 

Nonlag ma envelopes.

Updated version posted here : https://www.mql5.com/en/forum/general

Files:
 

This version of NonLag MA histo with alerts updated too to use new way of NonLag ma calculation : nonlag_ma_histo_mtfalerts-1_nmc.mq4

Originally it was posted here : https://www.mql5.com/en/forum/general

 

Hi Mladen,

It seems to be ok, but can you confirm that at the end of the code

1/ We need to add all alfa*price

and

2/ We divide this sum by the summation of all alfa ?

with i=0 to Len-1

Thanks a lot and have a nice day

Zilliq

mladen:
Happy coding
Files:
cac40_index.png  30 kb
 
zilliq:
Hi Mladen,

It seems to be ok, but can you confirm that at the end of the code

1/ We need to add all alfa*price

and

2/ We divide this sum by the summation of all alfa ?

with i=0 to Len-1

Thanks a lot and have a nice day

Zilliq

Yes, we divide that sum by the sum of the the alphas used (that way the oldest ones are having a logical values too - a kind of a scaling in of the indicator).

NonLag ma is simply a kind of a digital filter with coefficients for each price at a certain position (like SMA is a digital filter with all coefficients set to 1). If you remember that, than it is easier to know what are you doing

Reason: