Places exactly one order per symbol when momentum threshold is met. Holds the position all day regardless of P&L. Eliminates order spam and complex re-entry logic.
Long positions: Pay the ASK price
Short positions: Pay the BID price
Extended hours enabled for pre-market trading.
EOD liquidation at 3:55 PM ET uses market orders to guarantee all positions close before market close.
// Bullish Entry (BUY)
IF (mid_price - reference_price) / reference_price >= +1%
AND symbol NOT in enteredSymbols
THEN place LIMIT BUY @ ASK price
mark symbol as entered
// Bearish Entry (SHORT)
IF (mid_price - reference_price) / reference_price <= -1%
AND symbol NOT in enteredSymbols
THEN place LIMIT SELL @ BID price
mark symbol as entered
The flow uses separate API keys for trading and data operations:
Used for orders, positions, account
Endpoints:
โข POST /v2/orders
โข GET /v2/positions
โข GET /v2/orders?status=all
Used for real-time quotes and bars
Endpoints:
โข GET /v2/stocks/bars/latest
โข GET /v2/stocks/quotes/latest?feed=sip
// Run this in a function node once, or add to Node-RED settings.js
// Trading API keys
global.set('apiKeyLive', 'YOUR_TRADING_KEY');
global.set('apiSecretLive', 'YOUR_TRADING_SECRET');
// Data API keys (SIP feed)
global.set('apiDataKeyLive', 'YOUR_DATA_KEY');
global.set('apiDataSecretLive', 'YOUR_DATA_SECRET');
return msg;
The flow includes several inject nodes for manual operation:
| Button | Action | When to Use |
|---|---|---|
| Start Tracker | Initialize config, reset entries, load reference prices, begin polling | Manual start or testing |
| Stop Tracker | Halt polling, disable trading | Emergency stop or end of day |
| Show Status | Display current state, entered symbols, and pending symbols | Monitor progress during the day |
| Reset Entries | Clear enteredSymbols object (allows re-entry) | New trading day or testing |
| Liquidate All | Close all open positions immediately with market orders | Emergency exit or manual EOD |
| Fetch Earnings | Load earnings calendar from NASDAQ API | Manual refresh or testing |
| Fetch Orders | Retrieve all orders placed today from Alpaca | Audit and verification |
The flow uses Node-RED's flow context for state:
| Variable | Type | Description |
|---|---|---|
config |
Object | Trading parameters, API keys, timing settings |
running |
Boolean | Polling loop active flag |
tradingEnabled |
Boolean | Allow new entries flag |
symbols |
Array | Stock symbols to track (from earnings calendar) |
referenceData |
Object | Reference prices from 4 AM for momentum calculation |
enteredSymbols |
Object | Tracks which symbols have been entered |
{
"AAPL": {
action: "buy",
qty: 50,
limitPrice: 200.50,
time: "2026-01-30T08:15:00.000Z"
},
"TSLA": {
action: "short",
qty: 25,
limitPrice: 400.25,
time: "2026-01-30T09:30:00.000Z"
}
}
const config = {
// Trading thresholds
MOMENTUM_THRESHOLD: 0.01, // 1% move triggers entry
POSITION_SIZE: 10000, // $ per position
POLL_INTERVAL: 60000, // 60 seconds
// EOD timing (Eastern Time)
EOD_LIQUIDATE_HOUR: 15, // 3:55 PM
EOD_LIQUIDATE_MINUTE: 55,
EOD_SHUTDOWN_HOUR: 16, // 4:00 PM
EOD_SHUTDOWN_MINUTE: 0,
// API Configuration
ALPACA_BASE_URL: "https://paper-api.alpaca.markets",
ALPACA_DATA_URL: "https://data.alpaca.markets"
};
{
symbol: "AAPL",
qty: "50",
side: "buy",
type: "limit",
limit_price: "200.50",
time_in_force: "day",
extended_hours: true
}
{
symbol: "AAPL",
qty: "50",
side: "sell",
type: "market",
time_in_force: "day"
}
| Endpoint | Method | API Keys | Purpose |
|---|---|---|---|
/v2/stocks/bars/latest |
GET | Data | Reference prices (4 AM baseline) |
/v2/stocks/quotes/latest?feed=sip |
GET | Data | Real-time quotes (bid/ask) |
/v2/orders |
POST | Trading | Place entry/exit orders |
/v2/positions |
GET | Trading | Fetch positions for liquidation |
/v2/orders?status=all |
GET | Trading | View today's order history |
npm install -g node-red)http://localhost:1880)earnings_simple_tracker_flows.jsonCreate a function node and run once:
global.set('apiKeyLive', 'YOUR_TRADING_KEY');
global.set('apiSecretLive', 'YOUR_TRADING_SECRET');
global.set('apiDataKeyLive', 'YOUR_DATA_KEY');
global.set('apiDataSecretLive', 'YOUR_DATA_SECRET');
return msg;
How this simplified flow differs from more complex approaches:
| Feature | Complex Flow | Simple Tracker โ |
|---|---|---|
| Entry Orders | Limit (0.1% from market) | Limit (pay ask/bid) |
| Extended Hours | Post-liquidation only | All entries |
| Entries Per Symbol | Multiple (on each signal) | ONE per day |
| Exit Strategy | Profit target + Stop loss | EOD liquidation only |
| Complexity | High (many conditions) | Low (simple rules) |
| Order Volume | High (repeated orders) | Low (one per symbol) |
Deploy earnings-based strategies with MachineTrader's low-code platform.
Start Free Trial