Hi all - software developer here, but very new to the Optuma platform. In particular, I'm still trying to get my head around the capabilities of the scripting language...
I want to create a script to identify whether the most recent bar is a potential double top or bottom. To do that, I'm pretty sure I need to "walk back" through swings identified by e.g. the GANNSWING() tool, potentially back to the very first swing in the market's history, to see if there's an old top or bottom that lines up with the most recent bar - however, I can't find anything in the Optuma scripting language like a WHILE, REPEAT, FOR or FOREACH function that lets me walk back in time like that.
Logically, I want to be able to achieve something broadly like this:
- Work out how much tolerance I want to allow for a double top/bottom. As one option, identify the ticksize for the market (can't find a function to do this yet, but it's not hard to create one if none exists)
- Identify swings in the market (e.g. GS1=GANNSWINGS())
- Work out whether the most recent swing is up or down (simple enough). If the most recent swing move is up, we're looking for a potential double top; if the most recent swing move is down, we're looking for a potential double bottom. Assume we're looking for a double top from here on...
- Look back at the most recent swing top (i.e. OFFSET=2) and check whether the high on that day is within (say) 5 ticks of today's high. If so, we've found a potential double top, we return a True value and we're done. On the other hand, if that swing top is > 5 ticks above today's high, we return False as we can no longer have a potential double top
- If not, look back at the next most recent swing top (i.e. OFFSET=4) and check whether the high on that day is within 5 ticks of today's high. If so, we've found a double top, we return a True value and we're done; if that swing top is >5 ticks above today's high, we return False
- Continue walking back in time, adding 2 to the OFFSET value each time, until we either find a high within 5 ticks of today's high (return True), or we find a high >5 ticks above today's high (return False) or we run out of swings to look at (return False)
Similar logic for identifying potential double bottoms
Is there a function that I can use to iterate back through an unknown number of swings, as described above?
Thanks in advance