Count bars since price reach a certain point

Back to topics list  | 1 2 3 To post a new topic, please log in or register
avatar
105
simoncs 2015.05.25 08:07 #
 
WHRoeder:
Answer the question "What is the third datatype for the function"

ok see what you mean now :)

that was just the last iteration though. I previously had

LowRetracePrice=iLow(NULL,ExtZZSwingTF,iBarShift(Symbol(),ExtZZSwingTF,SwingDate[0]));

 but i just don't know how i get this to change on each new bar, hence i was trying to relate it back to "i"

 

avatar
13009
WHRoeder 2015.05.25 17:22 #
 
Just use "i"
avatar
105
simoncs 2015.05.28 08:19 #
 
WHRoeder:
Just use "i"

ok thanks, so i amended the code as below, but it still doesn't work. the LowRetracePrice or HighRetracePrice does not seem to change with each new bar, so there is still something wrong with the structure of the loop isn't there?

i have printed out the value of i, and it is counting the bars from the SwingDate[0] as i would expect, so i just need the high or the low of the "i" bar each time it changes. so i can't see what is wrong with LowRetracePrice or HighRetracePrice. 

 

void RetraceCheck()
{
RefreshRates();
static datetime Time0;





for(i=iBarShift(Symbol(),ExtZZSwingTF,SwingDate[0]);i>0; i--) // hoping to start at the SwingDate[0] and count forward
{

if(Time0==iTime(Symbol(),ExtZZSwingTF,0))
      return(0);           // if this is not a new bar then let's not do anything

   Time0=iTime(Symbol(),ExtZZSwingTF,0);
 

  
   if(Trend==UpTrend) //will be buy trades
   RefreshRates();
      
      LowRetracePrice=iLow(NULL,ExtZZSwingTF,i);
   
    
    
      if(ExtEntryLine==50)
         {
         if (LowRetracePrice < Fib50Line)
                
              {
              RetraceBarCount++;
              }
         }

etc.

 

avatar
105
simoncs 2015.06.03 03:34 #
 
simoncs:

ok thanks, so i amended the code as below, but it still doesn't work. the LowRetracePrice or HighRetracePrice does not seem to change with each new bar, so there is still something wrong with the structure of the loop isn't there?

i have printed out the value of i, and it is counting the bars from the SwingDate[0] as i would expect, so i just need the high or the low of the "i" bar each time it changes. so i can't see what is wrong with LowRetracePrice or HighRetracePrice. 

 

 

i have also tried counting the other way...

for(i=0;i<=iBarShift(Symbol(),ExtZZSwingTF,SwingDate[0]); i++)

 

but that doesn't work either.

I am not sure why i don't get the correct high or low for each bar in the loop. All it outputs is the high and low from the SwingDate[0]. I thought this might be because i have declared the HighRetracePrice/LowRetarcaePrice as global variables, but even if i declare them in the function it doesn't seem to work.

 

please help, this issue has already taken me over a month... 

avatar
Moderator
3423
GumRai 2015.06.03 04:27 #
 

if(Time0==iTime(Symbol(),ExtZZSwingTF,0))
      return(0);           // if this is not a new bar then let's not do anything

   Time0=iTime(Symbol(),ExtZZSwingTF,0);
 

Take this out of the for loop and place it before the loop.

As it stands, the first pass of the loop the if condition may not be true, but it will always be true on the second pass and so exiting the function 

avatar
105
simoncs 2015.06.05 01:47 #
 
GumRai:

Take this out of the for loop and place it before the loop.

As it stands, the first pass of the loop the if condition may not be true, but it will always be true on the second pass and so exiting the function 

thanks - i tried that - all that happens is that the retracebarcount then does not increase per bar, on each new bar it might increase by 5 for example. (no pattern that i can see)

also then depending on how i set the loop i either get no values for the LowRetracePrice, or the HighRetracePrice. Or sometimes it outputs the open price of the current bar for both values.

 

void RetraceCheck()
{
RefreshRates();
static datetime Time0;
int i;

if(Time0==iTime(Symbol(),ExtZZSwingTF,0))
      return(0);           // if this is not a new bar then let's not do anything
Time0=iTime(Symbol(),ExtZZSwingTF,0); 
   for(i=iBarShift(Symbol(),ExtZZSwingTF,SwingDate[0]);i<=0; i--) {       if(Trend==UpTrend) //will be buy trades    RefreshRates();       //LowRetracePrice=iLow(NULL,ExtZZSwingTF,iBarShift(Symbol(),ExtZZSwingTF,i));       LowRetracePrice=iLow(NULL,ExtZZSwingTF,i);        //if (i>iBarShift(Symbol(),ExtZZSwingTF,SwingDate[0])) continue;     //  {       if(ExtEntryLine==50)          {          if (LowRetracePrice < Fib50Line)                                {               RetraceBarCount++;               }          }

 

in my mind the loop should be (start; end; count direction) - in simple terms.

so the start being SwingDate[0], the end being the current bar - so for the start i= SwingDate[0]; for the end I tried "i=0",which returns no values, so I tried "i<=0" which doesn't work either. The only way to generate any value seems to be"i>=0" which makes no sense as i don't want to count past the current bar.

Either way I still don't get the LowRetracePrice or HighRetracePrice, to reflect each bars properties. 

avatar
105
simoncs 2015.06.16 23:54 #
 
how can i get the high or low for each bar past the SwingDate?
avatar
13009
WHRoeder 2015.06.17 02:44 #
 
iHighest and iLowest
avatar
105
simoncs 2015.06.18 00:44 #
 
WHRoeder:
iHighest and iLowest

i mean within the context of the previous posts.

i need to compare the high or low for each bar past the swingdate and count them. I thought that i was on the right track with putting this in a loop, but despite all your help so far,I still can't get this to work. So am wondering if there is a better way to do it.  I can't understand why the loop doesn't count the bars correctly,despite trying just about every iteration i can think of.

Back to topics list   | 1 2 3  

To add comments, please log in or register