standart deviation code crash

Back to topics list To post a new topic, please log in or register
avatar
4
shipsss 2015.03.08 10:12
 

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

 

 

 

 

avatar
Moderator
3206
angevoyageur 2015.03.08 11:28 #
 
Endless loop.
avatar
13008
WHRoeder 2015.03.08 14:46 #
 
  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


avatar
4
shipsss 2015.03.09 15:12 #
 

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"

avatar
13008
WHRoeder 2015.03.09 17:38 #
 
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

avatar
4
shipsss 2015.03.10 12:08 #
 
thanks ;)
avatar
13008
WHRoeder 2015.03.10 13:58 #
 
What part of "edit your post" was unclear?
avatar
4
shipsss 2015.03.10 16:40 #
 
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.
Back to topics list  

To add comments, please log in or register