๐ŸŽฏ Trading Strategy

Key Design Principles

1. ONE Entry Per Symbol

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.

2. Limit Orders for Entry

Long positions: Pay the ASK price
Short positions: Pay the BID price
Extended hours enabled for pre-market trading.

3. Market Orders for Exit

EOD liquidation at 3:55 PM ET uses market orders to guarantee all positions close before market close.

Entry Logic

// 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

โฐ Daily Schedule

3:30 AM ET
Fetch today's earnings calendar from NASDAQ API
4:00 AM ET
Start tracker ยท Initialize config ยท Load reference prices ยท Begin polling
4:00 AM โ€“ 3:55 PM
Monitor momentum every 60 seconds ยท Place limit entries when ยฑ1% threshold met
3:55 PM ET
EOD Liquidation ยท Close all positions with market orders
4:00 PM ET
Shutdown ยท Stop polling ยท Disable trading ยท Enter idle state

Flow Diagram

3:30 AM โ”€โ”€โ–บ Fetch Earnings Calendar โ”‚ 4:00 AM โ”€โ”€โ–บ Initialize Tracker โ”€โ”€โ–บ Load Reference Prices โ”€โ”€โ–บ Start Polling โ”‚ โ–ผ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ POLLING LOOP (Every 60 seconds) โ”‚ โ”‚ โ”‚ โ”‚ [Check Time] โ”€โ”€โ–บ Is it 3:55 PM? โ”€โ”€โ–บ YES โ”€โ”€โ–บ [EOD Liquidation] โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ NO โ”€โ”€โ–บ Is it 4:00 PM? โ”€โ”€โ–บ YES โ”€โ”€โ–บ [Shutdown] โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ NO โ”€โ”€โ–บ [Fetch Quotes] โ”€โ”€โ–บ [Check Momentum] โ”€โ”€โ–บ [Entry?] โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”‘ API Key Configuration

The flow uses separate API keys for trading and data operations:

๐Ÿ”ต Trading API Keys

Used for orders, positions, account

global.get("apiKeyLive")
global.get("apiSecretLive")

Endpoints:
โ€ข POST /v2/orders
โ€ข GET /v2/positions
โ€ข GET /v2/orders?status=all

๐ŸŸข Data API Keys (SIP Feed)

Used for real-time quotes and bars

global.get("apiDataKeyLive")
global.get("apiDataSecretLive")

Endpoints:
โ€ข GET /v2/stocks/bars/latest
โ€ข GET /v2/stocks/quotes/latest?feed=sip

Setup Code

// 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;
๐Ÿ’ก
Why separate keys?
Alpaca allows different subscription tiers for trading vs data. The SIP feed provides consolidated market data and may require a separate subscription.

๐ŸŽฎ Manual Controls

The flow includes several inject nodes for manual operation:

โ–ถ๏ธ Start Tracker
โน๏ธ Stop Tracker
๐Ÿ“Š Show Status
๐Ÿ”„ Reset Entries
๐Ÿ’ฐ Liquidate All
๐Ÿ“… Fetch Earnings
๐Ÿ“‹ Fetch Orders
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

๐Ÿ—๏ธ Flow Architecture

State Management

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

enteredSymbols Structure

{
    "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"
    }
}

Configuration Constants

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"
};

๐Ÿ“ Order Types

Entry Orders (Limit + Extended Hours)

{
  symbol: "AAPL",
  qty: "50",
  side: "buy",
  type: "limit",
  limit_price: "200.50",
  time_in_force: "day",
  extended_hours: true
}

Exit Orders (Market)

{
  symbol: "AAPL",
  qty: "50",
  side: "sell",
  type: "market",
  time_in_force: "day"
}

API Endpoints Used

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

๐Ÿš€ Installation & Setup

Prerequisites

  • Node-RED installed (npm install -g node-red)
  • Alpaca paper trading account
  • Separate trading and data API keys from Alpaca

Import Flow

  1. Open Node-RED (http://localhost:1880)
  2. Menu โ†’ Import โ†’ Select file
  3. Choose earnings_simple_tracker_flows.json
  4. Click "Deploy"

Configure API Keys

Create 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;

Daily Workflow

Automatic (Cron)
3:30 AM โ€” Earnings calendar fetched automatically
Automatic (Cron)
4:00 AM โ€” Tracker auto-starts, loads reference prices
Monitoring
4 AM โ€“ 4 PM โ€” Monitor via "Show Status" and debug sidebar
Automatic
3:55 PM โ€” All positions liquidated automatically
โš ๏ธ
Disclaimer
This is for educational and paper trading purposes only. Uses Alpaca's paper trading environment. No real money is at risk. Always test thoroughly before considering live trading.

๐Ÿ“Š Flow Comparison

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)

Ready to Trade Earnings Automatically?

Deploy earnings-based strategies with MachineTrader's low-code platform.

Start Free Trial