Download MetaTrader 5
To add comments, please log in or register
Have you discovered something really important? Write an article and receive 200 USD!
benda
14
benda 2015.03.08 09: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);

Alain Verleyen
Moderator
28626
Alain Verleyen 2015.03.08 10:28  
Endless loop.
whroeder1
13627
whroeder1 2015.03.08 13: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

benda
14
benda 2015.03.09 14: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"

whroeder1
13627
whroeder1 2015.03.09 16: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
benda
14
benda 2015.03.10 11:08  
thanks ;)
whroeder1
13627
whroeder1 2015.03.10 12:58  
What part of "edit your post" was unclear?
benda
14
benda 2015.03.10 15: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.
/
To add comments, please log in or register