Learning mql4. Intro and questions of a student. - page 3

 
WHRoeder wrote >>


Thanks again. Was trying out pretty much what you wrote when I was struggling to figure this out last night. Probably would have helped if I had the buffers numbered correctly. haha Problem solved though. Thanks again. On to the next one...

 
WHRoeder wrote >>
Don't use objects in indicators, an EA can't see them. Place the value in the buffer and use setIndexStyle(0,DRAW_ARROW)
Use the standard code for counting.


I've been playing around with the code for counting and using print to display the bar that is being checked each time. The only way I can get the "while" version to check only the last bar at each tick after all other bars have been checked is with the way I had it coded before.

int start()
  {
      int    i, counted_bars;
   
      counted_bars = IndicatorCounted();
      i=Bars-counted_bars-1;
      if(i>iHistory) i = iHistory;
   
      while(i>=0)
         {
       
          Print("Checking bar ",i);
          i--;
         }
         
     ErrorCheck();
   return(0);
  }

Thats the only way I can get it to print 10 through 0 and then check bar 0 at every tick. When I do the following method as was suggested:
int start()
  {
      int i; int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);   
      if(counted_bars>0) counted_bars--;
      i=Bars-counted_bars;
      
      if(i>iHistory) i = iHistory;
   
      while(i>=0)
         {
       
          Print("Checking bar ",i);
          i--;
         }
         
     ErrorCheck();
   return(0);
  }
With the above method, it prints 10 through 0 as it should but then goes through 2,1,0 with each tick? Any idea why or how I should have this written so it works properly? I've been trying to figure out the same thing with "for" that I am going to post next. Any suggestions are much appreciated. Thanks again.
 

And here are my results playing around with "for"

int start()
  {
      int    i, counted_bars;
   
      counted_bars = IndicatorCounted();
      i=Bars-counted_bars-1;
      if(i>iHistory) i = iHistory;
   
      for(i=iHistory; i>=0; i--)
         {
       
          Print("Checking bar ",i);
          
         }
         
     ErrorCheck();
   return(0);
  }
  
When I try my original version above, it counts 10 through 0 and repeats counting 10 through 0 at every tick? Why is it doing this and how do I code this so it only checks each bar once and then the last bar at each tick?

When I write it as suggested above:
int start()
  {
int i,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;






for(i=Bars-counted_bars-1; i>=0; i--)
         {
       
          Print("Checking bar ",i);
          
         }
         
     ErrorCheck();
   return(0);
  }
The above method counts all bars down to 0 and then checks bars 1 and 0 at each tick. Still not what I'm trying to do. Please help...
 

Ok. A little progress, i still dont think this is quite right though...

int start()
  {
int i,counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
//if(counted_bars>0) counted_bars--;
i=Bars-counted_bars-1;




if(i>iHistory) i=iHistory;

for(i=i; i>=0; i--)
         {
       
          Print("Checking bar ",i);
          
         }
         
     ErrorCheck();
   return(0);
  }
The above method does count form 10 to 0 and then checks bar 0 at each tick which is what Im tring to do. It still doesnt seem right to be setting i=Bars-counted_bars-1, then setting i=iHistory, and then setting i = i within the "for" line.
 

Anyone have any suggestions for the above 3 posts? Thanks

 

Trying to keep one organized thread here of the different questions and problems I come across as I'm learning but not having much luck getting answers and I don't want to fill up the forum by posting repeatedly or starting a new thread with each question. Would I have better luck by starting a new post each time? Still looking for any help or recommendations on the above posts as well as tips on how to best post my questions that will get a few replies. Thanks.

Reason: