Subversion Repositories Integrator Subversion

Rev

Rev 767 | Rev 773 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 767 Rev 770
Line 33... Line 33...
33
33
34
        for (PadraoGatilho p : padroes) {
34
        for (PadraoGatilho p : padroes) {
35
            if (p == null) continue;
35
            if (p == null) continue;
36
36
37
            Candle ref = p.getReferencia();
37
            Candle ref = p.getReferencia();
-
 
38
            Candle g1  = p.getGatilho1();
38
            Candle g2  = p.getGatilho2();
39
            Candle g2  = p.getGatilho2();
39
            Candle g3  = p.getGatilho3();
40
            Candle g3  = p.getGatilho3();
40
41
41
            // só interessa padrão completo até G3
42
            // só interessa padrão completo até G3
42
            if (ref == null || g2 == null || g3 == null) {
43
            if (ref == null || g2 == null || g3 == null) {
43
                continue;
44
                continue;
44
            }
45
            }
45
46
46
            if (ref.isCandleComprador()) {
47
            if (ref.isCandleComprador()) {
47
                // GR comprador -> operação VENDIDA
48
                // GR comprador -> operação VENDIDA
48
                SinalTradeGatilho3 sinal = montarSinalVenda(ref, g2, g3, p);
-
 
-
 
49
                SinalTradeGatilho3 sinal = montarSinalVenda(ref, g1, g2, g3, p);
49
                if (sinal != null) {
50
                if (sinal != null) {
50
                    sinais.add(sinal);
51
                    sinais.add(sinal);
51
                }
52
                }
52
            } else if (ref.isCandleVendedor()) {
53
            } else if (ref.isCandleVendedor()) {
53
                // GR vendedor -> operação COMPRADA
54
                // GR vendedor -> operação COMPRADA
54
                SinalTradeGatilho3 sinal = montarSinalCompra(ref, g2, g3, p);
-
 
-
 
55
                SinalTradeGatilho3 sinal = montarSinalCompra(ref, g1, g2, g3, p);
55
                if (sinal != null) {
56
                if (sinal != null) {
56
                    sinais.add(sinal);
57
                    sinais.add(sinal);
57
                }
58
                }
58
            }
59
            }
59
        }
60
        }
Line 65... Line 66...
65
     * Monta sinal de VENDA (referência comprador):
66
     * Monta sinal de VENDA (referência comprador):
66
     *  - Fibo preço com base nos candles G2 e G3.
67
     *  - Fibo preço com base nos candles G2 e G3.
67
     *  - 0% no topo de G3
68
     *  - 0% no topo de G3
68
     *  - 100% no fundo de G2
69
     *  - 100% no fundo de G2
69
     */
70
     */
