该策略通过扩大移动均线的间隔来识别趋势,在趋势向上时逐步建仓做多,通过不断加仓的方式来获得更高的收益。与此同时,策略还设置了止损点来控制风险。
设置两条均线EMA1和EMA2,它们的周期不太一样,例如EMA1为55周期,EMA2为89周期。这样可以形成较大的均线区间。
当价格上涨突破均线时,认为趋势开始,这个时候可以逐步买入。
买入后,如果价格继续上涨,可以继续加仓,每次加仓仓位翻倍。通过加仓获得更高收益。
设置止损点,如果价格跌破均线,则止损退出。止损点根据进场价格浮动上移。
这样就实现了在趋势中的加仓以获得更高收益,同时设置止损来控制风险。
扩大均线区间,可以更清晰判断趋势方向。
逐步加仓可以获得更高的盈利。
动态调整止损点,既可以享受趋势带来的收益,也可以及时止损。
适用于品种的长线趋势交易。
需要正确判断趋势方向,如果判断错误,亏损会加速扩大。
加仓需要计算好资金使用比例,加仓过于激进可能面临追加保证金的风险。
止损点设置需要合理,过于宽松可能导致亏损扩大,过于激进可能导致频繁止损。
需要关注交易品种的流动性,流动性差的品种不适合较大仓位的交易。
可以加入更多指标判断来确认趋势,例如RSI,KD等,避免假突破。
可以根据具体品种特点优化均线的周期参数,找到最合适的周期组合。
可以研究不同的加仓方式,适当控制单笔仓位大小,降低风险。
可以设置盈利后部分平仓的方式,来锁定部分利润,降低回撤。
可以根据品种特点选择最佳的止损位置,既要设置止损,也要考虑止损被触发的概率。
该策略通过扩大均线区间来识别趋势,趋势出现后采用加仓方式追涨,并设置浮动止损来控制风险,能够在趋势中获得较好的收益。但是策略也存在一定风险,需要进一步优化判断指标、加仓方式、止损位置等参数,使策略更稳健和适合不同品种。
/*backtest
start: 2023-10-02 00:00:00
end: 2023-11-01 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
// strategy(title='Super Simple Martingale Buying', shorttitle="Martingale v5",overlay=true, pyramiding = 10, initial_capital=1, calc_on_order_fills = true)
// Revision: 1
// Author: @ToS_MavericK
// === INPUT SMA ===
EMA1 = input(55)
EMA2 = input(89)
Amount = input(defval = 6, type = float, title = "Max open Orders", minval = 1, step = 1)
Multiplier = input(defval = 2 , type = float, title = "Multiplier", minval = 1, step = 0.1)
BuyLvl = input(defval = 1, type = float, title = "BuyLvl", minval = 0, step = 0.1)
Profit = input(3)
DoubleUpLimit = input(2)
// === INPUT BACKTEST RANGE ===
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromYear = input(defval = 2019, title = "From Year", minval = 2012)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToYear = input(defval = 2020, title = "To Year", minval = 2012)
RSIFilter = input(false)
minRSI = input(defval = 35, title = "RSI", minval = 1, step = 1)
lengthRSI = input(14, minval=1)
src = input(close, title="RSI Source")
StochRSIFilter = input(false)
lengthStoch = input(14, minval=1)
smoothK = input(3, minval=1)
smoothD = input(3, minval=1)
rsi = rsi(src, lengthRSI)
k = sma(stoch(rsi, rsi, rsi, lengthStoch), smoothK)
d = sma(k, smoothD)
// === FUNCTION EXAMPLE ===
start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window
window() => true // create function "within window of time"
// === SERIES SETUP ===
vEMA1 = ema(close, EMA1)
vEMA2 = ema(close, EMA2)
buy = (rsi < minRSI or RSIFilter == false) and ((crossover(k,d) and k < 20) or StochRSIFilter == false) and ((close < vEMA1 * (1 - BuyLvl/100) and vEMA1 < vEMA2) or (close < vEMA2 * (1 - BuyLvl/100) and vEMA2 < vEMA1))
BuyPrice = strategy.position_avg_price * (1 - DoubleUpLimit/50)
SellPrice = strategy.position_avg_price * (1 + Profit/(100*strategy.opentrades))
// Exit first, due to the limit orders, which can be hit on the same bar
strategy.exit("EMA1", limit = SellPrice, when = window() and strategy.opentrades > 0)
strategy.close("EMA1",when = time > finish) // close positions at the end of the specified time period
// Normal entry
strategy.entry("EMA1", strategy.long,qty = strategy.equity/ (close * pow(2,Amount - 1)), when = window() and strategy.opentrades == 0 and buy)
// Martingale
strategy.entry("EMA1", strategy.long,qty = strategy.position_size, limit = strategy.position_avg_price * (1 - DoubleUpLimit/100), when = window() and strategy.opentrades == 1)
strategy.entry("EMA1", strategy.long,qty = strategy.position_size, limit = BuyPrice, when = window() and strategy.opentrades > 1 and strategy.opentrades < Amount)
plot(vEMA1, title = 'EMA1', color = orange, linewidth = 2, style = line)
plot(vEMA2, title = 'EMA2', color = yellow, linewidth = 2, style = line)
plot(BuyPrice[1], title = 'BuyPrice', color = red, linewidth = 2, style = line)
plot(SellPrice[1], title = 'SellPrice', color = green, linewidth = 2, style = line)