该策略结合了超级趋势指标和MACD指标,通过捕捉小趋势来获取利润。策略使用超级趋势指标来判断当前市场趋势,同时使用MACD指标作为进场和出场的辅助条件。策略逻辑清晰,易于理解和实现。
该策略通过结合超级趋势指标和MACD指标,在捕捉小趋势的同时也考虑了趋势的持续性,是一个较为全面和均衡的策略。策略优势在于逻辑清晰,易于理解和实现,同时通过使用更长周期的MACD指标作为辅助条件,可以有效过滤掉一些假信号。但策略也存在一些风险,如在震荡市场中可能出现频繁交易,对参数设置较为敏感,以及缺乏止损措施等。针对这些风险,可以从加入更多过滤条件、优化参数、加入止损等方面进行优化和改进。总的来说,该策略可以作为一个基础性的策略框架,通过不断优化和改进,有望成为一个稳定盈利的策略。
/*backtest
start: 2024-02-01 00:00:00
end: 2024-02-29 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Samsuga supertrend", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
atrPeriod = input.int(7, "ATR Length", minval = 1)
factor = input.float(1.0, "Factor", minval = 0.01, step = 0.01)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
supertrend := barstate.isfirst ? na : supertrend
upTrend = plot(direction <= 0 ? supertrend : na, "Up Trend", color = color.green, style = plot.style_linebr)
downTrend = plot(direction <= 0 ? na : supertrend, "Down Trend", color = color.red, style = plot.style_linebr)
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
longcondition = direction[1] > direction
shortCondition = direction[1] < direction
macdp1 = 3
macdp2=10
macdp3=6
[macdLine, signalLine, histLine] =request.security(symbol = syminfo.tickerid, timeframe = "30",expression = ta.macd(close,macdp1,macdp2,macdp3),lookahead=barmerge.lookahead_on)
// plot(macdLine, title = "MACD", color = #2962FF)
// plot(signalLine, title = "Signal", color = #FF6D00)
// 8, 21, 5
// 8,13,9
// 12,26,9
// 1--> 3, 17, 5
// 3, 10, 16
// log.info(str.tostring(syminfo.tickerid)+str.tostring(histLine[0]))
// /////////----------------METHOD 1-----------------////////////////
// if(longcondition)
// if(strategy.opentrades>0)
// strategy.close("Long","Prev Exit", immediately = true)
// if( histLine[0] > 0.1)
// strategy.entry(id= "Long", direction=strategy.long, comment = "update long")
// else if(shortCondition and strategy.openprofit<=0.1)
// strategy.close("Long",comment = "Close",immediately = true)
// /////////----------------METHOD 2-----------------////////////////
// if(longcondition)
// if(histLine[0] > 0)
// strategy.entry(id= "Long", direction=strategy.long, comment = "update long" )
// strategy.exit("Long", loss = close*0.2)
// else if(shortCondition )
// strategy.close("Long",comment = "Close",immediately = true)
// /////////----------------METHOD 3-----------------////////////////
// log.info(str.tostring(syminfo.tickerid)+str.tostring(histLine[0]))
if(longcondition)
if(histLine[0] > 0)
strategy.close("Short",comment = "E-S", alert_message = "E-S",disable_alert = true)
strategy.entry(id= "Long", direction=strategy.long, comment = "L",alert_message = "L")
else if(shortCondition)
if(histLine[0] < 0)
strategy.close("Long",comment = "E-L",alert_message = "E-L",disable_alert = true)
strategy.entry(id= "Short", direction=strategy.short, comment = "S",alert_message = "S")