该策略通过计算高点和低点的简单移动均线,并与当前收盘价进行对比来判断买入和卖出时机。它的目标是捕捉价格突破均线的信号,以获取趋势的早期机会。
计算长度为4的高点简单移动平均线
计算长度为4的低点简单移动平均线
当收盘价突破高点均线时,做多入场
当收盘价突破低点均线时,做空入场
使用固定止损和止盈策略进行风险管理
使用简单指标,容易理解实现
及时捕捉价格突破均线的信号
可以快速过滤掉部分噪音,识别趋势
计算量小,可以降低策略运转消耗
适合作为基础策略进行扩展
需要合理的参数设定,避免过于灵敏
无法应对大幅突破带来的风险
存在一定程度的震荡套利风险
无法自动调整止损止盈位置
难以判断趋势背景的长短
测试不同参数对信号质量的影响
增加过滤条件,确保突破的有效性
结合趋势分析,避免被套
开发动态止损止盈策略
优化止损机制,提高策略胜率
在不同周期测试策略健壮性
该策略通过简单的指标研判价格动能,给出了基本的趋势交易思路。配合参数优化、风险控制等进一步完善,其交易逻辑可延展性强,可发展为较为稳健的量化系统。总体来说,该策略易于上手实践,适合作为量化交易的入门策略。
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-13 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("HiLo", overlay=true)
// Testing a specific period
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(4, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2017, "Backtest Stop Year")
testStopMonth = input(5, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() =>
time >= testPeriodStart and time <= testPeriodStop ? true : false
//HiLo Strategy
length = input(4, minval=0)
displace = input(0, minval=0)
highsma = sma(high, length)
lowsma = sma(low, length)
longCondition = close > highsma[displace]
if (longCondition)
strategy.entry("long", true)
shortCondition = close < lowsma[displace]
if (shortCondition)
strategy.entry("short", false)
// Exit seems with a problem. it keeps saying the order's limit (2000) was reached even if I back test it just for a day.
// If the two lines bellow are commented, then it it works. Anyone? Any idea what's wrong?
// strategy.exit("exit", "long", profit=10, loss=5)
// strategy.exit("exit", "short", profit=10, loss=5)