Overview
Action blocks execute trades when your conditions are met. These blocks place buy/sell orders, attach take-profit and stop-loss exits to a held position, and control order execution. Every profitable strategy needs well-designed action blocks to enter and exit positions at the right time.
Action: Buy
REQUIREDPlaces a buy order for a specified symbol and quantity. Supports market, limit, stop, and stop-limit orders, and four sizing methods (shares, cash, percent of cash, or percent of equity).
Order Types
- Market: Execute immediately at current price
- Limit: Execute only at your
Limit Priceor better (or setLimit % Below Market Price) - Stop: Trigger a market buy once price reaches your
Stop Price(orStop % Above Market) - Stop Limit: Trigger at the stop, then place a limit order at
Limit Price/Limit % Below Market Price - Time in Force: DAY, GTC (Good til canceled), IOC, FOK
Sizing Methods (Size Mode)
- Shares: Buy a fixed number of shares
- Cash $: Buy a fixed dollar amount worth of shares
- % Cash: Size off your available buying-power cash
- % Equity: Size off your total account equity (cash plus open positions)
Fill Handling
- Wait for fill (
waitFill, on by default): pause downstream blocks until this order fills or closes
Re-entry
- Allow repeated entries (default): the buy may re-fire each time its condition is met
- Wait until linked sell closes: set automatically when a Sell block is linked to this buy, so it will not re-buy while that lot is still open
📋 Example 1: Fixed Share Quantity
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
buy1 = Action: Buy (symbol=AAPL, 100 shares, Market, when=lt1)
📋 Example 2: Dollar-Based Sizing
source1 = Data: Ticker (TSLA, 1m)
sma1 = Indicator: SMA (source1, length=50)
gt1 = Condition: A > B (source1_price, sma1)
buy1 = Action: Buy (symbol=TSLA, cash=$10,000, Market, when=gt1)
📋 Example 3: Portfolio Percentage
source1 = Data: Ticker (SPY, 1m)
sma1 = Indicator: SMA (source1, length=50)
gt1 = Condition: A > B (source1_price, sma1)
buy1 = Action: Buy (symbol=SPY, % Equity=20, Market, when=gt1)
Action: Sell
REQUIREDPlaces a sell order to exit existing positions. Supports full position exit or partial exit, market/limit/stop/stop-limit orders, and profit/loss management.
Exit Methods
- Sell All: Close entire position
- Sell Shares (
Quantity): Close a specific number of shares - Sell all from buy (
sellAllFrom): Close everything tied to a specific buy block id, orALL - Sell lot mode (
sellLotMode, default Latest active lot): when linked viasellAllFrom, chooses which held lot this sell closes
Order Types
- Market / Limit / Stop / Stop Limit
- Limit % Above Last Buy (
limitPctAboveBuy): set the limit relative to the linked buy fill - Stop Loss % from Buy (
stopPctBelowBuy): set the stop relative to the linked buy fill, instead of an absoluteStop Price - Time in Force: DAY, GTC, IOC, FOK
- Wait for fill (
waitFill, on by default): pause downstream blocks until the order fills or closes
📋 Example 1: Profit Target Exit
pos_qty1 = State: Position Qty (AAPL)
gt1 = Condition: A > B (pos_qty1, 0)
sell1 = Action: Sell (symbol=AAPL, sell_all_from=buy1, Limit, Limit % Above Last Buy=10, when=gt1)
📋 Example 2: Stop Price Exit
pos_qty1 = State: Position Qty (TSLA)
gt1 = Condition: A > B (pos_qty1, 0)
sell1 = Action: Sell (symbol=TSLA, Stop, stop_price=180, when=gt1)
📋 Example 3: Partial Exit (Scale Out)
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
gt1 = Condition: A > B (rsi1, 70)
gt2 = Condition: A > B (rsi1, 80)
sell1 = Action: Sell (symbol=AAPL, qty=50, when=gt1)
sell2 = Action: Sell (sell_all_from=buy1, when=gt2)
Action: Take Profit + Stop Loss
EXITAttaches both a take-profit and a stop-loss to a position you already hold. The two exits are placed together as an OCO (One-Cancels-Other) pair on the linked lot: whichever price is reached first exits the lot, and the other order is automatically cancelled. Unlike a plain Limit Sell — which only closes the position on the upside and leaves losses uncapped — this block brackets the lot on both sides in a single step.
What it does
- Links to an existing held lot via
Sell all from buy(sellAllFrom) - Sets a take-profit above the linked buy
- Sets a stop-loss below the linked buy
- First one to hit exits the lot; the other is cancelled
When to use
- Bracketing a position with defined risk/reward
- Set-and-forget exits after an entry fills
- When you can't monitor positions live
- Capping downside while keeping an upside target
Take Profit
- Take Profit Price (
takeProfitPrice): an absolute price target, or - Take Profit % (
takeProfitPct): a percentage above the linked buy fill
Stop Loss
- Stop Loss Price (
stopLossPrice): an absolute stop price, or - Stop Loss % (
stopLossPct): a percentage below the linked buy fill
Symbol & Trigger
- Symbol / Symbol source (
sourceId): type a ticker or link a Data: Ticker block - When (cond id) (
when): optional condition id that gates when the exit is armed
Execution
- Time in Force (
timeInForce): DAY or GTC only - Wait for fill (
waitFill, on by default): pause downstream blocks until the exit fills or closes
📋 Example: 2:1 Bracketed Exit
source1 = Data: Ticker (SPY, 1m)
gt1 = Condition: A > B (source1_price, 450)
buy1 = Action: Buy (symbol=SPY, cash=$10,000, Market, when=gt1)
pos_qty1 = State: Position Qty (SPY)
gt2 = Condition: A > B (pos_qty1, 0)
oco1 = Action: Take Profit + Stop Loss (sell_all_from=buy1,
take_profit_pct=10, stop_loss_pct=5, TIF=GTC, when=gt2)
Quick Reference
| Action | Purpose | Best For | Risk Management |
|---|---|---|---|
| Buy | Enter long position | All entry strategies | Position sizing control |
| Sell | Exit long position | All exit strategies | Profit targets, stop losses |
| Take Profit + Stop Loss | Attach TP + SL to a held lot | Defined risk/reward | Automatic OCO exits (both sides) |
Common Order Strategies
1. Simple Entry/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)
Basic strategy with indicator-based entry and exit thresholds
2. Take Profit + Stop Loss (Set and Forget)
source1 = Data: Ticker (SPY, 1m)
gt1 = Condition: A > B (source1_price, 450)
buy1 = Action: Buy (symbol=SPY, cash=$10,000, Market, when=gt1)
pos_qty1 = State: Position Qty (SPY)
gt2 = Condition: A > B (pos_qty1, 0)
oco1 = Action: Take Profit + Stop Loss (sell_all_from=buy1,
take_profit_pct=8, stop_loss_pct=4, TIF=GTC, when=gt2)
Enter, then bracket the lot with automatic risk management
3. Scale Out (Partial Profits)
source1 = Data: Ticker (AAPL, 1m)
rsi1 = Indicator: RSI (source1, length=14)
lt1 = Condition: A < B (rsi1, 30)
gt1 = Condition: A > B (rsi1, 70)
gt2 = Condition: A > B (rsi1, 80)
gt3 = Condition: A > B (rsi1, 85)
buy1 = Action: Buy (symbol=AAPL, 200 shares, when=lt1)
sell1 = Action: Sell (symbol=AAPL, qty=50, when=gt1)
sell2 = Action: Sell (symbol=AAPL, qty=50, when=gt2)
sell3 = Action: Sell (sell_all_from=buy1, when=gt3)
Lock in profits incrementally while letting rest run
Best Practices
✅ Do:
- Always define both profit target AND stop loss before entry
- Use portfolio percentage for position sizing (scales with account)
- Aim for risk/reward ratio of at least 1:2 (risk $1 to make $2)
- Use the Take Profit + Stop Loss block to bracket a held lot with automatic exits
- Use stop / stop-limit orders to cap downside on entries and exits
- Test order execution in paper trading before going live
❌ Don't:
- Enter trades without stop loss - NEVER risk entire account
- Use fixed share quantities (doesn't scale with account growth)
- Move stop losses further away when losing (hope is not a strategy)
- Overtrade - quality over quantity
- Ignore slippage on market orders (especially low liquidity stocks)
- Risk more than 1-2% of portfolio per trade
📊 Position Sizing & Risk Management
Professional risk management guidelines:
| Risk Level | Risk per Trade | Max Positions | Strategy Type |
|---|---|---|---|
| Conservative | 0.5% - 1% | 3-5 | Long-term, low frequency |
| Moderate | 1% - 2% | 5-10 | Swing trading, medium frequency |
| Aggressive | 2% - 3% | 10-15 | Day trading, high frequency |
💡 Rule: Never risk more than 2% of your account on a single trade. Professional traders typically risk 0.5-1% per trade.