Advanced Trade Signals
TradeStaq supports advanced signal types for sophisticated trading strategies including trailing stops, DCA, grid trading, and more.
Signal Types Overview
| Signal Type | Description | Use Case |
|---|---|---|
buy / sell | Basic entry signals | Simple entries |
buy_trail / sell_trail | Entry with trailing stop | Trend following |
buy_risk / sell_risk | Risk-based position sizing | Fixed risk per trade |
buy_atr / sell_atr | ATR-based SL/TP | Volatility-adjusted stops |
dca_buy / dca_sell | Dollar-cost averaging | Averaging into positions |
scale_out | Progressive profit taking | Lock profits gradually |
grid | Grid trading | Range-bound markets |
flip | Reverse position | Trend reversal |
hedge | Open hedge position | Risk reduction |
breakeven | Move SL to breakeven | Protect capital |
lock_profits | Progressive stop trailing | Secure profits |
close_trail | Trailing exit | Ride trends |
close_steps | Stepped exit plan | Systematic exits |
close_after | Time-based exit | Timed trades |
alert | Send notification | Monitoring |
Basic Signals
Long Entry
// Simple market buy
td.trade.buy({
amountPercent: 50,
stopLoss: td.market.price * 0.98,
takeProfit: td.market.price * 1.06,
reason: 'RSI oversold'
});
// Short entry
td.trade.sell({
amountPercent: 50,
stopLoss: td.market.price * 1.02,
takeProfit: td.market.price * 0.94,
reason: 'RSI overbought'
});
Trailing Stop Entries
Enter with an automatic trailing stop that follows price.
Usage
// Trailing with percentage and activation
td.trade.buyTrail({
amountPercent: 50,
trailPercent: 2, // Trail 2% behind price
activationPercent: 0.5, // Start trailing after 0.5% profit
stopLoss: 49000, // Initial SL before trail activates
reason: 'Trend entry with trail'
});
// OR with fixed trail amount
td.trade.buyTrail({
amount: 0.1,
trailAmount: 500, // Trail $500 behind price
reason: 'Fixed trail entry'
});
// Short with trailing
td.trade.sellTrail({
amountPercent: 50,
trailPercent: 2,
activationPercent: 1.0, // Start after 1% profit
reason: 'Short with trail'
});
Parameters
| Parameter | Type | Description |
|---|---|---|
trailPercent | number | Trail distance as percentage (e.g., 2 = 2%) |
trailAmount | number | Trail distance in price units (alternative to percent) |
activationPercent | number | Profit % required to start trailing (default: 0) |
activationPrice | number | Price at which trailing activates (alternative to percent) |
stopLoss | number | Initial stop loss before trail activates |
How Trailing Works
Long Position with 2% Trail:
─────────────────────────────────────────────────
Entry: $50,000 → Initial Stop: $49,000 (2% below)
Price rises to $52,000 → Stop moves to $50,960
Price rises to $55,000 → Stop moves to $53,900
Price falls to $53,900 → STOP TRIGGERED
─────────────────────────────────────────────────
Profit locked: $3,900 (7.8%)
Risk-Based Position Sizing
Automatically calculate position size based on account risk.
Usage
td.trade.buyRisk({
riskPercent: 2, // Risk 2% of account
stopLoss: td.market.price * 0.97, // 3% stop loss
takeProfit: td.market.price * 1.06,
reason: 'Risk-based entry'
});
How It Works
// The system calculates:
const accountBalance = td.account.balance; // $10,000
const riskAmount = accountBalance * (riskPercent / 100); // $200
const stopLossDistance = entryPrice - stopLossPrice; // $1,500
const positionSize = riskAmount / stopLossDistance; // 0.133 BTC
// If stopped out, you lose exactly $200 (2% of account)
Parameters
| Parameter | Type | Description |
|---|---|---|
riskPercent | number | Percentage of account to risk (e.g., 2 = 2%) |
stopLoss | number | Required - determines position size |
ATR-Based Stops
Set stop loss and take profit based on ATR (Average True Range).
Usage
td.trade.buyAtr({
amountPercent: 50,
atrMultiplierSL: 1.5, // Stop Loss = Entry - (1.5 × ATR)
atrMultiplierTP: 3.0, // Take Profit = Entry + (3.0 × ATR)
reason: 'ATR-based entry'
});
How It Works
// Example with ATR = $1,000, Entry = $50,000
const atr = td.indicators.atr; // $1,000
const stopLoss = entryPrice - (atr * 1.5); // $48,500
const takeProfit = entryPrice + (atr * 3.0); // $53,000
// Risk:Reward = 1:2 (risking 1.5 ATR for 3.0 ATR)
Parameters
| Parameter | Type | Description |
|---|---|---|
atrMultiplierSL | number | ATR multiplier for stop loss |
atrMultiplierTP | number | ATR multiplier for take profit |
Benefits
- Stops adapt to market volatility
- Wider stops in volatile markets
- Tighter stops in calm markets
- Consistent risk/reward ratio
Dollar-Cost Averaging (DCA)
Enter positions gradually at multiple price levels.
Usage
td.trade.dcaBuy({
totalAmount: 1.0, // Total 1 BTC across all levels
dcaLevels: 4, // Split into 4 entries
dcaSpread: 2, // 2% between each level
stopLoss: td.market.price * 0.92, // Overall stop
reason: 'DCA entry'
});
How It Works
Entry Price: $50,000
DCA Levels: 4
DCA Spread: 2%
Total Amount: 1 BTC
─────────────────────────────────────────────────
Level 1: 0.25 BTC @ $50,000 (entry)
Level 2: 0.25 BTC @ $49,000 (-2%)
Level 3: 0.25 BTC @ $48,020 (-4%)
Level 4: 0.25 BTC @ $47,060 (-6%)
─────────────────────────────────────────────────
Average Entry: $48,520 (if all levels fill)
Parameters
| Parameter | Type | Description |
|---|---|---|
dcaLevels | number | Number of entry levels |
dcaSpread | number | Percentage between levels |
totalAmount | number | Total position size across all levels |
Scale Out (Progressive Profit Taking)
Take profits at multiple levels as price moves in your favor.
Usage
// After entry, set up scale out
td.trade.scaleOut({
scaleOutTargets: [
{ percent: 25, price: td.position.entryPrice * 1.02 }, // 25% at +2%
{ percent: 25, price: td.position.entryPrice * 1.04 }, // 25% at +4%
{ percent: 25, price: td.position.entryPrice * 1.06 }, // 25% at +6%
{ percent: 25, price: td.position.entryPrice * 1.10 }, // 25% at +10%
],
reason: 'Progressive profit taking'
});
Parameters
| Parameter | Type | Description |
|---|---|---|
scaleOutTargets | array | Array of { percent, price } targets |
Scale Out Target
| Property | Type | Description |
|---|---|---|
percent | number | Percentage of position to close (0-100) |
price | number | Target price for this exit |
Grid Trading
Place buy and sell orders at regular intervals within a range.
Usage
td.trade.grid({
gridLevels: 10, // 10 grid levels
gridSpacing: 1, // 1% between levels
gridUpperBound: td.market.price * 1.05,
gridLowerBound: td.market.price * 0.95,
amountPercent: 50, // Use 50% of balance for grid
reason: 'Grid trading range'
});
How It Works
Upper Bound: $52,500
Lower Bound: $47,500
Levels: 10
─────────────────────────────────────────────────
$52,500 ─── Sell order
$52,000 ─── Sell order
$51,500 ─── Sell order
$51,000 ─── Sell order
$50,500 ─── Sell order
─────────── Current Price: $50,000
$49,500 ─── Buy order
$49,000 ─── Buy order
$48,500 ─── Buy order
$48,000 ─── Buy order
$47,500 ─── Buy order
─────────────────────────────────────────────────
Parameters
| Parameter | Type | Description |
|---|---|---|
gridLevels | number | Number of grid levels |
gridSpacing | number | Percentage between levels |
gridUpperBound | number | Upper price limit |
gridLowerBound | number | Lower price limit |
Position Management Signals
Flip (Reverse Position)
Close current position and open opposite.
td.trade.flip({
reason: 'Trend reversal detected'
});
// Equivalent to:
// 1. Close current long
// 2. Open new short of same size
Hedge Position
Open a hedge without closing main position.
td.trade.hedge({
hedgePercent: 50, // Hedge 50% of position
reason: 'Hedging before news'
});
Move to Breakeven
Move stop loss to entry price after reaching profit target.
td.trade.breakeven({
breakevenTrigger: 2, // Trigger at 2% profit
breakevenOffset: 0.1, // Small offset (0.1% profit locked)
reason: 'Moving to breakeven'
});
Lock Profits (Progressive Stop)
Move stop loss up as profits increase.
td.trade.lockProfits({
lockProfitStep: 1, // Move SL every 1% profit
lockProfitTrail: 0.5, // Trail 0.5% behind current price
reason: 'Locking profits'
});
Advanced Exit Signals
Trailing Exit
Set up a trailing stop that follows price and closes the position when triggered.
td.trade.closeTrail({
trailPercent: 1.5,
activationPercent: 1.0, // Activate after 1% profit
reason: 'Trailing exit'
});
Check Before Setting (Recommended)
To avoid duplicate signals when closeTrail is called on every spin, check if trailing is already configured:
// Only set up trailing if not already configured
if (td.position.hasPosition && !td.position.trailingStop?.enabled) {
td.trade.closeTrail({
trailPercent: 1.5,
activationPercent: 1.0,
reason: 'Setting up trailing stop'
});
}
// Or check if trail has already activated
if (td.position.trailingStop?.activated) {
td.utils.log('Trail active at', td.position.trailingStop.highWaterMark);
}
Trailing Stop Properties
Access trailing stop state via td.position.trailingStop:
| Property | Type | Description |
|---|---|---|
enabled | boolean | Whether trailing stop is configured |
activated | boolean | Whether trail has activated (reached profit threshold) |
percent | number | Trail distance in % |
amount | number | Trail distance in absolute value |
activationPercent | number | Profit % required to activate |
highWaterMark | number | Current high water mark price |
currentTrailPrice | number | Current calculated trail stop price |
Stepped Exit
td.trade.closeSteps({
closeSteps: [
{ percent: 33, afterCandles: 24 }, // 33% after 24 candles
{ percent: 33, afterSeconds: 3600 }, // 33% after 1 hour
{ percent: 34, atPrice: targetPrice }, // Rest at target
],
reason: 'Systematic exit plan'
});
Time-Based Exit
td.trade.closeAfter({
closeAfterCandles: 48, // Close after 48 candles
reason: 'Time limit reached'
});
// OR
td.trade.closeAfter({
closeAfterSeconds: 86400, // Close after 24 hours
reason: 'Daily trade limit'
});
Alerts
Send notifications without executing trades.
td.trade.alert({
level: 'warning', // info, warning, error
title: 'RSI Oversold',
message: `RSI reached ${td.indicators.rsi.toFixed(2)}`,
data: {
rsi: td.indicators.rsi,
price: td.market.price,
timestamp: Date.now()
}
});
Alert Levels
| Level | Use Case |
|---|---|
info | General information |
warning | Potential action needed |
error | Critical condition |
trade_entry | Position opened |
trade_exit | Position closed |
Complete Strategy Example
// Multi-feature strategy combining advanced signals
// Helper to get custom indicator value safely
function getIndicator(key) {
const val = td.indicators.custom[key];
if (val === undefined || val === null) return 0;
if (Array.isArray(val)) return val[val.length - 1];
return val;
}
const rsi = td.indicators.rsi;
const atr = td.indicators.atr;
const ema9 = getIndicator('ema_9');
const ema21 = getIndicator('ema_21');
// Track previous values for crossover detection
const prevEma9 = td.state.get('prevEma9', ema9);
const prevEma21 = td.state.get('prevEma21', ema21);
td.state.set('prevEma9', ema9);
td.state.set('prevEma21', ema21);
// Entry logic with risk-based sizing
if (!td.position.hasPosition) {
// Bullish setup - EMA crossover
const emaCrossUp = prevEma9 <= prevEma21 && ema9 > ema21;
if (rsi < 35 && emaCrossUp) {
// Risk-based entry with ATR stops
const stopLoss = td.market.price - (atr * 1.5);
const takeProfit = td.market.price + (atr * 3);
td.trade.buyRisk({
riskPercent: 2,
stopLoss,
takeProfit,
reason: 'RSI oversold + EMA crossover'
});
// Set up scale out after entry
td.state.set('pendingScaleOut', true);
}
}
// Position management
if (td.position.hasPosition && td.position.side === 'long') {
const profitPercent = td.position.pnlPercent;
// Setup scale out targets
if (td.state.get('pendingScaleOut') && profitPercent > 0) {
td.trade.scaleOut({
scaleOutTargets: [
{ percent: 33, price: td.position.entryPrice * 1.03 },
{ percent: 33, price: td.position.entryPrice * 1.05 },
{ percent: 34, price: td.position.entryPrice * 1.08 },
]
});
td.state.set('pendingScaleOut', false);
}
// Move to breakeven at 2% profit
if (profitPercent >= 2 && !td.state.get('atBreakeven')) {
td.trade.breakeven({
breakevenOffset: 0.1,
reason: 'Securing entry'
});
td.state.set('atBreakeven', true);
}
// Lock profits progressively after 3%
if (profitPercent >= 3) {
td.trade.lockProfits({
lockProfitStep: 1,
lockProfitTrail: 0.5
});
}
// Alert on significant profit
if (profitPercent >= 5 && !td.state.get('alertedProfit')) {
td.trade.alert({
level: 'info',
title: 'Position +5%',
message: `Position is up ${profitPercent.toFixed(2)}%`
});
td.state.set('alertedProfit', true);
}
}
Next Steps
- Multi-Timeframe Analysis - Use multiple timeframes
- Risk Management - Bot-level risk controls
- Testing Strategies - Validate before live
- Order Types - Detailed order reference