
El cruce de la media móvil es una señal de negociación común. La estrategia utiliza el cruce de la media móvil rápida y la media móvil lenta como una señal de negociación. En concreto, cuando la media móvil rápida atraviesa la media móvil lenta desde abajo, haga más; cuando la media móvil rápida atraviesa la media móvil lenta desde arriba, haga menos.
Esta estrategia utiliza el promedio móvil exponencial de 20 días (EMA) como promedio móvil rápido, el EMA de 50 días como promedio móvil medio y el EMA de 200 días como promedio móvil lento. Haga más cuando el EMA de 20 días y el EMA de 50 días cruzan al mismo tiempo el EMA de 200 días y haga vacío cuando el EMA de 20 días y el EMA de 50 días cruzan al mismo tiempo el EMA de 200 días.
El concepto de la estrategia de cruce de la media móvil es simple y fácil de dominar, y es una de las estrategias básicas para la transacción cuantitativa. Esta estrategia tiene un buen valor de referencia como aprendizaje inicial. Pero en la guerra real, aún se necesitan optimizaciones de parámetros para variedades y períodos, y se complementan con otros indicadores técnicos más complejos para filtrar las señales, lo que mejora la efectividad de la estrategia en la guerra real.
/*backtest
start: 2023-01-05 00:00:00
end: 2024-01-11 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/
// © rt-maax
//@version=5
strategy(title = "rt maax EMA cross strategy", shorttitle = "rt maax ema ", overlay = true, precision = 8, max_bars_back = 200, pyramiding = 0, initial_capital = 100000,
currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 100000, commission_type = "percent", commission_value = 0.27)
fastema = ta.ema (close , 50)
fema=ta.ema(close,20)
slowema= ta.ema(close,200)
price = close
// === INPUT BACKTEST RANGE ===
fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromYear = input.int(defval = 2021, title = "From Year", minval = 1970)
thruMonth = input.int(defval = 10, title = "Thru Month", minval = 1, maxval = 12)
thruDay = input.int(defval = 25, title = "Thru Day", minval = 1, maxval = 31)
thruYear = input.int(defval = 2112, title = "Thru Year", minval = 1970)
// === INPUT SHOW PLOT ===
showDate = input(defval = true, title = "Show Date Range")
// === FUNCTION EXAMPLE ===
longCondition1= ta.crossover (fema , fastema)
longcondition2= fema> slowema
longcondition3=fastema>slowema
if (longCondition1 and longcondition2 and longcondition3 )
stoploss=low*0.97
takeprofit=high*1.12
strategy.entry("Long Entry", strategy.long)
strategy.exit ("exit","long",stop=stoploss,limit=takeprofit)
shortCondition1 = ta.crossunder (fema , fastema )
shortcondition2= fastema< slowema
shortcondition3= fema< slowema
if (shortCondition1 and shortcondition2 and shortcondition3 )
stoploss=low*0.97
takeprofit=high*1.5
strategy.entry("Short Entry", strategy.short)
strategy.exit("exit","short",stop=stoploss,limit=takeprofit)