本策略名为“SMA和PSAR多空策略”,它结合了简单移动平均线(SMA)和抛物线转向指标(PSAR)的优势,据此判断市场趋势方向,以发出交易信号。当SMA显示正在上升趋势而PSAR位于价格之下时,视为买入时机;当SMA显示正在下降趋势而PSAR高于价格时,则为卖出信号。
该策略使用100周期的SMA判断总体趋势方向。当收盘价上涨突破SMA 100时,被定义为上升趋势;当收盘价下跌突破SMA 100时,定义为下降趋势。
同时,计算PSAR指标判断细节入市点。PSAR起始值设置为0.02,递增值为0.01,最大值为0.2。当在上升趋势中,如果PSAR位于收盘价之下,产生买入信号;而如果在下降趋势中PSAR高于收盘价,则产生卖出信号。
综合来看,在判断为上升趋势时,如果PSAR低于收盘价,则产生买入信号;而在判断为下降趋势时,如果PSAR高于收盘价,则产生卖出信号。
为减少交易风险,该策略还设置了时间 exits,交易5分钟后平仓。
这种策略结合SMA和PSAR指标判断趋势和入市时机,可以有效利用两种指标的优势,提高决策准确性。SMA可用于判断大趋势,而PSAR对细节入市点更敏感,两者搭配使用可使策略更加完善。
另外设置时间exit有助于控制单笔交易风险,避免亏损过大。整体上,该策略稳健可靠,适合多数市场环境。
SMA和PSAR指标可能产生错误信号,导致不必要的交易亏损。
时间exit设置较短,未必能充分捕捉趋势行情。
参数设置(如SMA周期、PSAR 参数等)可能不适应某些具体品种,需要优化。
回测数据拟合风险。实盘中市场环境会发生变化,策略表现可能不如回测。
测试不同SMA周期参数,找到对具体品种更合适的数值。
测试优化PSAR的参数设置,使其对细节入市点判断更为准确。
延长时间exit的参数,在盈利充分的前提下,适当延长持仓时间。
添加止损策略,更好控制单笔交易最大损失。
本策略综合运用SMA和PSAR等指标判断市场走势和入市时机,稳健可靠,适合多数市场环境。同时设置时间exit有助于控制风险。本策略可通过参数优化、止损策略等进一步完善,从而获得更好的实盘效果。
/*backtest
start: 2023-12-10 00:00:00
end: 2023-12-17 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy(title="SMA and Parabolic SAR Strategy with Time-Based Exit", shorttitle="SMA+PSAR", overlay=true)
// Define the parameters for the Parabolic SAR
psarStart = 0.02
psarIncrement = 0.01
psarMax = 0.2
// Calculate the 100-period SMA
sma100 = sma(close, 1000)
// Calculate the Parabolic SAR
sar = sar(psarStart, psarIncrement, psarMax)
// Determine the trend direction
isUpTrend = close < sma100
// Buy condition: Up trend and SAR below price
buyCondition = isUpTrend and sar < close
// Sell condition: Down trend and SAR above price
sellCondition = not isUpTrend and sar > close
// Plot the SMA and Parabolic SAR
plot(sma100, color=color.blue, title="100-period SMA")
plot(sar, color=color.red, title="Parabolic SAR")
// Plot buy and sell signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)
// Strategy entry
strategy.entry("Buy", strategy.long, when = buyCondition)
// Time-based exit after 5 minutes
strategy.exit("Close Buy", from_entry = "Buy", when = time[0] > timestamp(year, month, dayofmonth, hour, minute + 5))
strategy.entry("Sell", strategy.short, when = sellCondition)
// Time-based exit after 5 minutes
strategy.exit("Close Sell", from_entry = "Sell", when = time[0] > timestamp(year, month, dayofmonth, hour, minute + 5))