Indicator Question - page 6

 

for(i=0; val1==val3; i++)

This code leaves the possibility of an endless loop IMO.

 
I have to think about this some more, my eyes are blurry reading again.

I'll check in tomorrow
 
ubzen:

for(i=0; val1==val3; i++)

This code leaves the possibility of an endless loop IMO.

Really, seems like it should cycle until val1 is not val3

If val3 = 0 and val1 = 0 it should cycle until it gets a value

ii val3 = iFractal(momentarily) then val1 should cycle until val1=0 (and this is my problem right here)

it really is sort of an endless loop or lockup point, although I do get a print statement to return the iFractal value for val1 i'm not really sure where this is
I'll have to experiment some more with what others have posted for testing this, but I think your right

Perhaps it's not exactly as intended, but this is the concept I want to achieve to just increment to the previous fractal value

I'll keep working on it
 
diostar:

Honestly, this is my first time seeing this, for the loop termination condition. Its is tricky one...

It seems to partially work which is deceiving me because my print statement returns a value but I think the problem is that as soon as val3 actually is >0 then val1 will increment back to a value that is 0 and not really the previous fractal value

So it would appear that in theory it will only work once as long as val3 == 0 and then and only then will i++ incriment backwards until val1 is no longer == val3 which is what I want to do, however if val3 == a value then val1 will inciment back to a value of 0 where it's not longer == to val3 and then the loop will end.
This is not exactly what I wanted after all so back to the drawingboard again LOL

Thanks all

 
RaptorUK:

When you get an iFractal the value is > 0, yes ?

So, for example, if you want to know where the last UPPER and LOWER iFractals were just do something like this . . .

I think I see, now If I can work out how to produce the value of these previous locations

I think I can work this out, I hope. he he

Thanks
 

The 0 candle can't be a Fractal so val3 will always be 0, so why not use . . .

for(i=0; val1==0; i++)

. . . and get rid of val3.

I prefer a while in this case though, seemed to fit better to what you were trying to do . .

 
RaptorUK:

When you get an iFractal the value is > 0, yes ?

So, for example, if you want to know where the last UPPER and LOWER iFractals were just do something like this . . .

This seems to tell me where the last iFractal is, but not both previous iFractals

For example:

2011.10.07 09:05:36 sup_res EURUSD,M5: Last UPPER Fractal at 6 Last LOWER Fractal at 0

So it will show the current UPPER high fractal and print the location which is good
I can also change val1=i to val1=iFractal(NULL, 0, MODE_UPPER,i) and this will give me the value for the last iFractal
So I'm making some progress on understanding this but I still need to recode in order to go back to the previous iFractal

Once an iFractal forms then this while statement will continue to print the currently formed and latest iFractal which is cool
So lets say a new iFractal forms I want to reference this current fractal from the while statement which is really the previous 1 and not the current
So lets say iFractal LOWER_MODE forms now and I want to reference the previous iFractal UPPER_MODE and compare those values.

But from your advise I think I might be able to work this out these are all great ideas that are helping me a lot.
As I get more familiar with how code works I'm really starting to enjoy using what I know for my trading ideas.

Thanks
 
Agent86:
This seems to tell me where the last iFractal is, but not both previous iFractals

There is an error in my code . . .

while( val1==0 && val2==0)

should be . . .

while( val1==0 || val2==0)
 
RaptorUK:

The 0 candle can't be a Fractal so val3 will always be 0, so why not use . . .

. . . and get rid of val3.

I prefer a while in this case though, seemed to fit better to what you were trying to do . .

OK i changed val3 shift to 3, but I don't really like this either I'll make some changes, thanks
 
if(val1 > 0 && faster > slower)
      {
       Print (val1, " val1");
       for(i=0; val1 || val2==0; i++)
         {
         if(iFractals(NULL, 0, MODE_LOWER, i) > 0 && val2 == 0)
         val2 = iFractals(NULL, 0, MODE_LOWER, i);
         Print (" Last LOWER Fractal at ", val2);
        
         }

When adding a for(statement) within an if(statement) can you add additional if(statements) and refer to the values in the loop ?

And do those additional if(statements) have to occur inside the loop or can you be outside the loop and still refer to the looped values such as val2 ?

Please advise what is considered normal for loops inside of other code blocks ? And how to extract values of the loops ?

Thanks