DataSeries caching issue
Author: htg
Creation Date: 9/14/2010 10:23 AM
profile picture

htg

#1
Rather than waiting till some event occurs, say a TurnUp in a computed series, I want to place a conditional order that would execute during the current bar if the price series reaches a value such that the computed series will have turned.

One way to do it is to reverse engineer the computed series, which isn't always possible.

Another is to take the current bar's closing price, increment it by some value, say 0.01, and recompute the series, repeating until the computed series has reached some threshold value. Then I can place the conditional order using a BuyAtStop.

The problem I run into is that the value of the computed series doesn't seems to change. I'm guessing there's some sort of caching going on.

The following is a simple example which takes the rsi of a smoothed price series (using iirsmoother).

When I do a PrintDebug (with Flushing) I see that UC[bar] and DC[bar] change as they should but AUC and ADC are unchanged, which causes my code to loop unchecked.

CODE:
Please log in to see this code.


Thanks.
profile picture

Eugene

#2
I don't see a reason why should AUC and ADC change. Both the UC and DC as well as the period are defined outside the main loop and isn't being altered anyhow.

What I don't understand is how you get this code to even compile given that "nrs" is defined inside the do-while loop.
profile picture

htg

#3
Eugene:

The code is more complex. It compiles just fine. I cut and paste and have obviously made an error in doing so. But the problem is still there.

Either UC[bar] or DC[bar] is altered inside the do-while loop.

See:
CODE:
Please log in to see this code.


Thanks for the quick response.
profile picture

Eugene

#4
Ah, I see it now, thanks. The one-line syntax obfuscated me.

And yes, caching the data series is the reason. Wealth-Lab looks for those series in the Bars.Cache. Therefore try the following as a workaround:
CODE:
Please log in to see this code.

And later in the code, refer to UC_ and DC_.
profile picture

htg

#5
Eugene:

I'm not sure I follow.

Following are the changes to the code per your suggestion. I get the same behavior as before.

UC_ is now the original UC shifted left one bar with a new value for UC[bar]. Ditto for DC_.

CODE:
Please log in to see this code.

profile picture

Eugene

#6
Sorry for not being clear. What I mean is to replace these lines:
CODE:
Please log in to see this code.
With these:
CODE:
Please log in to see this code.
profile picture

htg

#7
Eugene:

Something is getting lost in the translation here. How about we start over?

Following is a complete code segment, which compiles and runs. It computes the RSI of a price series after it has been smoothed using IIRSmoother.

I am trying to determine what change in price will cause the value of the current RSI[bar] to increase by 10. I do so by incrementing the price of the last close by 0.01 iteratively, each time computing the new value of RSI.

As you can see in the code I followed your advice of using UC_ and DC_. But I still get into an infinite loop in the first instance in which the newly computed value of the RSI does not exceed the current RSI value by 10 (and it's < 90).

Thanks much for your assistance and I spologize for the confusion.

CODE:
Please log in to see this code.

profile picture

htg

#8
I'v determined that it's definitely a caching issue.

I replaced:
CODE:
Please log in to see this code.


in the middle of the do-while loop with:
CODE:
Please log in to see this code.


and everything works as it should.

Now the question is whether this can be done while retaining the cache.

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).