🧩Sample Trading Strategies
This section presents reference strategies demonstrating common trading patterns. These examples are intended as learning tools and starting points rather than ready-to-use trading systems.
The strategies below illustrate common trading patterns. Each example highlights a specific idea or combination of indicators and is intended to help you understand how strategies are structured and composed.
Spot grid trading bot
DCA
Spot Martingale
Rebalancing BOT
TWAP
Infinity Grid
looping
trend follow
memejob LUA strategies, intro:
All strategies:
Are stateless
Script runs once per bar
Use only supported syntax and indicators
Express intent exclusively via
returnvalues
Return values:
Each example below focuses on a specific concept such as trend detection, momentum confirmation, mean reversion, or volume filtering. You are encouraged to adapt parameters, combine patterns, and test variations rather than using examples verbatim.
Each example focuses on a specific concept such as trend detection, momentum confirmation, mean reversion, or volume filtering. You are encouraged to adapt parameters, combine patterns, and test variations rather than using examples verbatim.
1. Price Above SMA (Trend Baseline)
Logic: Buy above SMA, exit below.
Visual intuition:
2. EMA Fast / Slow Crossover
Visual:
3. Triple EMA Trend Filter
Visual:
4. Pullback to EMA (DCA-Friendly)
5. EMA Momentum DCA
Visual:
6. Price Momentum (Bar-to-Bar)
7. SMA Slope Confirmation
8. EMA Trend + Price Confirmation
9. HLC3 Trend Strategy
10. WMA Trend Strategy
11. EMA Compression Breakout
12. Price vs Previous High
13. SMA Mean Reversion (Simple)
14. EMA Acceleration
15. Dual-Timeframe Proxy (Fast vs Slow SMA)
Note: As new indicators and primitives are added, this page will expand with advanced variants of each pattern.
1. The "Golden Cross" (Classic Trend Following)
The "Hello World" of trading bots.
It captures massive moves by entering when short-term momentum overtakes long-term trends.
Logic:
Buy when the fast MA (e.g., 50) crosses above the slow MA (e.g., 200).
Sell when it crosses below.
1'. Golden Cross / Death Cross
Following long-term trend following using two SMAs
2. The "MACD Zero-Cross" Momentum
A faster strategy than moving averages, good for swing trading volatile assets.
Logic: If the MACD line crosses above 0, momentum has shifted from bearish to bullish.
3. Volume Breakout (Fakeout Detector)
Crypto prices often jump without volume ("fake pumps"). This strategy only buys if the price increases and volume spikes significantly.
Logic: Buy if Price > EMA(20) AND Current Volume > 2x Previous Volume.
4. The "AI Sentiment Analyst"
This uses your complete() function. This is your "killer feature" that standard algo-tools don't have. You feed technical data to the LLM and let it decide.
Lua
Recommendation
9. Canonical Safe Strategy Template
spot martingale
-- ============================================================================ -- STRATEGY 1: Golden Cross / Death Cross -- Classic long-term trend following using two SMAs -- ============================================================================ function strategy_golden_cross() local sma_short = sma(50, "1d") -- 50-day SMA local sma_long = sma(200, "1d") -- 200-day SMA local prev_sma_short = sma(50, "1d", 1) -- Previous period local prev_sma_long = sma(200, "1d", 1)
end
-- ============================================================================ -- STRATEGY 2: EMA Crossover (Fast Trading) -- Quick trend changes using two EMAs -- ============================================================================ function strategy_ema_crossover() local ema_fast = ema(9, "15m") -- 9-period EMA on 15min local ema_slow = ema(21, "15m") -- 21-period EMA on 15min local prev_ema_fast = ema(9, "15m", 1) local prev_ema_slow = ema(21, "15m", 1)
end
-- ============================================================================ -- STRATEGY 3: MACD Zero Line Cross -- Trade when MACD crosses above/below zero -- ============================================================================ function strategy_macd_zero_cross() local macd_current = macd(12, 26, "1h") -- 1-hour MACD local macd_prev = macd(12, 26, "1h", 1)
end
-- ============================================================================ -- STRATEGY 4: Triple EMA Trend -- Uses three EMAs to confirm strong trends -- ============================================================================ function strategy_triple_ema() local ema_short = ema(8, "1h") local ema_mid = ema(21, "1h") local ema_long = ema(55, "1h")
end
-- ============================================================================ -- STRATEGY 5: Price Above/Below Moving Average -- Simple trend following with price position -- ============================================================================ function strategy_price_ma_position() local sma_20 = sma(20, "4h") -- 20-period SMA on 4-hour local prev_close = close[1]
end
-- ============================================================================ -- STRATEGY 6: MACD Histogram Divergence -- Detects momentum changes via MACD direction -- ============================================================================ function strategy_macd_momentum() local macd_curr = macd(12, 26, "30m") local macd_prev_1 = macd(12, 26, "30m", 1) local macd_prev_2 = macd(12, 26, "30m", 2)
end
-- ============================================================================ -- STRATEGY 7: WMA Trend Strength -- Uses WMA's emphasis on recent prices -- ============================================================================ function strategy_wma_trend() local wma_10 = wma(10, "1h", 10) local wma_30 = wma(30, "1h", 30) local prev_wma_10 = wma(10, "1h", 10, 1) local prev_wma_30 = wma(30, "1h", 30, 1)
end
-- ============================================================================ -- STRATEGY 8: Volume-Weighted Breakout -- Combines price action with volume confirmation -- ============================================================================ function strategy_volume_breakout() local sma_price = sma(20, "1h") local avg_volume = sma(20, "1h") -- SMA of volume
end
-- ============================================================================ -- STRATEGY 9: Multi-Timeframe EMA -- Confirms trend across multiple timeframes -- ============================================================================ function strategy_multi_timeframe() local ema_15m = ema(20, "15m") local ema_1h = ema(20, "1h") local ema_4h = ema(20, "4h")
end
-- ============================================================================ -- STRATEGY 10: Mean Reversion with Bollinger-style Logic -- Uses SMA distance to detect oversold/overbought -- ============================================================================ function strategy_mean_reversion() local sma_20 = sma(20, "1h") local price_distance = ((close - sma_20) / sma_20) * 100 -- % distance
end
-- ============================================================================ -- USAGE EXAMPLE -- ============================================================================ --[[ To use these strategies, call them in your main strategy logic:
]]
Last updated