70
    private SinalTradeGatilho3 montarSinalVenda(Candle ref, Candle g2, Candle g3, PadraoGatilho padrao) {
-
 
-
 
71
    private SinalTradeGatilho3 montarSinalVenda(Candle ref, Candle g1, Candle g2, Candle g3, PadraoGatilho padrao) {
71
        BigDecimal topoG3   = g3.getMaxima();
72
        BigDecimal topoG3   = g3.getMaxima();
72
        BigDecimal fundoG2  = g2.getMinima();
73
        BigDecimal fundoG2  = g2.getMinima();
73
74
74
        // Garantia mínima de geometria: topo > fundo
75
        // Garantia mínima de geometria: topo > fundo
75
        if (BigDecimalUtils.ehMenorOuIgualQue(topoG3, fundoG2)) {
76
        if (BigDecimalUtils.ehMenorOuIgualQue(topoG3, fundoG2)) {
Line 79... Line 80...
79
        // Orientação: 0% = topo (G3), 100% = fundo (G2)
80
        // Orientação: 0% = topo (G3), 100% = fundo (G2)
80
        BigDecimal base0   = topoG3;
81
        BigDecimal base0   = topoG3;
81
        BigDecimal base100 = fundoG2;
82
        BigDecimal base100 = fundoG2;
82
83
83
        BigDecimal entrada1 = nivelFibo(base0, base100, 50.0);    // 50%
84
        BigDecimal entrada1 = nivelFibo(base0, base100, 50.0);    // 50%
84
        BigDecimal entrada2 = nivelFibo(base0, base100, 75.0);    // 75%
-
 
-
 
85
        BigDecimal entrada2 = nivelFibo(base0, base100, 25.0);    // 25%
85
        BigDecimal alvo1    = nivelFibo(base0, base100, 123.6);   // 123,6%
86
        BigDecimal alvo1    = nivelFibo(base0, base100, 123.6);   // 123,6%
86
        BigDecimal alvo2    = nivelFibo(base0, base100, 300.0);   // 300%
87
        BigDecimal alvo2    = nivelFibo(base0, base100, 300.0);   // 300%
87
        BigDecimal stopFib  = nivelFibo(base0, base100, -100.0);  // -100%
88
        BigDecimal stopFib  = nivelFibo(base0, base100, -100.0);  // -100%
88
89
89
        // Stop alternativo: 25% acima do último fundo relevante (aqui uso fundo de G2)
90
        // Stop alternativo: 25% acima do último fundo relevante (aqui uso fundo de G2)
Line 92... Line 93...
92
        );
93
        );
93
94
94
        SinalTradeGatilho3 s = new SinalTradeGatilho3();
95
        SinalTradeGatilho3 s = new SinalTradeGatilho3();
95
        s.setPadrao(padrao);
96
        s.setPadrao(padrao);
96
        s.setReferencia(ref);
97
        s.setReferencia(ref);
-
 
98
        s.setGatilho1(g1);
97
        s.setGatilho2(g2);
99
        s.setGatilho2(g2);
98
        s.setGatilho3(g3);
100
        s.setGatilho3(g3);
99
101
100
        s.setTipoOperacao(TipoOperacao.VENDA);
102
        s.setTipoOperacao(TipoOperacao.VENDA);
101
        s.setContratosTotais(CONTRATOS_TOTAIS);
103
        s.setContratosTotais(CONTRATOS_TOTAIS);
Line 116... Line 118...
116
     * Monta sinal de COMPRA (referência vendedor):
118
     * Monta sinal de COMPRA (referência vendedor):
117
     *  - Fibo preço com base nos candles G2 e G3.
119
     *  - Fibo preço com base nos candles G2 e G3.
118
     *  - 0% no fundo de G3
120
     *  - 0% no fundo de G3
119
     *  - 100% no topo de G2
121
     *  - 100% no topo de G2
120
     */
122
     */
121
    private SinalTradeGatilho3 montarSinalCompra(Candle ref, Candle g2, Candle g3, PadraoGatilho padrao) {
-
 
-
 
123
    private SinalTradeGatilho3 montarSinalCompra(Candle ref, Candle g1, Candle g2, Candle g3, PadraoGatilho padrao) {
122
        BigDecimal topoG2   = g2.getMaxima();
124
        BigDecimal topoG2   = g2.getMaxima();
123
        BigDecimal fundoG3  = g3.getMinima();
125
        BigDecimal fundoG3  = g3.getMinima();
124
126
125
        if (BigDecimalUtils.ehMenorOuIgualQue(topoG2, fundoG3)) {
127
        if (BigDecimalUtils.ehMenorOuIgualQue(topoG2, fundoG3)) {
126
            return null;
128
            return null;
Line 129... Line 131...
129
        // Orientação: 0% = fundo (G3), 100% = topo (G2)
131
        // Orientação: 0% = fundo (G3), 100% = topo (G2)
130
        BigDecimal base0   = fundoG3;
132
        BigDecimal base0   = fundoG3;
131
        BigDecimal base100 = topoG2;
133
        BigDecimal base100 = topoG2;
132
134
133
        BigDecimal entrada1 = nivelFibo(base0, base100, 50.0);    // 50%
135
        BigDecimal entrada1 = nivelFibo(base0, base100, 50.0);    // 50%
134
        BigDecimal entrada2 = nivelFibo(base0, base100, 75.0);    // 75%
-
 
-
 
136
        BigDecimal entrada2 = nivelFibo(base0, base100, 25.0);    // 25%
135
        BigDecimal alvo1    = nivelFibo(base0, base100, 123.6);   // 123,6%
137
        BigDecimal alvo1    = nivelFibo(base0, base100, 123.6);   // 123,6%
136
        BigDecimal alvo2    = nivelFibo(base0, base100, 300.0);   // 300%
138
        BigDecimal alvo2    = nivelFibo(base0, base100, 300.0);   // 300%
137
        BigDecimal stopFib  = nivelFibo(base0, base100, -100.0);  // -100%
139
        BigDecimal stopFib  = nivelFibo(base0, base100, -100.0);  // -100%
138
140
139
        // Stop alternativo: 25% abaixo do último topo relevante (aqui uso topo de G2)
141
        // Stop alternativo: 25% abaixo do último topo relevante (aqui uso topo de G2)
Line 142... Line 144...
142
        );
144
        );
143
145
144
        SinalTradeGatilho3 s = new SinalTradeGatilho3();
146
        SinalTradeGatilho3 s = new SinalTradeGatilho3();
145
        s.setPadrao(padrao);
147
        s.setPadrao(padrao);
146
        s.setReferencia(ref);
148
        s.setReferencia(ref);
-
 
149
        s.setGatilho1(g1);
147
        s.setGatilho2(g2);
150
        s.setGatilho2(g2);
148
        s.setGatilho3(g3);
151
        s.setGatilho3(g3);
149
152
150
        s.setTipoOperacao(TipoOperacao.COMPRA);
153
        s.setTipoOperacao(TipoOperacao.COMPRA);
151
        s.setContratosTotais(CONTRATOS_TOTAIS);
154
        s.setContratosTotais(CONTRATOS_TOTAIS);