Endless loop.
-
Play videoPlease edit your post.
For large amounts of code, attach it.
Your lookback is period-1. First time, IndicatorCounted == 0 and you access k=[Bars-1 .. Bars-1+period-1] which do not exist. 4002 ERR_ARRAY_INDEX_OUT_OF_RANGE Array index is out of range int counted = IndicatorCounted(); int i = Bars - counted - 1; while(i>=0){ : for (int k =i ; k<=i+period-1;k++){ sum = sum + Close[k];
Handle your lookback properly. int counted = IndicatorCounted(); int lookback = period - 1; int i = Bars - MathMax(lookback, counted) - 1; while(i>=0){ : for (int k =i ; k<=i+lookback;k++){ sum = sum + Close[k];
- If you want to calculate the standard deviation, you don't need two loops and an extra array. std=sqrt[ (1/n E Xi^2) - (1/n E Xi)^2 ] Standard deviation - Wikipedia, the free encyclopedia
ok, I made some modification but...
before using the standart formula i want to Print delta like example: Close[10] - MA[10-0] Close[11] - MA[11-1] Close[12] - MA[12-2] Close[13] - MA[13-3] etc..... Close[i+period-1] - MA[i+period-1 - period-1]
my idea was :
FOR( k=i ; i+period -1; i++)
close[k] - mm[k-n]
I don't know how to code "n"
shipsss: i want to Print delta like example: Close[10] - MA[10-0] Close[11] - MA[11-1] Close[12] - MA[12-2] Close[13] - MA[13-3] etc..... Close[i+period-1] - MA[i+period-1 - period-1]
my idea was : FOR( k=i ; i+period -1; i++) close[k] - mm[k-n] I don't know how to code "n" |
|
thanks ;)
What part of "edit your post" was unclear?
last time i wanted to put code like your vidéo but after clicking on "insert" the code was not appear, there was just message and not the code. I think that maybe it was because of my internet browser.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
hello, big problems, Can anyone tell me where is the trouble with my code, since yesterday my plateforme going down. thanks ;) (ps : I tried to put code between code tags but It's not work, i tried to add a files too but I can see them ???? sorry)
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen
double mm[];
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,mm);
return(0);
}
int start()
{
int period = 20;
int counted = IndicatorCounted();
int i = Bars - counted - 1;
while(i>=0)
{
double sum = 0;
for (int k =i ; k<=i+period-1;k++)
{
sum = sum + Close[k];
}
mm[i] = sum / period;
for (int a = i ; a<=i+period-1;k++)
{
double square = 0;
square = square + MathPow(Close[a] - mm[-a],2);
double sigma = MathSqrt(square/period);
}
Print ("°°° SIGMA = °°°", sigma);
i--;
}
return(0);
}