Welcome Guest, please sign in to participate in a discussion. | Search | Active Topics | |
Registered User Joined: 5/20/2006 Posts: 101
|
I have a code block that has a for next loop using i to index thru the data.. Is it possible to nest another for next loop with in it and use another variable say x to further ahead in the data? then revert back to where i was/is and continue? for instance:
For i As Integer = 1 To inputcount -1 if XYZ(i) = true then (looking for a pattern) found = true for x as integer = (i+3) to inputcount-1 < look ahead for price to be < the inputhigh(i).. look thru all the data for the first instance next end if <go back to i and look for another pattern> next
I know this won't compile.. I am thinking conceptually.. also would it be possible to actually talk to someone regarding coding something?
Thankyou
|
|
Administration
Joined: 10/7/2004 Posts: 378
|
Actually at first glance I think it will compile... but may or may not give you the results you want. First off, you will miss the first index in the array because you start "for i as integer = 1" instead of 0. Also, the second loop will not enter when i+3>inputcount-1, which if thats what you want is fine. Probably a safer way to do this would be like so:
if inputcount>=3 then ' make sure we have at least 3 values for i as integer = 2 to inputcount-1 'start the index at the 3rd position if XYZ(i-2) = true then 'look 2nd item back which will be 0 for first time through found = true for x as integer = i-2 to i 'loop through 3 indexes including current - first time through this would be 0,1,2 'look for whatever you want if ABC(x) then endif next endif next end if
if you want more than a 3 bar span then 3's = span and 2's = span -1
Ole
|
|
Registered User Joined: 5/20/2006 Posts: 101
|
Thanks..but I guess what I am asking is can you have a for next loop indexing with "i" find a date and value then with index"x" scroll forward from that point in time( from i) and look for that same value?
and then return to the "i" for next loop and continue:
for i = 0 to inputcount -1 look for some thing and if found ( call it buypoint)then for x = i to inputcount -1 look for the buypoint again(only one occurance) if found again then addtooutput buypoint(x) x=inputcount-1 end if next end if next
something like that?
|
|
Administration
Joined: 10/7/2004 Posts: 378
|
Sure...that should work.
Also, rather than set x=inputcount-1 to exit the inner loop you can just use "exit for"
Ole
|
|
Registered User Joined: 5/20/2006 Posts: 101
|
OK Thanks...put that where I had x=inputcount-1?
|
|
Administration
Joined: 9/18/2004 Posts: 3,522
|
Yes
Ken Gilb (Kuf) Chief Software Engineer - Worden Brothers Inc. Try/Catch - My RealCode Blog
|
|
Guest-1 |