
Esta estrategia se basa en una sencilla estrategia de medias móviles, que puede tener un buen efecto en diferentes pares de divisas. Traza una media de apertura y una media de cierre, y decide establecer o abandonar una posición cuando las dos líneas se cruzan. Su principio es establecer una posición cuando el precio de cierre promedio aumenta, lo que puede indicar que el precio futuro aumentará.
Esta estrategia comienza con la selección de los tipos de promedios móviles según la configuración, que incluyen EMA, SMA, RMA, WMA y VWMA. Luego se establece el ciclo para el cálculo de los promedios móviles, generalmente de 10 a 250 líneas K. La elección de diferentes tipos de promedios móviles y el número de ciclos puede obtener un efecto completamente diferente según los diferentes pares de monedas.
La lógica de negociación de esta estrategia es la siguiente:
Cuando se establece una posición se considera un presagio de aumento de precios, y cuando se cierra una posición se considera un presagio de caída de precios.
La estrategia tiene las siguientes ventajas:
La estrategia también tiene sus riesgos:
La respuesta y el camino a seguir:
Esta estrategia es simple en su lógica general, y utiliza un indicador de promedio móvil para determinar la tendencia de los precios y los puntos de inflexión. Puede obtener muy buenos resultados mediante el ajuste de los parámetros, y es una estrategia de seguimiento de tendencias efectiva que vale la pena perfeccionar y aplicar aún más. Pero también debe tenerse en cuenta el control de los riesgos y la selección de los pares y parámetros adecuados para que tengan la máxima eficacia.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//Author @divonn1994
initial_balance = 100
strategy(title='Close v Open Moving Averages Strategy', shorttitle = 'Close v Open', overlay=true, pyramiding=0, default_qty_value=100, default_qty_type=strategy.percent_of_equity, precision=7, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent, initial_capital=initial_balance)
//Input for number of bars for moving average, Switch to choose moving average type, Display Options and Time Frame of trading----------------------------------------------------------------
bars = input.int(66, "Moving average length (number of bars)", minval=1, group='Strategy') //66 bars and VWMA for BTCUSD on 12 Hours.. 35 bars and VWMA for BTCUSD on 1 Day
strategy = input.string("VWMA", "Moving Average type", options = ["EMA", "SMA", "RMA", "WMA", "VWMA"], group='Strategy')
redOn = input.string("On", "Red Background Color On/Off", options = ["On", "Off"], group='Display')
greenOn = input.string("On", "Green Background Color On/Off", options = ["On", "Off"], group='Display')
maOn = input.string("On", "Moving Average Plot On/Off", options = ["On", "Off"], group='Display')
startMonth = input.int(title='Start Month 1-12 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=12, group='Beginning of Strategy')
startDate = input.int(title='Start Date 1-31 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=31, group='Beginning of Strategy')
startYear = input.int(title='Start Year 2000-2100 (set any start time to 0 for furthest date)', defval=2011, minval=2000, maxval=2100, group='Beginning of Strategy')
endMonth = input.int(title='End Month 1-12 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=12, group='End of Strategy')
endDate = input.int(title='End Date 1-31 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=31, group='End of Strategy')
endYear = input.int(title='End Year 2000-2100 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=2100, group='End of Strategy')
//Strategy Calculations-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
inDateRange = true
maMomentum = switch strategy
"EMA" => (ta.ema(close, bars) > ta.ema(open, bars)) ? 1 : -1
"SMA" => (ta.sma(close, bars) > ta.sma(open, bars)) ? 1 : -1
"RMA" => (ta.rma(close, bars) > ta.rma(open, bars)) ? 1 : -1
"WMA" => (ta.wma(close, bars) > ta.wma(open, bars)) ? 1 : -1
"VWMA" => (ta.vwma(close, bars) > ta.vwma(open, bars)) ? 1 : -1
=>
runtime.error("No matching MA type found.")
float(na)
openMA = switch strategy
"EMA" => ta.ema(open, bars)
"SMA" => ta.sma(open, bars)
"RMA" => ta.rma(open, bars)
"WMA" => ta.wma(open, bars)
"VWMA" => ta.vwma(open, bars)
=>
runtime.error("No matching MA type found.")
float(na)
closeMA = switch strategy
"EMA" => ta.ema(close, bars)
"SMA" => ta.sma(close, bars)
"RMA" => ta.rma(close, bars)
"WMA" => ta.wma(close, bars)
"VWMA" => ta.vwma(close, bars)
=>
runtime.error("No matching MA type found.")
float(na)
//Enter or Exit Positions--------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ta.crossover(maMomentum, 0)
if inDateRange
strategy.entry('long', strategy.long, comment='long')
if ta.crossunder(maMomentum, 0)
if inDateRange
strategy.close('long')
//Plot Strategy Behavior---------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot(series = maOn == "On" ? openMA : na, title = "Open moving Average", color = color.new(color.purple,0), linewidth=3, offset=1)
plot(series = maOn == "On" ? closeMA : na, title = "Close Moving Average", color = color.new(color.white,0), linewidth=2, offset=1)
bgcolor(color = inDateRange and (greenOn == "On") and maMomentum > 0 ? color.new(color.green,75) : inDateRange and (redOn == "On") and maMomentum <= 0 ? color.new(color.red,75) : na, offset=1)