该策略是一个基于趋势线突破的交易系统,结合了移动平均线和价格突破概念。策略核心是通过监测收盘价对移动平均线的突破来产生交易信号,并设置了基于最近低点的止损和2:1比例的止盈来管理风险。策略采用简单移动平均线作为趋势指标,通过价格与均线的交叉来判断趋势方向的改变。
策略使用20周期的简单移动平均线(SMA)作为趋势指标。当收盘价从均线下方突破到上方时,系统会产生做多信号。止损位设置在过去7根K线的最低点,这样可以避免过于靠近入场点。止盈位的设置采用了经典的2:1盈亏比,即止盈距离为止损距离的2倍。策略还包含了可视化组件,在图表上标注出趋势线、交易信号以及止损止盈位置。
这是一个结构完整、逻辑清晰的趋势跟随策略。通过移动平均线突破产生信号,配合合理的风险管理机制,具有良好的实用性。虽然存在一些固有风险,但通过建议的优化方向可以进一步提升策略的稳定性和收益性。策略适合在趋势明显的市场环境中使用,交易者可根据具体市场特点调整参数设置。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-11 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend Breakout with SL and TP", overlay=true)
// Parametrlar
length = input(25, title="Length for SL Calculation")
trendLength = input(20, title="Trend Line Length")
// Trend chizig'ini hisoblash
trendLine = ta.sma(close, trendLength)
// Yopilish narxi trend chizig'ini yorib o'tganda signal
longSignal = close > trendLine and close[1] <= trendLine
// Oxirgi 7 shamning minimumini hisoblash
lowestLow = ta.lowest(low, 7)
// Stop Loss darajasini belgilash
longSL = lowestLow // SL oxirgi 7 shamning minimumiga teng
// Take Profit darajasini SL ga nisbatan 2 baravar ko'p qilib belgilash
longTP = longSL + (close - longSL) * 2 // TP 2:1 nisbatida
// Savdo bajarish
if longSignal
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit", "Long", limit=longTP)
strategy.exit("Stop Loss", "Long", stop=longSL)
// Grafikda trend chizig'ini chizish
plot(trendLine, title="Trend Line", color=color.blue, linewidth=2)
// Signal chizish
plotshape(longSignal, style=shape.labelup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
// SL va TP darajalarini ko'rsatish
// if longSignal
// // SL chizig'i
// line.new(bar_index, longSL, bar_index + 1, longSL, color=color.red, width=2, style=line.style_dashed)
// // TP chizig'i
// line.new(bar_index, longTP, bar_index + 1, longTP, color=color.green, width=2, style=line.style_dashed)
// // SL va TP label'larini ko'rsatish
// label.new(bar_index, longSL, "SL: " + str.tostring(longSL), color=color.red, style=label.style_label_down, textcolor=color.white, size=size.small)
// label.new(bar_index, longTP, "TP: " + str.tostring(longTP), color=color.green, style=label.style_label_up, textcolor=color.white, size=size.small)