Simple MACD and EMA

Simple MACD and EMA looks for a recovery through an EMA while MACD is also improving. It is designed to catch a move that first traded below both references, then regained the EMA as MACD approached or crossed its zero line.
The exit plan is built around recent structure, an EMA-following stop, and a risk/reward target. Protection is optional, while profitable EMA and MACD reversals can close the position independently.
warning
The target is always part of this strategy. SME_USE_PROTECTION controls whether the calculated stop may realize a loss; it does not disable the target or profitable technical exits.
Entry sequence
A long setup needs four pieces:
- Within
SME_SETUP_LOOKBACK, price was belowSME_EMA_LENGTHand MACD was below zero. - The current close crosses upward through the EMA.
- The close reaches the optional entry buffer above that EMA.
- MACD either crossed above zero within
SME_MACD_CROSS_LOOKBACK, or is still below zero but rising with an improving histogram.
The last condition lets the strategy enter while a bullish zero-line cross is visibly developing, rather than requiring it to be complete.
SME_ENTRY_BUFFER_PCT sets the clearance above the EMA in percentage mode. In pip mode, SME_ENTRY_BUFFER_PIPS is used instead. A larger buffer demands a more decisive recovery but enters farther from the EMA.
The strategy holds one position at a time and does not average down.
EMA and MACD controls
SME_EMA_LENGTH is both the entry reference and the basis for the following stop.
SME_MACD_FAST, SME_MACD_SLOW, and SME_MACD_SIGNAL define MACD. Keep the slow length above the fast length. Shorter values react earlier but also produce more zero-line changes in sideways markets.
The two lookbacks serve different purposes:
SME_SETUP_LOOKBACKremembers the earlier below-EMA, negative-MACD condition;SME_MACD_CROSS_LOOKBACKaccepts a recent completed MACD zero cross.
Widening both can combine events that belong to different market swings, so tune them separately.
Stop mode and trailing
The initial stop depends on SME_STOP_MODE:
conservativeplaces it one configured stop buffer below the EMA;aggressiveuses the recent low fromSME_SWING_LOOKBACKwhen that low is valid.
“Aggressive” here can create a structurally different and sometimes wider stop; always verify the actual distance on the pair.
After entry, the calculated stop follows the EMA at SME_TRAIL_BUFFER_PCT or SME_TRAIL_BUFFER_PIPS below it. It only ratchets upward. Enable SME_USE_PROTECTION to make this stop executable.
SME_MOVE_STOP_TO_BREAKEVEN raises the stored stop to entry after the target event has been processed.
Risk/reward target and partial amount
The target is entry price plus initial risk multiplied by SME_RISK_REWARD. It is raised when needed to cover fees and SME_MIN_NET_GAIN_PCT.
SME_PARTIAL_SELL_PCT controls how much is sold when that target is reached. At the default 100%, it is a full exit. With a smaller value, the remainder stays open and the target is marked as taken; EMA/MACD exits or protection manage what remains.
Technical exits
Enable SME_EXIT_ON_MACD_FLIP to exit profitably after MACD crosses below zero.
A close crossing below the EMA is also a built-in profitable exit and has no separate switch. Both technical exits wait for the fee-aware profitable floor. Only enabled protection can deliberately close at a loss.
Good market conditions
This strategy generally suits:
- liquid pairs with small spreads;
- recoveries after a controlled pullback;
- an EMA that acts as a meaningful dividing line;
- MACD improving from negative territory;
- enough range for the risk/reward target.
Avoid flat markets where price repeatedly crosses the EMA and MACD hovers around zero. Large buffers reduce some noise but can worsen entry price.
Creating the strategy
Create a spot strategy and choose Simple MACD and EMA as both methods. Start on the default 15-minute period in backtesting or paper trading.
First tune the EMA and MACD relationship, then the two signal lookbacks. Choose pip or percentage distances, inspect conservative versus aggressive stops, and only then tune risk/reward and partial sizing.
Strategy settings
Trading and safeguards
| Setting | Description |
|---|---|
BUY_ENABLED | Enables entries. |
SELL_ENABLED | Enables all exits. |
PERIOD | Candle period; default 15 minutes. |
TRADING_LIMIT | Compatibility fallback only. It is ignored while the strategy-specific trading limit contains a positive value. Configure the strategy-specific setting for normal use. For USDT-BTC, this value is in USDT. |
SME_TRADING_LIMIT | For USDT-BTC, the amount of USDT used for an entry. |
FUNDS_RESERVE | For USDT-BTC, the amount of USDT the bot must leave unused. |
KEEP_QUOTE | For USDT-BTC, the amount of BTC the strategy must not sell. |
MIN_VOLUME_TO_BUY | General minimum buy value. For USDT-BTC, this value is in USDT. |
MIN_VOLUME_TO_SELL | General minimum sell value. For USDT-BTC, this value is in USDT. |
SME_MIN_ORDER_VALUE | Strategy minimum entry value. For USDT-BTC, this value is in USDT. |
SME_MIN_SELL_VALUE | Strategy minimum exit value. For USDT-BTC, this value is in USDT. |
GAIN | General gain fallback retained in configuration. |
SME_COOLDOWN_MS | Delay between actions. |
SME_ENFORCE_COOLDOWN_IN_BACKTEST | Reproduces the cooldown in backtests. |
SME_MAX_SPREAD_PCT | Relative spread ceiling for entries. |
SME_MAX_SPREAD_ABSOLUTE | Optional absolute spread ceiling; 0 disables it. For USDT-BTC, this value is in USDT. |
SME_NEWS_BLOCK | Manually blocks entries. |
SME_NEWS_BLOCK_UNTIL | Blocks entries until the configured time. |
Signal
| Setting | Description |
|---|---|
SME_EMA_LENGTH | EMA used for setup, trigger, trail, and technical exit. |
SME_MACD_FAST | Fast MACD EMA length. |
SME_MACD_SLOW | Slow MACD EMA length. |
SME_MACD_SIGNAL | MACD signal-line length. |
SME_MACD_CROSS_LOOKBACK | Candles in which a bullish MACD zero cross remains acceptable. |
SME_SETUP_LOOKBACK | Candles searched for the earlier below-EMA, negative-MACD setup. |
SME_ENTRY_BUFFER_PIPS | Required EMA clearance in pip mode. |
SME_ENTRY_BUFFER_PCT | Required EMA clearance in percentage mode. |
Risk and exit
| Setting | Description |
|---|---|
SME_USE_PIPS | Selects pip rather than percentage distances. |
SME_PIP_SIZE | For USDT-BTC, the USDT value represented by one pip. |
SME_STOP_BUFFER_PIPS | Initial EMA stop buffer in pip mode. |
SME_TRAIL_BUFFER_PIPS | EMA-following stop buffer in pip mode. |
SME_STOP_PCT | Initial EMA stop buffer in percentage mode. |
SME_TRAIL_BUFFER_PCT | EMA-following stop buffer in percentage mode. |
SME_STOP_MODE | Chooses EMA-buffer (conservative) or recent-low (aggressive) initial stop. |
SME_SWING_LOOKBACK | Candles searched for the aggressive recent-low stop. |
SME_PARTIAL_SELL_PCT | Position percentage sold at the risk/reward target. |
SME_RISK_REWARD | Initial-risk multiplier used for the target. |
SME_MIN_NET_GAIN_PCT | Intended gain beyond round-trip fee break-even. |
SME_USE_PROTECTION | Allows the calculated stop to execute. |
SME_MOVE_STOP_TO_BREAKEVEN | Raises the stop to entry after the target event. |
SME_EXIT_ON_MACD_FLIP | Enables profitable exit on bearish MACD zero cross. |
Backtesting
| Setting | Description |
|---|---|
BF_SINCE | Backtest start. |
BF_UNTIL | Backtest end. |
DEEP_TESTING | Enables deeper backtesting mode. |
Practical tuning directions
If entries are too early, increase the entry buffer or require a more recent setup. If they are too late, reduce the buffer before making MACD extremely fast.
Use percentage mode for instruments with very different price scales. Use pip mode only when SME_PIP_SIZE matches the market’s price scale (USDT per BTC on USDT-BTC).
When using a partial target, test the remainder explicitly: its eventual outcome depends on the EMA trail, profitable signal exits, and whether protection is enabled.
Important limitations
- EMA and MACD can whipsaw around flat levels.
- A developing MACD zero cross can reverse before completion.
- “Aggressive” stop mode is not guaranteed to be tighter.
- The EMA exit has no user switch and waits for profit.
- A calculated stop does nothing while protection is disabled.
- News blocking is manual.
- Live fills can differ from backtests.
Simple MACD and EMA works best when the earlier weak phase and the current recovery are visibly part of the same move. Lookbacks should preserve that relationship, not merely increase the number of trades.