该策略基于移动量的突破来产生交易信号,主要思想是在指定的时间段内观察价格的移动情况,以移动量的突破来判断价格的趋势变化。
该策略通过计算价格在特定时间段内的最高价和最低价,即pivot high和pivot low,来判断价格的移动情况。
具体来说,策略会计算过去N根K线的最高价作为pivot high,过去M根K线的最低价作为pivot low。当当前K线的高点超过pivot high时,产生做多信号;当当前K线的低点跌破pivot low时,产生做空信号。
做多和做空后,策略会使用ATR来设定止损,并在日内阶段性止损。同时,策略还会在特定时间段内(如14:55分)平仓所有头寸。
该策略简单有效地利用了价格在特定时间范围内的突破来捕捉趋势,非常适合日内短线交易。计算思路清晰、易于实现。
可以适当调整时间段,或组合其他指标确定入场时机
可以适当调整参数,或增加过滤条件,例如趋势指标、成交量等
可以调整仓位大小,或适当延长持仓时间
应根据不同市况调整参数,或采用机器学习等方法自动优化
尝试其他价格数据,如典型价格、均价等
增加成交量或波动率等过滤条件
尝试不同的参数组合
结合趋势指标,确定趋势方向
利用机器学习方法自动优化参数
扩展至多个时间段,改进入场时机
该策略整体思路清晰简洁,通过有效利用价格的移动突破来捕捉短期趋势,实现了较高的盈利因子。策略参数较少,易于测试和优化,适合日内短线操作。虽然存在一定程度的滞后和假信号问题,但可以通过参数调整、加入过滤条件等方法加以改进,具有很大的优化空间。该策略为我们提供了一个基于突破思想的有效交易框架。
/*backtest
start: 2022-10-27 00:00:00
end: 2023-11-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// ____________ _________ _____________
// |____________| ||________| ||__________|
// || || || ||
// || ||________|| ||
// || H E ||________ U L L || H A R T I S T
// || || || ||
// || ||________|| ||__________
// || ||________| ||__________|
//@version=5
// strategy("PIVOT STRATEGY [5MIN TF]",overlay=true ,commission_type = strategy.cash, commission_value = 30 , slippage = 2, default_qty_value = 60, currency = currency.NONE, pyramiding = 0)
leftbars = input(defval = 10)
rightbars = input(defval = 15)
// ═══════════════════════════ //
// ——————————> INPUTS <——————— //
// ═══════════════════════════ //
EMA1 = input.int(title='PRICE CROSS EMA', defval = 150, minval = 10 ,maxval = 400)
factor1 = input.float(title='_ATR LONG',defval = 3.2 , minval = 1 , maxval = 5 , step = 0.1, tooltip = "ATR TRAIL LONG")
factor2 = input.float(title='_ATR SHORT',defval = 3.2 , minval = 1 , maxval = 5 , step = 0.1, tooltip = "ATR TRAIL SHORT")
risk = input.float(title='RISK',defval = 200 , minval = 1 , maxval = 5000 , step = 50, tooltip = "RISK PER TRADE")
var initialCapital = strategy.equity
t = time(timeframe.period, '0935-1400:1234567')
time_cond = true
// ══════════════════════════════════ //
// ———————————> EMA DATA <——————————— //
// ══════════════════════════════════ //
ema1 = ta.ema(close, EMA1)
plot(ema1, color=color.new(color.yellow, 0), style=plot.style_linebr, title='ema1')
// ══════════════════════════════════ //
// ————————> TRAIL DATA <———————————— //
// ══════════════════════════════════ //
// *******Calculate LONG TRAIL data*****
ATR_LO = ta.atr(14)*factor1
// *******Calculate SHORT TRAIL data*****
ATR_SH = ta.atr(14)*factor2
longStop = close - ATR_LO
shortStop = close + ATR_SH
// Plot atr data
//plot(longStop, color=color.new(color.green, 0), style=plot.style_linebr, title='Long Trailing Stop')
//plot(shortStop , color=color.new(color.red, 0), style=plot.style_linebr, title='Short Trailing Stop')
// ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ //
// ————————————————————————————————————————————————————————> PIVOT DATA <———————————————————————————————————————————————————————————————————————————————————————————————————— //
// ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ //
ph = ta.pivothigh(close,leftbars, rightbars)
pl = ta.pivotlow(close,leftbars, rightbars)
pvt_condition1 = not na(ph)
upper_price = 0.0
upper_price := pvt_condition1 ? ph : upper_price[1]
pvt_condition2 = not na(pl)
lower_price = 0.0
lower_price := pvt_condition2 ? pl : lower_price[1]
// Signals
long = ta.crossover(high, upper_price + syminfo.mintick)
short = ta.crossunder(low, lower_price - syminfo.mintick)
plot(upper_price, color= close > ema1 ? color.green : na, style=plot.style_line, title='PH')
plot(lower_price, color= close < ema1 ? color.red : na, style=plot.style_line, title='PL')
// ══════════════════════════════════//
// ————————> LONG POSITIONS <————————//
// ══════════════════════════════════//
//******barinstate.isconfirmed used to avoid repaint in real time*******
if ( long and strategy.opentrades==0 and barstate.isconfirmed and time_cond and close >= ema1 )
strategy.entry(id= "Long" ,direction = strategy.long, comment = "B")
//plot(longStop , color=color.new(color.blue, 0), style=plot.style_linebr, title='long Stop')
if strategy.position_size > 0
strategy.exit("long tsl", "Long" , stop = longStop ,comment='S')
// ═════════════════════════════════════//
// ————————> SHORT POSITIONS <————————— //
// ═════════════════════════════════════//
if ( short and strategy.opentrades==0 and barstate.isconfirmed and time_cond and close <= ema1 )
strategy.entry(id = "Short" ,direction = strategy.short, comment = "S")
if strategy.position_size < 0
strategy.exit("short tsl", "Short" , stop = shortStop ,comment='B')
// ════════════════════════════════════════════════//
// ————————> CLOSE ALL POSITIONS BY 3PM <————————— //
// ════════════════════════════════════════════════//
strategy.close_all(when = hour == 14 and minute == 55)
// ════════════════════════════════════════//
// ————————> MAX INTRADAY LOSS <————————— //
// ════════════════════════════════════════//
// strategy.risk.max_intraday_loss(type = strategy.cash, value = risk)