Download MetaTrader 5

standart deviation code crash

To add comments, please log in or register
benda
14
benda  

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);

Alain Verleyen
Moderator
32810
Alain Verleyen  
Endless loop.
whroeder1
15709
whroeder1  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. 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];
  3. 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

benda
14
benda  

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"

whroeder1
15709
whroeder1  
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"

  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. for(int k=i; k < period; ++k)
       Print(  close[i+k] - mm[i] );
    n == k - i
benda
14
benda  
thanks ;)
whroeder1
15709
whroeder1  
What part of "edit your post" was unclear?
benda
14
benda  
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.
To add comments, please log in or register