ThinkorSwim’s Thinkscript has a function, ‘WITHIN’: suppose one wanted to those occasions when 2 or more conditions are all fulfilled within the span of any 2 bars: one might have been fulfilled on the most current bar, one might have been fulfilled on the bar preceding it. WITHIN allow one to do this in ThinkScript. Is there a way to achieve this same effect within Optuma’s Scripting language?
Hi,
We don’t have a single function that does this for multiple criteria. You can use the BarsTrue() function to give a Window for each criteria to pass, so they do not have to trigger at the same time.
Here’s an example using 2 days, with an MA Cross and a Gap Up.
//Set MA Cross V1 = MA(BARS=30, STYLE=Exponential) CrossesAbove MA(BARS=150, STYLE=Exponential) ; //Set Gap Up V2 = LOW() > HIGH(1) ; //Check if Either criteria passed in the last 2 days V3 = BARSTRUE(V1, LOOKBACK=2) >=1; V4 = BARSTRUE(V2, LOOKBACK=2) >=1; //Mark where both criteria have triggered in either of the last 2 days V3 and V4
Here is how it looks on the chart:
The MA Cross was 1 day before the gap up, but as both happened within the last 2 days, the script passed.