Overview
Action blocks execute trades when your conditions are met. These blocks place buy/sell orders, manage risk with bracket orders and trailing stops, 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 orders, limit orders, and various sizing methods (shares, dollars, or portfolio percentage).
Order Types
- Market Order: Execute immediately at current price
- Limit Order: Execute only at specified price or better
- Time in Force: Day, GTC (Good til canceled), IOC, FOK
Sizing Methods
- Shares: Buy fixed number of shares
- Dollars: Buy dollar amount worth of shares
- Portfolio %: Buy percentage of portfolio value
📋 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 or limit orders, and profit/loss management.
Exit Methods
- Sell All: Close entire position
- Sell Shares: Close specific number of shares
- Sell from Buy ID: Close everything tied to a specific buy block
When to Use
- Profit targets reached
- Stop loss triggered
- Exit signal generated
- Time-based exits
📋 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: Bracket Order
ADVANCEDAll-in-one order type that simultaneously places an entry order with both a profit target (take-profit) and stop loss. Perfect for set-and-forget risk management.
What it does
- Places entry order (buy)
- Automatically sets take-profit order
- Automatically sets stop-loss order
- Both exit orders placed as OCO (One-Cancels-Other)
When to use
- Automated risk management
- Set-and-forget strategies
- Defined risk/reward ratio
- When you can't monitor positions
📋 Example: 2:1 Risk/Reward Bracket
source1 = Data: Ticker (SPY, 1m)
gt1 = Condition: A > B (source1_price, 450)
bracket1 = Action: Bracket Order (symbol=SPY, qty=100, entry=Market,
take_profit_pct=10, stop_loss_pct=5, when=gt1)
Action: Trailing Stop
DYNAMICDynamic stop loss that follows price as it moves in your favor, locking in profits while giving the trade room to run. The stop "trails" behind the price by a set percentage or dollar amount.
How it works
- Stop loss follows price up (for long positions)
- Buy-side trailing stops can cover short positions (if your account allows shorts)
- Never moves against the favorable trend
- Triggers when price reverses by trail amount
- Can be percentage or dollar-based
When to use
- Trending markets (let winners run)
- Momentum strategies
- Uncertain profit targets
- Capturing large moves
📋 Example: Momentum Trailing Stop
source1 = Data: Ticker (TSLA, 1m)
ema1 = Indicator: EMA (source1, length=20)
rsi1 = Indicator: RSI (source1, length=14)
gt1 = Condition: A > B (source1_price, ema1)
gt2 = Condition: A > B (rsi1, 60)
and1 = Condition: AND (gt1, gt2)
buy1 = Action: Buy (symbol=TSLA, cash=$10,000, Market, when=and1)
pos_qty1 = State: Position Qty (TSLA)
gt3 = Condition: A > B (pos_qty1, 0)
trail1 = Action: Trailing Stop (symbol=TSLA, sell_all_from=buy1, trail%=5, when=gt3)
📋 Example: Short Cover Trailing Stop
source1 = Data: Ticker (TSLA, 1m)
pos_qty1 = State: Position Qty (TSLA)
lt1 = Condition: A < B (pos_qty1, 0)
trail_buy1 = Action: Trailing Stop (symbol=TSLA, trail%=3, when=lt1)
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 |
| Bracket Order | Entry + TP + SL in one | Defined risk/reward | Automatic exits (both sides) |
| Trailing Stop (Buy/Sell) | Dynamic stop loss | Trending markets | Lock in profits as price moves favorably |
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. Bracket Order (Set and Forget)
source1 = Data: Ticker (SPY, 1m)
gt1 = Condition: A > B (source1_price, 450)
bracket1 = Action: Bracket Order (symbol=SPY, qty=100, entry=Market,
take_profit_pct=8, stop_loss_pct=4, when=gt1)
Fire-and-forget with automatic risk management
3. Trailing Stop (Trend Following)
source1 = Data: Ticker (SPY, 1m)
rsi1 = Indicator: RSI (source1, length=14)
gt1 = Condition: A > B (rsi1, 60)
buy1 = Action: Buy (cash=$10,000, when=gt1)
pos_qty1 = State: Position Qty (SPY)
gt2 = Condition: A > B (pos_qty1, 0)
trail1 = Action: Trailing Stop (symbol=SPY, sell_all_from=buy1, trail%=5, when=gt2)
Best for strong trends - maximizes profit potential
4. 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 bracket orders for automated risk management
- Use trailing stops in strong trending markets
- 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.