Estratégia de negociação quantitativa multifator

Autora:ChaoZhang, Data: 2023-12-27 15:46:27
Tags:

img

Resumo

Esta estratégia combina a estratégia de reversão e a estratégia de linha psicológica para formar uma estratégia quantitativa de negociação multifator.

Princípio

123 Estratégia de reversão

A estratégia de reversão 123 julga que, se o preço de fechamento do dia subir em comparação com o dia anterior, e a linha lenta K estiver abaixo de 50, vá longo; se cair, e a linha rápida K estiver acima de 50, vá curto.

Estratégia de linha psicológica

A estratégia de linha psicológica conta a proporção de subidas e quedas em um determinado ciclo. Se a subida for maior que 50%, indica que os touros controlam o mercado; se a subida for menor que 50%, indica que os ursos controlam o mercado. Faça julgamentos sobre a psicologia do mercado com base na proporção de subidas e quedas.

Esta estratégia combina os sinais das duas estratégias acima: abrir posições quando as duas estratégias dão sinais na mesma direção e fechar posições quando dão sinais em direções diferentes.

Vantagens

A estratégia combina múltiplos fatores e pode fazer julgamentos mais precisos sobre as tendências do mercado, evitando julgamentos errôneos causados por um único indicador técnico.

Riscos e soluções

A definição de parâmetros para cada fator na estratégia terá um impacto maior no desempenho da estratégia. Combinações irracionais de parâmetros podem reduzir muito a eficácia da estratégia. Além disso, mudanças drásticas nas tendências também podem fazer com que a estratégia falhe. Para reduzir os riscos, precisamos testar várias condições de mercado para encontrar as configurações ideais de parâmetros; também controlar o tamanho da posição para garantir que uma única perda não seja muito grande.

Orientações de otimização

Na base existente, podemos continuar a adicionar outros fatores de julgamento, como volatilidade e volume para formar uma lógica de estratégia mais tridimensional; ou adicionar algoritmos de aprendizado de máquina para alcançar otimização adaptativa automática de parâmetros.

Resumo

Esta estratégia considera de forma abrangente múltiplos fatores, como padrões técnicos e psicologia do mercado. A validação entre diferentes fatores garante a validade dos sinais. Ao mesmo tempo, deixa amplo espaço para otimização e espera-se alcançar um desempenho superior. Esta é uma estratégia quantitativa de alta qualidade que vale a pena rastreamento, acumulação e otimização a longo prazo.


/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 30/04/2021
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This System was created from the Book "How I Tripled My Money In The 
// Futures Market" by Ulf Jensen, Page 183. This is reverse type of strategies.
// The strategy buys at market, if close price is higher than the previous close 
// during 2 days and the meaning of 9-days Stochastic Slow Oscillator is lower than 50. 
// The strategy sells at market, if close price is lower than the previous close price 
// during 2 days and the meaning of 9-days Stochastic Fast Oscillator is higher than 50.
//
// Second strategy
// Psychological line (PSY), as an indicator, is the ratio of the number of 
// rising periods over the total number of periods. It reflects the buying 
// power in relation to the selling power.
// If PSY is above 50%, it indicates that buyers are in control. Likewise, 
// if it is below 50%, it indicates the sellers are in control. If the PSY 
// moves along the 50% area, it indicates balance between the buyers and 
// sellers and therefore there is no direction movement for the market.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
Reversal123(Length, KSmoothing, DLength, Level) =>
    vFast = sma(stoch(close, high, low, Length), KSmoothing) 
    vSlow = sma(vFast, DLength)
    pos = 0.0
    pos := iff(close[2] < close[1] and close > close[1] and vFast < vSlow and vFast > Level, 1,
	         iff(close[2] > close[1] and close < close[1] and vFast > vSlow and vFast < Level, -1, nz(pos[1], 0))) 
	pos


PLine(Length) =>
    pos = 0.0
    cof = close > close[1]? 1:0
    xPSY = sum(cof,Length) / Length * 100
    pos:= iff(xPSY > 50, 1,
           iff(xPSY < 50, -1, nz(pos[1], 0))) 
    pos

strategy(title="Combo Backtest 123 Reversal & Psychological line", shorttitle="Combo", overlay = true)
line1 = input(true, "---- 123 Reversal ----")
Length = input(14, minval=1)
KSmoothing = input(1, minval=1)
DLength = input(3, minval=1)
Level = input(50, minval=1)
//-------------------------
line2 = input(true, "---- Psychological line ----")
LengthPLine = input(20, minval=1)
reverse = input(false, title="Trade reverse")
posReversal123 = Reversal123(Length, KSmoothing, DLength, Level)
posPLine = PLine(LengthPLine)
pos = iff(posReversal123 == 1 and posPLine == 1 , 1,
	   iff(posReversal123 == -1 and posPLine == -1, -1, 0)) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1 , 1, pos))	   
if (possig == 1 ) 
    strategy.entry("Long", strategy.long)
if (possig == -1 )
    strategy.entry("Short", strategy.short)	 
if (possig == 0) 
    strategy.close_all()
barcolor(possig == -1 ? #b50404: possig == 1 ? #079605 : #0536b3 )

Mais.