Guides / Rule playground
Rule playground · about 8 min
Offsets and windows
Look back with offsets and ref(), choose between windows that include today and ones that do not, and know what happens when history runs out.
The request
Eleven rules on XLE:
{ "model": "ora-fin1", "state": { "symbol": "XLE" }, "questions": { "today_up": { "type": "yes_no", "ask": "C > C[-1]" }, "yesterday_up": { "type": "yes_no", "ask": "C[-1] > C[-2]" }, "ref_form": { "type": "yes_no", "ask": "C > ref(C, -1)" }, "week_ago": { "type": "yes_no", "ask": "C > C[-5]" }, "future": { "type": "yes_no", "ask": "C > C[1]" }, "breakout": { "type": "yes_no", "ask": "C > highest(C, 20)" }, "never": { "type": "yes_no", "ask": "C > max(C, 20)" }, "at_max": { "type": "yes_no", "ask": "C >= max(C, 20)" }, "ma_rising": { "type": "yes_no", "ask": "sma(C, 20) > ref(sma(C, 20), -5)" }, "year": { "type": "yes_no", "ask": "C > sma(C, 250)" }, "too_long": { "type": "yes_no", "ask": "C > sma(C, 2000)" } } }Open this in the PlaygroundThe answers
Session of 2026-10-30:
Question Rule Belief today_upC > C[-1]0.9085 yesterday_upC[-1] > C[-2]0.6708 ref_formC > ref(C, -1)0.9085 week_agoC > C[-5]0.7066 futureC > C[1]0.5 breakoutC > highest(C, 20)0.6462 neverC > max(C, 20)0.5 at_maxC >= max(C, 20)0.5 ma_risingsma(C, 20) > ref(sma(C, 20), -5)0.9425 yearC > sma(C, 250)0.9463 too_longC > sma(C, 2000)0.5 Offsets count back
C[-1]is yesterday's close,C[-5]a week ago.C > ref(C, -1)is the same rule asC > C[-1](both 0.9085). A positive offset looks at a bar that does not exist yet, soC > C[1]is 0.5.ref() for everything else
Offsets work on price letters only. To look back at an indicator, use
ref():sma(C, 20) > ref(sma(C, 20), -5)asks whether the 20-day average is higher than a week ago (0.9425).Including or excluding today
highest(C, 20)is the 20 sessions before today;max(C, 20)includes today. SoC > highest(C, 20)(0.6462) is the breakout, andC > max(C, 20)(0.5) can never be more than a tie.When history runs out
About 1,500 sessions are loaded. A window longer than that is not known, so
C > sma(C, 2000)is 0.5, whileC > sma(C, 250)is 0.9463.
Information, not investment advice. Every number on this page is a real response for the session shown; answers change with each session.