Overview
Utility blocks provide essential control flow, debugging, data management, and advanced analytics features. These blocks help you control algorithm execution, debug strategies, export data, review performance, and manage timing constraints. They're the "supporting cast" that makes complex strategies possible.
Wait for Fill (Action checkbox)
EXECUTIONPauses algorithm execution until an order is filled (or times out). This is enabled directly on the Action block (no standalone Utility block).
What it does
- Waits for order to fill completely
- Blocks execution until filled or timeout
- Prevents race conditions
- Ensures order sequencing
When to use
- Before checking position state
- Sequential order execution
- Bracket orders (entry before exits)
- Multi-step trading logic
📋 Example: Sequential Order Execution
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
buy1 = Action: Buy (symbol=AAPL, 100 shares, Limit=225, when=lt1, wait_for_fill=on)
sell1 = Action: Sell (symbol=AAPL, sell_all_from=buy1, Limit, Limit % Above Last Buy=10)
sell2 = Action: Sell (symbol=AAPL, Stop, stop_price=215)
Utility: Loop Restart
CONTROL FLOWRestarts the current algorithm loop from the beginning. Use to re-evaluate conditions or reset logic after certain events.
📋 Example: Re-check After Exit
source1 = Data: Ticker (SPY, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
gt1 = Condition: A > B (rsi1, 70)
buy1 = Action: Buy (cash=$10,000, when=lt1)
sell1 = Action: Sell (sell_all_from=buy1, when=gt1, wait_for_fill=on)
loop_restart1 = Utility: Loop Restart
Utility: New Loop
CONTROL FLOWWaits for the next algorithm cycle/iteration before continuing. Use to delay execution or wait for new market data.
📋 Example: Wait for Market Confirmation
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
gt1 = Condition: A > B (rsi1, 70)
buy1 = Action: Buy (symbol=AAPL, 100 shares, when=lt1, wait_for_fill=on)
new_loop1 = Utility: New Loop
sell1 = Action: Sell (sell_all_from=buy1, when=gt1)
Utility: Log
DEBUGGINGPrints debug messages and variable values to the console. Essential for troubleshooting and understanding algorithm behavior.
What it does
- Prints messages to console
- Shows variable values in real-time
- Logs timestamps for events
- Helps debug logic issues
When to use
- Debugging strategy logic
- Tracking variable values
- Monitoring entry/exit signals
- Understanding execution flow
📋 Example: Debug Signal Generation
source1 = Data: Ticker (SPY, 1m)
sma1 = Indicator: SMA (source1, length=50)
sma2 = Indicator: SMA (source1, length=200)
rsi1 = Indicator: RSI (source1, length=14)
log1 = Utility: Log (msg="SMA 50:", expr=sma1)
log2 = Utility: Log (msg="SMA 200:", expr=sma2)
log3 = Utility: Log (msg="RSI:", expr=rsi1)
gt1 = Condition: A > B (sma1, sma2)
log4 = Utility: Log (msg="🟢 Golden Cross detected!", expr=gt1)
buy1 = Action: Buy (cash=$10,000, when=gt1)
log5 = Utility: Log (msg="✅ Buy order placed at", expr=source1_price)
Utility: File Output (CSV)
DATA EXPORTQueues rows for the Export CSV button in Algorithm. Each time this block runs, it snapshots the current bar timestamp, price, and the block values you select.
What it does
- Appends a row to the in-app CSV export buffer
- Automatically includes timestamp + current price
- Exports selected block values (indicators, conditions, state)
- Downloads via Export CSV after your run
When to use
- Indicator/value snapshots
- Position monitoring
- Backtest diagnostics
- External analysis (Excel, Python)
📋 Example: Signal Snapshot
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
pos_qty1 = State: Position Qty (AAPL)
File Output (CSV) columns:
rsi1, lt1, pos_qty1
Utility: Wait Market Open
TIMINGPauses algorithm execution until market opens. Essential for strategies that should only trade during regular market hours.
📋 Example: Market Hours Only
wait_market_open1 = Utility: Wait Market Open
source1 = Data: Ticker (SPY, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
buy1 = Action: Buy (cash=$10,000, when=lt1)
Quick Reference
| Utility | Purpose | Best For |
|---|---|---|
| Wait for Fill (Action checkbox) | Wait for order to complete | Sequential orders, bracket setups |
| Loop Restart | Restart algorithm loop | Re-evaluate conditions after events |
| New Loop | Wait for next cycle | Delay execution, wait for new data |
| Log | Debug output to console | Troubleshooting, monitoring |
| File Output (CSV) | Queue rows for Export CSV | Custom snapshots, external analysis |
| Wait Market Open | Wait until market opens | Regular hours strategies only |
Common Utility Patterns
1. Entry + Exit Orders with Wait for Fill
source1 = Data: Ticker (AAPL, 1m)
buy1 = Action: Buy (symbol=AAPL, 100 shares, Limit=225, wait_for_fill=on)
sell1 = Action: Sell (symbol=AAPL, sell_all_from=buy1, Limit, Limit % Above Last Buy=10)
sell2 = Action: Sell (symbol=AAPL, Stop, stop_price=215)
Ensure entry fills before setting exit orders
2. Debug Signal Generation
source1 = Data: Ticker (SPY, 1m)
rsi1 = Indicator: RSI (source1, length=14)
log1 = Utility: Log (msg="RSI:", expr=rsi1)
lt1 = Condition: A < B (rsi1, 30)
log2 = Utility: Log (msg="🟢 Buy signal: RSI oversold", expr=lt1)
buy1 = Action: Buy (cash=$10,000, when=lt1)
Track why signals do or don't trigger
3. Signal Snapshot Export
source1 = Data: Ticker (SPY, 1m)
rsi1 = Indicator: RSI (source1, length=14)
macd1 = Indicator: MACD Line (source1, 12/26/9)
lt1 = Condition: A < B (rsi1, 30)
File Output (CSV) columns:
rsi1, macd1, lt1
Filter rows where lt1 is true after Export CSV
Best Practices
✅ Do:
- Enable Wait for Fill on actions before reading position state after orders
- Use Log extensively during development for debugging
- Use File Output (CSV) to capture key values, then Export CSV
- Use Wait Market Open if you only want regular hours trading
❌ Don't:
- Read position state immediately after order (enable Wait for Fill first)
- Leave excessive Log statements in production code
- Expect File Output to save files automatically (use Export CSV)
- Use Loop Restart excessively (can cause infinite loops)