该策略基于市场的低点买入、高点卖出的思想设计。它会追踪过去一定周期内的最高价和最低价,在价格突破最低价时建立多头头寸,在价格跌破最高价或达到止盈条件时平仓。同时,该策略加入了可选的趋势过滤器,只有在价格处于上升趋势时才会买入。
最低价(lowcriteria):调用ta.lowest函数,基于用户设定的回看周期(默认20根K线)计算过去一定周期内的最低价,并绘制最低价线。
最高价(highcriteria):调用ta.highest函数,基于用户设定的回看周期(默认10根K线)计算过去一定周期内的最高价,并绘制最高价线。
当现价突破最低价线时,即发出买入信号,建立多头头寸。
提供两种出场方式可选:
固定止盈:当价格达到设定的止盈水平(如超过入场价8%)时,平仓套利。
最高价突破:当价格跌破最高价线时,判断趋势反转,平仓止损。
加入EMA均线判断趋势方向,只有在价格高于EMA均线(称为上升趋势)时才会买入。该过滤器可选择开启或关闭。
利用突破低点买入、突破高点卖出的策略,符合市场基本规律。
增加趋势判断机制,可避免价格震荡时频繁开仓。
提供两种出场选择,既可追求高止盈,也可减少亏损。
可自定义参数,适应更广泛的市场环境。
策略优化空间大,可通过参数调整、过滤器设计等进一步完善。
固定止盈无法根据市场实际走势调整,可能导致过早止盈或止盈幅度过小。
突破最高价卖出时,可能已产生较大亏损,无法有效控制损失。
EMA趋势判断仅从一定历史周期判断,可能滞后于实际趋势转变。
回测数据无法代表未来,实盘效果存在不确定性。
增加止盈方式:如移动止盈、级差止盈等,使止盈水平能根据市场走势实时调整。
优化出场信号:比如改为分批出场,或增加其他指标判断。
优化趋势判断:如加入更多指标,或机器学习判断。
优化参数:通过更广泛的回测找到最佳参数组合。
增加止损方式:使损失控制更加灵活有效。
本策略总体运用了经典的低买高卖原则,在一定条件下可以取得较好的效果。但策略本身仍有优化空间,通过参数调整、出场优化、止损方式改进等可以获得更稳定的收益。本文对策略的原理、优势、风险、优化方向等进行了全面深入的分析,旨在提供策略思路的同时也提醒投资者注意风险,谨慎对待量化交易。
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @version=5
// Author = TradeAutomation
strategy(title="Low-High-Trend Strategy", shorttitle="Low-High-Trend Strategy", process_orders_on_close=true, overlay=true, commission_type=strategy.commission.cash_per_order, commission_value=1, slippage=3, initial_capital = 25000, margin_long=50, margin_short=50, default_qty_type=strategy.percent_of_equity, default_qty_value=110)
// Backtest Date Range Inputs //
StartTime = input(defval=timestamp('01 Jan 2000 05:00 +0000'), title='Start Time')
EndTime = input(defval=timestamp('01 Jan 2099 00:00 +0000'), title='End Time')
InDateRange = true
// Strategy Calculations //
lowcriteria = ta.lowest(close, input(20, "Lowest Price Lookback", tooltip="The strategy will BUY when the price crosses over the lowest it has been in the last X amount of bars"))[1]
highcriteria = ta.highest(close, input(10, "Highest Price Lookback", tooltip="If Take-Profit is not checked, the strategy will SELL when the price crosses under the highest it has been in the last X amount of bars"))[1]
plot(highcriteria, color=color.green)
plot(lowcriteria, color=color.red)
// Take Profit //
TakeProfitInput = input(true, "Sell with Take-Profit % intead of highest price cross?")
TakeProfit = ta.crossover(close,strategy.position_avg_price*(1+(.01*input.float(8, title="Take Profit %", step=.25))))
// Operational Functions //
TrendFilterInput = input(true, "Only buy when price is above EMA trend?")
ema = ta.ema(close, input(200, "EMA Length"))
TrendisLong = (close>ema)
plot(ema)
// Entry & Exit Functions//
if (InDateRange and TrendFilterInput==true)
strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria) and TrendisLong)
if (InDateRange and TrendFilterInput==false)
strategy.entry("Long", strategy.long, when = ta.crossover(close, lowcriteria))
if (InDateRange and TakeProfitInput==true)
strategy.close("Long", when = TakeProfit)
if (InDateRange and TakeProfitInput==false)
strategy.close("Long", when = ta.crossunder(close, highcriteria))
if (not InDateRange)
strategy.close_all()