static array ? - page 3

 

OK, I see something,

 while(i>=0)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
      if (val1 > 0) v1[i]=High[i];
      else          v1[i]=v1[i+1];

      val2=iFractals(NULL, 0, MODE_LOWER,i);
      if (val2 > 0) v2[i]=Low[i];
      else          v2[i]=v2[i+1];
      
      i--;    
     }

when does this loop finish ? when i is not >=0 i.e. -1

then the next code is . .

     for(val1=High[i]; v1[i] == 0 ;i++)  // or v1[i] == EMPTY_VALUE
      {
      Print (v1[i]);
      }

so the starting value for i is -1 . . hence your print out. v[-1] does actually = 0 so the loop ends.

 
When I print anything at all it always seems to equal 0

int i=Bars;         
   
   while(i>=0)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
      if (val1 > 0) v1[i]=High[i];
      else          v1[i]=v1[i+1];

      val2=iFractals(NULL, 0, MODE_LOWER,i);
      if (val2 > 0) v2[i]=Low[i];
      else          v2[i]=v2[i+1];
      
      i--;
       
     }
   
     Print (v1[i+10]);
      

I've changed i to something else and the while statements and even created a totally different code and all seem to = 0 I have no idea why.
But yet the indicator is working and the buffer seems to hold val1 within v1[i] properly, yet I cannot refer to anything in the array to print any of it.

everything always = 0

I'll keep reading some more.






 
for(v1[i]=High[i]; v1[i] !=0; i++)
      {
      Print (v1[i]);
      }
      

This prints nothing so still having -1 issue I guess
but if it starts a -1 then it ends as soon as it cycles one time because i++ takes it to zero again also.

I didn't know that this for statement would be effected by the while statement since this occurs outside of the while statement

 
int i=Bars;         
   
   while(i>=0)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
      if (val1 > 0)
      { 
      v1[i]=High[i];
      Print (v1[i]);
      }
      else          
      {
      v1[i]=v1[i+1];
      }

      val2=iFractals(NULL, 0, MODE_LOWER,i);
      if (val2 > 0) v2[i]=Low[i];
      else          v2[i]=v2[i+1];
      
      i--;
       
     }
Still 0 even when printing inside and before the loop

Seems even the basic of tasks evade me. To even read about Bars does not mention the subject of -1 in the documentation or the book at least in the Bars or Predefined variables sections where I thought it should be.
Quit discouraging. 1.5 weeks on this one simple subject and yet printing I thought would be the simplest of tasks which would help get me going in the right direction.

What a bummer ! LOL

I'll try some more tomorrow.
 

You didn't read my post very carefully . . .

Bars doesn't equal -1 at any time . . . or have anything to do with the -1 I mentioned.

You are using the i variable in two loops . . . unless you change it to some other value between the loops then it's starting value for the second loop will be it's finishing value from the first loop.

 
I'm confused


I got rid of my for loop altogether and thought that I would just print inside of the loop.
I've tried to reinitialise i=0 or i !=0 with no effect. or even a totally different variable altogether such as val3-iFractals.....a
And a=0 and not bars, then counted upwards from there also and printing still equals 0.

I don't understand why printing inside the loop won't work either as in the code posted above.

Thanks

 

Maybe you can answer a question for me . . .

Why do so many people with little coding experience seem to be terrified of adding Print statements ? Why do you want to make laife so hard for yourself . . maybe you are into S&M ?

You have one single Print statement . . . and it outputs 0 . . . you don't even know what the value of i was at the time, you don't know what the value of val1 was . . . do you know how iFractals works, I mean how it calculates what it does and what range of values it gives ?

 

I copied your code, added some print statements and ran it . . it is printing . . .

2011.09.18 14:42:24 Agent86 EURUSD,H1: v1[29]= 1.4727

 
RaptorUK:

Maybe you can answer a question for me . . .

Why do so many people with little coding experience seem to be terrified of adding Print statements ? Why do you want to make laife so hard for yourself . . maybe you are into S&M ?

You have one single Print statement . . . and it outputs 0 . . . you don't even know what the value of i was at the time, you don't know what the value of val1 was . . . do you know how iFractals works, I mean how it calculates what it does and what range of values it gives ?


I'm not terrified of adding Print statements, I've put them after each variable and do not understand what it's printing and why because it is not what I expected to see it print.
The single print statement you see is not the only one I put there. I would not have posted if I only tried one single print statement.
Only after 2-3 weeks of trying hundreds of things and reading and re-reading 100's of posts, and dictionary,book,documentation and more did I post to try and understand how this array works and how to print the elements and values

I worked on this 2-3 hours per day trying to understand it and I am not much closer, although I learned a lot of other things while trying to figure this out.

I completely re-wrote the code with a for loop instead of a while loop and limited the array 100 elements thinking this would simplify it for me a bit; and still could not print the values.


I just don't understand it.

I thought that iFractals gives the value of the high/low of the middle candle in a series of 5 candles provided that these 2) candles to the left, and 2)candles to the right are higher or lower then the middle candle. Marking or recording the middle candle high or low point.

I don't know the actual calculations of iFractals, but I didn't think this would matter since I was printing it if >0 which I thought was meaning true, and as it was being initialized with High[i] also .

I just do not understand it.


 
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[0]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[1]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[2]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[3]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[4]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[5]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[6]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[7]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[8]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[9]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[10]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[11]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[12]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[13]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[14]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[15]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[16]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[17]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[18]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[19]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[20]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[21]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[22]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[23]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[24]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[25]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[26]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[27]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[28]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[29]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[30]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[31]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[32]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[33]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[34]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[35]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[36]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[37]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[38]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[39]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[40]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[41]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[42]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[43]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[44]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[45]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[46]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[47]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[48]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[49]= 0
2011.09.20 20:41:50 2011.01.03 10:21 Agent86_5min EURUSD,M5: v1[50]= 0


From this code and yes there were other print statements all over except for val1 all other attempt to print v1[i] anywhere in the code prints = 0

//+------------------------------------------------------------------+
//|                                                  Agent86_5min.mq4 |
//|                                                    Unfinished POS |
//|                                    
//+------------------------------------------------------------------+
#property copyright "Unfinished POS by Agent86"


//---- input parameters
extern double    TakeProfit=20.0;
extern double    Lots=0.1;
extern double    StopLoss=15.0;
extern int MagicNumber=123486;

double v1[];
double v2[];
double v3[];
double val1;
double val2;
double val3;


//++++ These are adjusted for 5 digit brokers.

int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)

    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if (Digits == 5 || Digits == 3)
   {    // Adjust for five (5) digit brokers.
      pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
   } 
   else 
    {    
      pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; 
    }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
     
   
    
//---- 

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
   
    
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  
  
   double   faster = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1), //MODE_MAIN
            slower = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,1); //MODE_SIGNAL
            
  
          
   
    for(int i=Bars; i >= 0; i--)
     {
      val1=iFractals(NULL, 0, MODE_UPPER,i);
   
      // Print (val1, (" val1")); //will print some 0's
      if (val1 > 0)
         {        
         
          v1[i]=High[i];
 
         }
      else          
         {
         v1[i]=v1[i+1];
         }
        

      val2=iFractals(NULL, 0, MODE_LOWER,i);
     
      if (val2 > 0) 
         {
         v2[i]=Low[i];
         }
      else          v2[i]=v2[i+1];
     
      i--;
       
     }
   
   for(i=50; i>=0; i--)
      {
      Print ("v1[", i, "]= ", v1[i]);
      }

//----
            
                       
            

           

//---- 

 
                    
        

                
   return(0);
  }    

//+------------------------------------------------------------------+
Reason: