
This is a quantitative trading strategy system based on moving average crossover and volume analysis. The strategy makes trading decisions through crossover signals of various types of moving averages (including EMA, SMA, and WMA), combined with volume indicators. The system supports flexible configuration of moving average types and parameters, while introducing volume analysis as a trade confirmation condition to improve reliability.
The strategy uses a dual moving average crossover system as the core trading signal, combined with volume analysis as auxiliary judgment: 1. Uses two moving averages (MA1 and MA2) of different periods, supporting free switching between SMA, EMA, and WMA. 2. Introduces Volume SMA as a volume reference standard. 3. Uses 200-period EMA as a long-term trend judgment benchmark. 4. Generates long signals when the fast MA crosses above the slow MA with volume above its average. 5. Generates short signals when the fast MA crosses below the slow MA with volume above its average.
This is a quantitative trading strategy combining classical technical analysis theories through moving average crossover and volume analysis. The strategy design is reasonable with strong practicality and scalability. Through parameter optimization and module enhancement, the strategy’s stability and profitability can be further improved. It’s recommended to conduct thorough backtesting before live trading and adjust parameters according to specific trading instrument characteristics.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Cruzamento de Médias com Volume ☾︎ 𝔇𝔞𝔯𝔎 ✞︎ 𝔗𝔯𝔞𝔡𝔢𝔯 ☽︎", overlay=true)
// Criação de opções no editor para selecionar o tipo de média móvel
maType1 = input.string(title="Tipo de Média Móvel 1", defval="EMA", options=["SMA", "EMA", "WMA"])
maType2 = input.string(title="Tipo de Média Móvel 2", defval="EMA", options=["SMA", "EMA", "WMA"])
// Função para selecionar a média móvel de acordo com o tipo escolhido
getMovingAverage(maType, src, length) =>
if maType == "SMA"
ta.sma(src, length)
else if maType == "EMA"
ta.ema(src, length)
else if maType == "WMA"
ta.wma(src, length)
else
na
// Parâmetros para o cálculo das médias móveis
length1 = input.int(9, title="Período da Média 1")
length2 = input.int(21, title="Período da Média 2")
// Cálculo das médias móveis escolhidas
ma1 = getMovingAverage(maType1, close, length1)
ma2 = getMovingAverage(maType2, close, length2)
// Parâmetro editável para o período da média de volume
volLength = input.int(20, title="Período da Média de Volume")
// Cálculo da média móvel do volume com período ajustável
volSMA = ta.sma(volume, volLength) // Média móvel simples do volume
// Cálculo da EMA de 200 períodos para visualizar a tendência primária
ema200 = ta.ema(close, 200)
// Condições para compra: ma1 cruza acima da ma2 + Volume acima da média de volume ajustável
longCondition = ta.crossover(ma1, ma2) and volume > volSMA
// Condições para venda: ma1 cruza abaixo da ma2 + Volume acima da média de volume ajustável
shortCondition = ta.crossunder(ma1, ma2) and volume > volSMA
// Executa a operação de compra
if (longCondition)
strategy.entry("Compra", strategy.long)
// Executa a operação de venda
if (shortCondition)
strategy.entry("Venda", strategy.short)
// Plotando as médias móveis no gráfico de preços
plot(ma1, color=color.green, title="Média Móvel 1", linewidth=2)
plot(ma2, color=color.red, title="Média Móvel 2", linewidth=2)
// Plotando a EMA de 200 períodos para visualização da tendência de longo prazo
plot(ema200, color=color.orange, title="EMA 200", linewidth=2)
// Plotando a média de volume para visualização no painel inferior
plot(volSMA, color=color.blue, title="Média de Volume", linewidth=2)