
伽利略均线交叉策略是一种基于移动平均线的交易策略。该策略通过计算一定周期的指数移动平均线,并与价格进行交叉比较,产生交易信号。当价格从上方向下跌破均线时,产生卖出信号;当价格从下方向上突破均线时,产生买入信号。该策略名称来源于伽利略·伽利莱
伽利略均线交叉策略的核心是指数移动平均线(EMA)。EMA是一种趋向于给予最近价格更大权重的移动平均线算法。它的计算公式是:
EMA今天 = (收盘价今天×平滑常数) + (EMA昨天×(1-平滑常数))
其中,平滑常数α=(2/(周期数+1))。
该策略通过用户输入的周期长度,实时计算EMA值。然后将价格与EMA进行比较,判断二者的交叉情况,作为买入和卖出信号:
当价格从上方向下跌破EMA时,产生卖出信号,进行短线操作。
当价格从下方向上突破EMA时,产生买入信号,进行做多操作。
该策略同时绘制EMA线,以及标记出买卖信号的箭头。
伽利略均线交叉策略具有以下优势:
伽利略均线交叉策略也存在以下风险:
伽利略均线交叉策略可以从以下几个方向进行优化:
结合其他指标,构建复合策略,避免假信号,提高稳定性。例如加入成交量,趋势指标等。
增加止损策略,设置移动止损或百分比止损,控制单笔损失。
测试EMA不同参数的效果,选择最佳参数组合。也可以测试其他类型的移动平均线。
评估加入重新进场机制,在价格反转后再次进场,提高盈利率。
伽利略均线交叉策略是一种简单实用的交易策略,思路清晰,易于操作,适合量化交易的初学者。在不断优化和改进下,相信其效果会越来越好,值得推荐。
/*backtest
start: 2022-12-11 00:00:00
end: 2023-12-17 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/
// © armigoldman
//@version=3
strategy(title="Galileo Galilei", shorttitle="Galileo Galilei", overlay=true, initial_capital = 100000, default_qty_type=strategy.cash, default_qty_value = 100000)
len = input(11, minval=1, title="Length")
src = input(open, title="Source")
out = ema(src, len)
plot(out, title="EMA", color=yellow)
//last8h = highest(close, 8)
//lastl8 = lowest(close, 8)
//plot(last8h, color=red, linewidth=2)
//plot(lastl8, color=green, linewidth=2)
////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
// From Date Inputs
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=2020, title="From Year", minval=1970)
// To Date Inputs
toDay = input(defval=1, title="To Day", minval=1, maxval=31)
toMonth = input(defval=12, title="To Month", minval=1, maxval=12)
toYear = input(defval=2021, title="To Year", minval=1970)
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true
bearish = cross(close, out) == 1 and close[1] > close
bullish = cross(close, out) == 1 and close[1] < close
plotshape(bearish, color=white, style=shape.arrowdown, text="BEAR", location=location.abovebar)
plotshape(bullish, color=white, style=shape.arrowup, text="BULL", location=location.belowbar)
buy = if cross(close, out) == 1 and close[1] < close
strategy.entry("BUY", strategy.long, when=time_cond)
//strategy.close_all(when=bearish)
// strategy.exit("exit", "Long", profit =, loss = 35)
sell = if cross(close, out) == 1 and close[1] > close
strategy.entry("SELL", strategy.short, when=time_cond)
//sell = if bearish
//strategy.close_all(when=bullish)
// strategy.exit("exit", "Long", profit = bullish, loss = 100)
profit = strategy.netprofit
if not time_cond
strategy.close_all()
//plotshape(true, style=shape.triangleup, location=location.abovebar)