
A estratégia de dinâmica de retorno médio é uma estratégia de negociação de tendências que acompanha a média de preços de curto prazo. Combina o indicador de retorno médio e o indicador de dinâmica para determinar a tendência de médio prazo do mercado.
A estratégia primeiro calcula a linha de regresso médio e o desvio padrão do preço. Em seguida, em combinação com os parâmetros de limite superior e inferior, os valores de limite definidos são calculados para determinar se o preço excede o desvio padrão de um limite. Se for excedido, um sinal de negociação é gerado.
Para um sinal multi-cabeça, é necessário um diferencial padrão de preço abaixo da linha de retorno do valor médio, um preço de fechamento abaixo da média SMA do ciclo LENGTH e acima da média SMA de TREND, para realizar uma posição aberta em várias direções. A condição de parada é a média SMA do ciclo LENGTH sobre o preço.
Para um sinal de cabeça vazia, o preço deve ser superior a uma diferença padrão da linha de retorno do valor médio, o preço de fechamento acima da média SMA do ciclo LENGTH e abaixo da média SMA de TREND, para que essas três condições sejam preenchidas. A condição de posição livre é a média SMA do ciclo LENGTH abaixo do preço.
A estratégia combina o Percent Profit Target com o Percent Stop Loss para gerenciar o Stop Loss.
O modo de saída pode ser o quebra de uma média móvel ou a quebra de uma regressão linear.
A combinação de negociações bilaterais multi-marcas, filtragem de tendências e stop loss permite o julgamento e o acompanhamento da tendência de médio prazo do mercado.
O indicador de regressão ao valor médio é eficaz para determinar se o preço está desviado do centro de valor
Indicadores de dinâmica SMA filtram o ruído do mercado de curto prazo
O mercado de criptomoedas está em alta, e o mercado de criptomoedas está em alta, e o mercado de criptomoedas está em alta.
O Stop Loss Mechanism é um mecanismo de controle de risco eficaz.
Métodos de saída opcionais, com flexibilidade para adaptar-se ao mercado
Estratégias de negociação de tendências completas, para uma melhor compreensão das tendências de médio prazo
O indicador de regressão de valor médio é sensível à configuração de parâmetros, e a configuração de um limite inadequado pode levar a falsos sinais
Em situações de grandes tremores, pode ocorrer uma perda excessiva de frequência.
A frequência de negociação pode ser excessiva durante a tendência de choque, aumentando os custos de negociação e o risco de deslizamento
O controle de ponto de deslizamento pode ser desejável quando a variedade de transação não é tão líquida.
O risco de transações bilaterais multinacionais exige uma gestão prudente dos fundos
Estes riscos podem ser controlados por meio de métodos como otimização de parâmetros, ajustamento de stop loss e gestão de fundos.
Parâmetros de regressão de média optimizada e configuração de indicadores de dinâmica para que sejam mais adequados às características de diferentes variedades
Aumentar os indicadores de avaliação de tendências e melhorar a capacidade de identificação de tendências
Optimizar a estratégia de parada de perdas para que seja mais adaptável às grandes flutuações do mercado
Adição de módulo de gerenciamento de posições para ajustar o tamanho das posições de acordo com as condições do mercado
Adição de mais módulos de controle de vento, como controle de retração máxima, controle de curva de valor líquido, etc.
Considerar métodos de aprendizado de máquina para otimização automática de parâmetros de estratégia
Em suma, a estratégia de valor de regressão dinâmica capta a tendência de retorno de valor a médio prazo por meio de um design de indicadores simples e eficazes. A estratégia tem uma forte adaptabilidade e universalidade, mas também existe um certo risco.
/*backtest
start: 2023-10-15 00:00:00
end: 2023-11-14 00:00:00
period: 1h
basePeriod: 15m
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/
// © GlobalMarketSignals
//@version=4
strategy("GMS: Mean Reversion Strategy", overlay=true)
LongShort = input(title="Long Only or Short Only or Both?", type=input.string, defval="Both", options=["Both", "Long Only", "Short Only"])
Lookback = input(title="Length", type=input.integer, defval=10, minval=0)
LThr1 = input(title="Upper threshold", type=input.float, defval=1, minval=0)
LThr = input(title="Lower threshold", type=input.float, defval=-1, maxval=0)
src = input(title="Source", type=input.source, defval=close)
LongShort2 = input(title="Linear Regression Exit or Moving Average Exit?", type=input.string, defval="MA", options=["LR", "MA"])
SMAlenL = input(title="MA/LR Exit Length", type = input.integer ,defval=10)
SMALen2 = input(title="Trend SMA Length", type = input.integer ,defval=200)
AboveBelow = input(title="Above or Below Trend SMA?", type=input.string, defval="Above", options=["Above", "Below", "Don't Include"])
PTbutton = input(title="Profit Target On/Off", type=input.bool, defval=true)
ProfitTarget = input(title="Profit Target %", type=input.float, defval=1, step=0.1, minval=0)
SLbutton = input(title="Stop Loss On/Off", type=input.bool, defval=true)
StopLoss = input(title="Stop Loss %", type=input.float, defval=-1, step=0.1, maxval=0)
x = (src-linreg(src,Lookback,0))/(stdev(src,Lookback))
plot(linreg(src,Lookback,0))
//PROFIT TARGET & STOPLOSS
if PTbutton == true and SLbutton == true
strategy.exit("EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick), loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
if PTbutton == true and SLbutton == false
strategy.exit("PT EXIT", profit=((close*(ProfitTarget*0.01))/syminfo.mintick))
else
if PTbutton == false and SLbutton == true
strategy.exit("SL EXIT", loss=((close*(StopLoss*-0.01))/syminfo.mintick))
else
strategy.cancel("PT EXIT")
////////////////////////
//MOVING AVERAGE EXIT//
//////////////////////
if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
strategy.close("LONG", when = close>sma(close,SMAlenL))
if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
strategy.close("LONG", when = close>sma(close,SMAlenL))
if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
strategy.close("LONG", when = close>sma(close,SMAlenL))
///////
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
strategy.close("SHORT", when = close<sma(close,SMAlenL))
if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close<sma(close,SMALen2))
strategy.close("SHORT", when = close<sma(close,SMAlenL))
if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) )
strategy.close("SHORT", when = close<sma(close,SMAlenL))
//////
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close>sma(close,SMALen2))
strategy.close("LONG", when = close>sma(close,SMAlenL))
if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) and close<sma(close,SMALen2))
strategy.close("LONG", when = close>sma(close,SMAlenL))
if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
strategy.entry("LONG", true, when = x<LThr and close<sma(close,SMAlenL) )
strategy.close("LONG", when = close>sma(close,SMAlenL))
///////
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close>sma(close,SMALen2))
strategy.close("SHORT", when = close<sma(close,SMAlenL))
if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) and close<sma(close,SMALen2))
strategy.close("SHORT", when = close<sma(close,SMAlenL))
if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="MA"
strategy.entry("SHORT", false, when = x>LThr1 and close>sma(close,SMAlenL) )
strategy.close("SHORT", when = close<sma(close,SMAlenL))
/////////////////
//LIN REG EXIT//
///////////////
if LongShort=="Long Only" and AboveBelow=="Above" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
if LongShort=="Long Only" and AboveBelow=="Below" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
if LongShort=="Long Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
///////
if LongShort=="Short Only" and AboveBelow=="Above" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
if LongShort=="Short Only" and AboveBelow=="Below" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
if LongShort=="Short Only" and AboveBelow=="Don't Include" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) )
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
//////
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
strategy.entry("LONG", true, when = x<LThr and close<linreg(close,SMAlenL,0) )
strategy.close("LONG", when = close>linreg(close,SMAlenL,0))
///////
if LongShort=="Both" and AboveBelow=="Above" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close>sma(close,SMALen2))
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
if LongShort=="Both" and AboveBelow=="Below" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) and close<sma(close,SMALen2))
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))
if LongShort=="Both" and AboveBelow=="Don't Include" and LongShort2 =="LR"
strategy.entry("SHORT", false, when = x>LThr1 and close>linreg(close,SMAlenL,0) )
strategy.close("SHORT", when = close<linreg(close,SMAlenL,0))