
This is an intelligent trend-following strategy based on multiple technical indicator crossover signals. The strategy integrates three major technical indicators: Exponential Moving Average (EMA), Relative Strength Index (RSI), and Moving Average Convergence Divergence (MACD) to identify market trends through multi-dimensional signal confirmation, coupled with dynamic stop-loss and take-profit for risk management. The strategy is designed for fully automated trading and is particularly suitable for intraday trading.
The core logic is based on three layers of technical indicator filtering: 1. Using 9-period and 21-period EMA crossovers to confirm trend direction 2. Utilizing RSI to filter overbought and oversold areas, avoiding entry in extreme market conditions 3. Further confirming trend strength and direction through MACD indicator
Entry signals require simultaneous satisfaction of the following conditions: - Long conditions: Short-term EMA crosses above long-term EMA, RSI below 70, and MACD line above signal line - Short conditions: Short-term EMA crosses below long-term EMA, RSI above 30, and MACD line below signal line
The strategy employs a percentage-based position sizing model, using 10% of account equity per trade, with 2% take-profit and 1% stop-loss for risk control.
Risk control suggestions: - Dynamically adjust stop-loss and take-profit percentages based on market volatility - Add trend strength filters to reduce trading frequency in ranging markets - Optimize holding time management to avoid overnight risks
The strategy constructs a relatively complete trend-following system through the synergy of multiple technical indicators. Its strengths lie in high signal reliability and comprehensive risk management, though it faces certain limitations in terms of lag and market environment dependency. Through the suggested optimization directions, the strategy can further enhance its adaptability and stability. For live trading application, it is recommended to conduct thorough backtesting and parameter optimization, making appropriate adjustments based on actual market conditions.
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © egidiopalmieri
//@version=5
strategy("BTCUSD Intraday - AI-like Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)
// ==========================
// Risk and Strategy Parameters
// ==========================
takeProfitPerc = input.float(2.0, "Take Profit (%)", step=0.1) / 100.0 // Target profit: 2%
stopLossPerc = input.float(1.0, "Stop Loss (%)", step=0.1) / 100.0 // Stop loss: 1%
// ==========================
// Technical Indicators
// ==========================
emaShortPeriod = input.int(9, "Short EMA (period)", minval=1)
emaLongPeriod = input.int(21, "Long EMA (period)", minval=1)
emaShort = ta.ema(close, emaShortPeriod)
emaLong = ta.ema(close, emaLongPeriod)
// RSI Indicator
rsiPeriod = input.int(14, "RSI (period)", minval=1)
rsiValue = ta.rsi(close, rsiPeriod)
// MACD Indicator
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
// ==========================
// Entry Conditions
// ==========================
// LONG entry: short EMA crosses above long EMA, RSI not in overbought zone, MACD in bullish trend
longCondition = ta.crossover(emaShort, emaLong) and (rsiValue < 70) and (macdLine > signalLine)
// SHORT entry: short EMA crosses below long EMA, RSI not in oversold zone, MACD in bearish trend
shortCondition = ta.crossunder(emaShort, emaLong) and (rsiValue > 30) and (macdLine < signalLine)
// ==========================
// Signal Visualization
// ==========================
plotshape(longCondition, title="Long Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Long")
plotshape(shortCondition, title="Short Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Short")
// ==========================
// Entry Logic
// ==========================
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// ==========================
// Stop Loss and Take Profit Management
// The levels are calculated dynamically based on the average entry price
// ==========================
if strategy.position_size > 0
// For long positions
longSL = strategy.position_avg_price * (1 - stopLossPerc)
longTP = strategy.position_avg_price * (1 + takeProfitPerc)
strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
if strategy.position_size < 0
// For short positions
shortSL = strategy.position_avg_price * (1 + stopLossPerc)
shortTP = strategy.position_avg_price * (1 - takeProfitPerc)
strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)
// ==========================
// Final Notes
// ==========================
// This script uses rules based on technical indicators to generate signals
// "AI-like". The integration of actual AI algorithms is not natively supported in PineScript.
// It is recommended to customize, test, and validate the strategy before using it in live trading.