Coding help... Cyclical indicator - page 2

 

...

Krish

It is centered indicator, and as all centered indicators it recalculates, so if you try to pinpoint peaks and throughs you can not. Read this post and the post bellow it for some more explanation from lucmat : https://www.mql5.com/en/forum/181353

krish23456:
Hi Lucmat and Mladen,

Its a wonderful indicator. Liked it. But when I configured it at 1 m chart and 5 m chart, I am facing the cycle stability issue !

Is there a way I can precisely pin point the Cycle Peak and Cycle Trough ?

Thanks for any help.

Regards,

Krish
 
lucmat:
Mladen your second indicator is almost identical to the excel file.

The only difference is in the last few bars.

The problem of centered moving averages is that the last period to be calculated remains uncovered, just because the moving average is shifted backward by n-periods: for example, with 48-period centered moving average remain uncovered the last 24 periods.

In excel I remedy that problem, assuming that the missing values for calculating moving average ​​are exactly equal to the last one: if the last known value is 1.2550 we can assume that every missing and unknown values, required to draw the centered moving average, are equal at 1.2550 (it is a good compromise).

A similar proceeding should be adopted for calculating the other centered moving average of my cyclical indicator.

Thanks Mladen, I really appreciate your work!

Hi Mladen!

Do you think it's possible to adjust "SMA centered oscillator" with the trick I use in excel?

In other words, is it possible to assume that the missing values for calculating future moving average ​​are exactly equal to the last one?

Thanks

Lucmat

 

lucmat

The "version 2" does that

In this part of code :

double iCSma(int useValue, int halfLength, int i)

{

i = Bars-i-1;

//

//

//

//

//

double sum = work;

double sumw = 1;

//

//

//

//

//

for(int j=1; j<=halfLength; j++)

{

sum += work;

sumw += 1;

int k = MathMin(i+j,Bars-1);

sum += work[k];

sumw += 1;

}

return(sum/sumw);

}

line that is saying "int k = MathMin(i+j,Bars-1);" reuses the last (current) value over and over if it would go out of the scope of the available elements (so, in the future). Don't be puzzled with the inverted way it uses indexes : those are "raw" (C like array) and that is why it uses that way of accessing array elemnts

lucmat:
Hi Mladen!

Do you think it's possible to adjust "SMA centered oscillator" with the trick I use in excel?

In other words, is it possible to assume that the missing values for calculating future moving average ​​are exactly equal to the last one?

Thanks

Lucmat
 

Automatic refresh

mladen:
Don't know exactly why is there a difference (what does excel do in cases when there are no values - the missing future values) so try out this version : it calculates the last bars differently. It is a "guessing work" but might be closer to excel version

Hi mladen

I need a help, because I'm not able to solve this little problem.

As you can see from the attached pictures, the yellow line of the indicator, when the price is updated tick-by-tick, tends to segment: so I need to refresh the graph to rectify it.

Is it possible to update automatically this indicator every tick?

thanks

I really appreciate your work.

Lucmat

Files:
immagine1.jpg  87 kb
immagine.jpg  85 kb
 

Lucmat

You can try using the indicator attached (it should help to refresh all the data at the chart it is attached to)

But from the pictures you sent it seems that the indicator itself has a problem and it would be best to correct the indicator itself instead of using "middle solutions"

lucmat:
Hi mladen

I need a help, because I'm not able to solve this little problem.

As you can see from the attached pictures, the yellow line of the indicator, when the price is updated tick-by-tick, tends to segment: so I need to refresh the graph to rectify it.

Is it possible to update automatically this indicator every tick?

thanks

I really appreciate your work.

Lucmat
 

PS: also try out this version of the indicator (multiple centered sma needs more bars for "compensation" so this one adds those extra calculating bars to it)

 

Thanks Mladen

Your help is always great!!!

 

A big thanks to.......

lucmat:
Thanks Mladen

Your help is always great!!!

A big thanks to lucmat, Mladen, and Mr. Tools!!!! Mr Tools modified sma centered for me and me likes it alot... Felt it should be posted here as well.

All the best and Happy Holidays

TCT

 

SMA centered oscillator

SMA centered oscillator with coloring added om slope changes. Please note that SMA centered recalculates (as it is explained in this thread) and that color changes should not be used as a signal

 

Which indi is the same as the excel file?