该策略通过计算快速移动平均线、慢速移动平均线、MACD指标,实现对价格趋势的判断,构建金叉死叉交易信号,并结合止盈止损追踪止损来锁定利润,实现对趋势的持续追踪。
该策略主要基于三个指标进行构建。
首先,计算快速移动平均线和两个慢速移动平均线。当快速移动平均线上穿两个慢速移动平均线时生成买入信号;当快速移动平均线下穿两个慢速移动平均线时生成卖出信号。这样可以判断价格的短期趋势和长期趋势的关系,实现金叉死叉交易。
其次,计算MACD指标,包括MACD线、信号线和直方图。当MACD直方图>0时为多头指标;当MACD直方图时为空头指标。这样辅助判断金叉死叉信号的可靠性。
最后,结合止盈止损追踪止损机制。采用止盈点和止损点来锁定利润和控制风险;采用追踪止损来跟踪利润。
该策略具有以下优势:
该策略也存在一些风险:
对应风险的解决方法:
该策略还可以从以下几个方面进行优化:
该策略整体来说是一个利用金叉死叉与MACD指标判断趋势,实现追踪止损的简单有效策略。优点是实现了趋势跟踪和利润锁定,可自定义性较强,适用于多种品种,是一种通用型的参数优化型策略。存在一定的风险和可优化空间,但总体而言是一种可靠实用的交易策略。
/*backtest
start: 2023-12-14 00:00:00
end: 2023-12-21 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy('The Puria Method', shorttitle = 'Puria',overlay = true)
//=== GENERAL INPUTS ===
// short ma
maFastSource = input(defval = close, title = "Fast MA Source")
maFastLength = input(defval = 5, title = "Fast MA Period", minval = 1)
// long ma 1
maSlow1Source = input(defval = low, title = "Slow MA1 Source")
maSlow1Length = input(defval = 85, title = "Slow MA Period", minval = 1)
// long ma 2
maSlow2Source = input(defval = low, title = "Slow MA2 Source")
maSlow2Length = input(defval = 75, title = "Slow MA Period", minval = 1)
//macd
macdFastLength = input(defval = 12, title = "Fast MACD Period", minval = 1)
macdSlowLength = input(defval = 26, title = "Slow MACD Period", minval = 1)
macdSmaLength = input(defval = 9, title = "SMA MACD Period", minval = 1)
// the risk management inputs
inpTakeProfit = input(defval = 30, title = "Take Profit", minval = 0)
inpStopLoss = input(defval = 10, title = "Stop Loss", minval = 0)
inpTrailStop = input(defval = 5, title = "Trailing Stop Loss", minval = 0)
inpTrailOffset = input(defval = 0, title = "Trailing Stop Loss Offset", minval = 0)
// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na
// === SERIES SETUP ===
maFast = ema(maFastSource, maFastLength)
maSlow1 = wma(maSlow1Source, maSlow1Length)
maSlow2 = wma(maSlow2Source, maSlow2Length)
[_, signal, histLine] = macd(close, macdFastLength, macdSlowLength, macdSmaLength)
// === PLOTTING ===
fast = plot(maFast, title = "Fast MA", color = green, linewidth = 2, style = line, transp = 50)
slow1 = plot(maSlow1, title = "Slow MA1", color = red, linewidth = 2, style = line, transp = 50)
slow2 = plot(maSlow2, title = "Slow MA2", color = red, linewidth = 2, style = line, transp = 50)
// === LOGIC ===
signalUp = crossover(maFast, maSlow1) and crossover(maFast, maSlow2) and histLine > 0
signalDown = crossunder(maFast, maSlow1) and crossunder(maFast, maSlow2) and histLine < 0
// ===STRATEGY===
strategy.entry(id = "Long", long = true, when = signalUp)
strategy.entry(id = "Short", long = false, when = signalDown)
strategy.exit("Exit Long", from_entry = "Long", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)
strategy.exit("Exit Short", from_entry = "Short", profit = useTakeProfit, loss = useStopLoss, trail_points = useTrailStop, trail_offset = useTrailOffset)