Hello,
I am trying to code from scratch the famous SMI, so far the code is working BUT it is not lean and when I try to introduce if IsFirstBar() then begin .... end in different places then it does not display anything. I am a bit bugged since I am using a similar structure in other indicators and it works well.
I think I am not too clear as when I need to insert calculation under if IsFirstBar() then begin .... end and when it does not require it, this SMI code is a good example as the calculation requires the use of functions (highest, lowest, EMA) in different places and it is not possible to regroup them under one main if IsFirstBar() then begin .... end section.
Thank you for any advice.
best regards,
Jean-Christophe.
Stochastic Momentum Index Programming
Stochastic Momentum Index Programming
You do not have the required permissions to view the files attached to this post.
- WHS Support
- Posts: 2443
- Joined: 14 Feb 2013 10:27
Re: Stochastic Momentum Index Programming
Hello Jean-Christophe,
thank you very much for sharing your code. Have you already noticed our new Express functions manual?:
http://www.whselfinvest.de/docs/manual- ... ons-en.pdf
It is also providing examples for every function and furthermore explaining the principles of the IsFirstBar // IsFinalBar functions.
It is very important to use these functions when you are calculating Moving Averages, RSI etc. If not the code will require an enormous amount of computation which will eventually slow down your entire system. If it's not possible for you to use FirstBar / Finalbar (for example if you are probably somewhere in the middle of the code) you can calculate the MA bar by bar, which is also much better than just using the MovingAverage() function without FirstBar / FinalBar. You can find examples how to do that also here in the forum. For example (MA bar by bar):
post1018.html?hilit=bar%20by%20bar#p1018
We hope you will keep on programming
If you have any further questions please don't hesitate to contact us.
Kind regards,
Timo
WH SelfInvest
thank you very much for sharing your code. Have you already noticed our new Express functions manual?:
http://www.whselfinvest.de/docs/manual- ... ons-en.pdf
It is also providing examples for every function and furthermore explaining the principles of the IsFirstBar // IsFinalBar functions.
It is very important to use these functions when you are calculating Moving Averages, RSI etc. If not the code will require an enormous amount of computation which will eventually slow down your entire system. If it's not possible for you to use FirstBar / Finalbar (for example if you are probably somewhere in the middle of the code) you can calculate the MA bar by bar, which is also much better than just using the MovingAverage() function without FirstBar / FinalBar. You can find examples how to do that also here in the forum. For example (MA bar by bar):
post1018.html?hilit=bar%20by%20bar#p1018
We hope you will keep on programming

Kind regards,
Timo
WH SelfInvest
Re: Stochastic Momentum Index Programming
Try this :
You do not need a Series for OverBoughtLine.
If IsBarCompleted() then
begin
Short_HH = highest(high,$Short_period);
Short_LL = lowest (low,$Short_period);
Short_A = (price - (0.5*(Short_HH + Short_LL)));
Short_B = Short_HH - Short_LL;
// calcul des séries intermédiaires Short SMI
ExpMovingAverage(Short_A,Short_EMA1,$Short_period1);
ExpMovingAverage(Short_EMA1,Short_EMA2,$Short_period2);
ExpMovingAverage(Short_B,Short_EMA3,$Short_period1);
ExpMovingAverage(Short_EMA3,Short_EMA4,$Short_period2);
If isNonZero(Short_EMA4) then
Short_SMI = 100*(Short_EMA2/(0.5*Short_EMA4));
else
Short_SMI = void;
end
else
Short_SMI=Short_SMI[1];
interpretation
begin
end
Plotline($OverBoughtLine,"black", 2);
Plotline($OverSoldLine,"black", 2);
You do not need a Series for OverBoughtLine.
If IsBarCompleted() then
begin
Short_HH = highest(high,$Short_period);
Short_LL = lowest (low,$Short_period);
Short_A = (price - (0.5*(Short_HH + Short_LL)));
Short_B = Short_HH - Short_LL;
// calcul des séries intermédiaires Short SMI
ExpMovingAverage(Short_A,Short_EMA1,$Short_period1);
ExpMovingAverage(Short_EMA1,Short_EMA2,$Short_period2);
ExpMovingAverage(Short_B,Short_EMA3,$Short_period1);
ExpMovingAverage(Short_EMA3,Short_EMA4,$Short_period2);
If isNonZero(Short_EMA4) then
Short_SMI = 100*(Short_EMA2/(0.5*Short_EMA4));
else
Short_SMI = void;
end
else
Short_SMI=Short_SMI[1];
interpretation
begin
end
Plotline($OverBoughtLine,"black", 2);
Plotline($OverSoldLine,"black", 2);
Re: Stochastic Momentum Index Programming
Hello,
Thank you for your support, please find below the Stochastic Momentum Index (on the weighted price).
I cannot get around the change of variable from series to numeric, it does not work so I leave the code as it is because it works.
best regards,
Jean-Christophe.
Thank you for your support, please find below the Stochastic Momentum Index (on the weighted price).
I cannot get around the change of variable from series to numeric, it does not work so I leave the code as it is because it works.
best regards,
Jean-Christophe.

You do not have the required permissions to view the files attached to this post.