
Chiến lược này là một hệ thống giao dịch theo dõi xu hướng dựa trên đường trung bình di chuyển hai chỉ số ((EMA)). Chiến lược sử dụng hai đường EMA 44 chu kỳ và 200 chu kỳ, kết hợp với tín hiệu phá vỡ giá để xác định hướng giao dịch. Đồng thời tích hợp cơ chế quản lý rủi ro, bao gồm tính toán vị trí động và dừng chân di chuyển.
Lập luận cốt lõi của chiến lược dựa trên sự tương tác của giá với hai đường EMA. Sử dụng EMA 44 chu kỳ để tạo ra các kênh lên xuống cho giá cao nhất và giá thấp nhất, 200 chu kỳ EMA như bộ lọc xu hướng dài hạn. Khi giá đóng cửa phá vỡ đường EMA trên đường và đáp ứng các điều kiện lọc 200 EMA, hệ thống tạo ra nhiều tín hiệu; Khi giá đóng cửa phá vỡ đường EMA trên đường và đáp ứng các điều kiện lọc 200 EMA, hệ thống tạo ra tín hiệu trống.
Đây là một chiến lược theo dõi xu hướng có cấu trúc và logic rõ ràng. Nó cung cấp tín hiệu giao dịch thông qua kênh EMA kép và lọc xu hướng dài hạn, kết hợp với cơ chế quản lý rủi ro hoàn hảo, có tính thực tế tốt.
/*backtest
start: 2024-02-25 00:00:00
end: 2024-03-17 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("RENTABLE Dual EMA Breakout TSLA ", overlay=true)
// Inputs for EMA lengths and risk per trade
length = input(44, title="EMA Length")
longTermLength = input(200, title="Long-Term EMA Length")
riskPerTrade = input.float(1.0, title="Risk per Trade (%)", minval=0.1, maxval=10.0)
// Additional inputs for strategy customization
useFilter = input.bool(true, title="Use 200 EMA Filter")
tradeDirection = input.string("Both", title="Trade Direction", options=["Long", "Short", "Both"])
// EMAs based on the high and low prices and long-term EMA
emaHigh = ta.ema(high, length)
emaLow = ta.ema(low, length)
ema200 = ta.ema(close, longTermLength)
// Plotting EMAs on the chart
plot(emaHigh, color=color.green, title="High EMA")
plot(emaLow, color=color.red, title="Low EMA")
plot(ema200, color=color.blue, title="200 EMA")
// Entry conditions with optional EMA filter
longCondition = close > emaHigh and (useFilter ? close > ema200 : true)
shortCondition = close < emaLow and (useFilter ? close < ema200 : true)
// Calculating stop-loss and position size
longStop = emaLow
shortStop = emaHigh
riskPerShareLong = close - longStop
riskPerShareShort = shortStop - close
equity = strategy.equity
// Ensure risk per share is positive for calculations
riskPerShareLong := riskPerShareLong > 0 ? riskPerShareLong : 0.01
riskPerShareShort := riskPerShareShort > 0 ? riskPerShareShort : 0.01
positionSizeLong = (equity * riskPerTrade / 100) / riskPerShareLong
positionSizeShort = (equity * riskPerTrade / 100) / riskPerShareShort
// Ensure position sizes are positive before entering trades
if (longCondition and (tradeDirection == "Long" or tradeDirection == "Both") and positionSizeLong > 0)
strategy.entry("Long", strategy.long, qty= positionSizeLong)
if (shortCondition and (tradeDirection == "Short" or tradeDirection == "Both") and positionSizeShort > 0)
strategy.entry("Short", strategy.short, qty=positionSizeShort)
// Applying the stop-loss to strategy
strategy.exit("Exit Long", "Long", stop=longStop)
strategy.exit("Exit Short", "Short", stop=shortStop)
////Usar en 1,2 3 4 HRS TSLA