♥ 0 |
Since conditional order entry based on a study cannot have recursion used within it, is there a way of getting around this using one or more of (a) additional variables, (b) the GetValue() function, and/or (c) the Fold (looping) feature, or other thinkscript features to access historical data? So in short, given a simple example: <pre>def x = x[1] + 1;</pre> Can the value of x[1] be accessed/recreated in a way that avoids recursion so that it can be applied to x and be valid for a conditional order use? I have managed (I think) to do a workaround with a boolean variable (values are based on Forex pips, hence the 0.0003 and this was purely for testing purposes): <pre> declare lower; def test; if close > open + 0.0003 { </pre> But it seems to get more complicated when actually trying to utilize a previous calculated value (such as the x = x[1] + 1), yet it seems like somehow a GetValue() might work in some way to retrieve needed info. Have you come across any workarounds to get needed data without recursion?
Marked as spam
|
Please log in to post questions.
In the case of the Boolean condition example, I would want the value kept at the last condition met. So recursively, the final ”else” would normally simply be test = test[1]. But since recursion is not allowed in a study used for a conditional order, I am looping backwards to a maximum number of times that is a good chunk of the whole chart (1440 using a 5min chart) looking for the first time Double.NEGATIVE_INFINITY was *not* set on the shadow variable (which ends the loop), but as I’m looping I am setting to the previous value (so when the loop ends, I actually end up with the last value that was set at 1 or 0). But my real question is how to obtain a recursive value non-recursively to use in a more complex way of actually assigning the value. So a more complex example, look at the code for the VariableMA in ThinkorSwim, where it not only uses the CompoundValue function, but within the setting of asd uses a complex mathematical call to set the current asd in relation to the previous asd via asd[1]. I hope that makes sense. In short, I’m looking for a ”round about” method of obtaining recursive information to set a variable based off its past value, without directly using recursion since it is not allowed for conditional orders.
I have not found a way to do so. Does not mean there is not some way to do it. But adding levels of obfuscation to try and trick the compiler that no recursion is taking place does not seem to be effective. It is able to detect the recursion anyway.
I suggest you consider moving to another platform with more robust support for placing orders that execute from code.
I’ve had the same problems. If you’re calling a built in function with the same parameters then you can use recursion on that. e.g. foo(x,y)[1]. I’m not sure what the limits are or what exactly it’s doing but I’ve used it in places that don’t allow recursion.
Fascinating technique Stephen. I’ll have to test this out a bit and if I find anything usable I’ll be sure to post a follow-up.