Como criar indicadores de pontos pivot e fractais VIDEO
Muitos indicadores e estratégias dependem de objetos de gráfico para apresentar informações essenciais, e o cTrader Algo fornece os métodos API necessários para desenhar tais objetos. Os pontos pivot e os fractais, em particular, são desenhados em gráficos de negociação para ajudar a identificar níveis de preço críticos e pontos de viragem.
Neste artigo e no vídeo correspondente, aprenderá a desenhar pontos pivot e fractais em gráficos.
Criar um indicador de ponto pivot Os pontos pivot são níveis de preço calculados a partir de preços anteriores. Tais pontos indicam potenciais áreas de suporte ou resistência.
Vamos criar um indicador que desenha pontos pivot diários num gráfico.
No cTrader Algo, navegue até ao separador Indicadores e clique em Novo . Digite um nome para o novo indicador e depois clique no botão Criar .
Modifique o indicador no editor de código para o tornar um indicador de sobreposição.
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
Defina e obtenha as barras diárias no método Initialize().
Bars _bars ;
protected override void Initialize ()
{
_bars = MarketData . GetBars ( TimeFrame . Daily , SymbolName );
}
Calcule os diferentes níveis de suporte e resistência conhecidos como pontos pivot. São calculados sete valores que compreendem o ponto pivot, três níveis de resistência e três níveis de suporte.
var pivot = ( _bars . HighPrices . Last ( 1 ) + _bars . LowPrices . Last ( 1 ) + _bars . ClosePrices . Last ( 1 )) / 3 ;
var r1 = 2 * pivot - _bars . LowPrices . Last ( 1 );
var s1 = 2 * pivot - _bars . HighPrices . Last ( 1 );
var r2 = pivot + _bars . HighPrices . Last ( 1 ) - _bars . LowPrices . Last ( 1 );
var s2 = pivot - _bars . HighPrices . Last ( 1 ) + _bars . LowPrices . Last ( 1 );
var r3 = _bars . HighPrices . Last ( 1 ) + 2 * ( pivot - _bars . LowPrices . Last ( 1 ));
var s3 = _bars . LowPrices . Last ( 1 ) - 2 * ( _bars . HighPrices . Last ( 1 ) - pivot );
Uma vez que os pontos pivot foram calculados, podem ser desenhados no gráfico usando linhas de tendência.
Chart . DrawTrendLine ( "pivot " , _bars . OpenTimes . LastValue , pivot , _bars . OpenTimes . LastValue . AddDays ( 1 ), pivot , Color . White );
Chart . DrawTrendLine ( "r1 " , _bars . OpenTimes . LastValue , r1 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r1 , Color . Green );
Chart . DrawTrendLine ( "r2 " , _bars . OpenTimes . LastValue , r2 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r2 , Color . Green );
Chart . DrawTrendLine ( "r3 " , _bars . OpenTimes . LastValue , r3 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r3 , Color . Green );
Chart . DrawTrendLine ( "s1 " , _bars . OpenTimes . LastValue , s1 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s1 , Color . Red );
Chart . DrawTrendLine ( "s2 " , _bars . OpenTimes . LastValue , s2 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s2 , Color . Red );
Chart . DrawTrendLine ( "s3 " , _bars . OpenTimes . LastValue , s3 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s3 , Color . Red );
Pode copiar o código completo abaixo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 using System ;
using cAlgo.API ;
using cAlgo.API.Collections ;
using cAlgo.API.Indicators ;
using cAlgo.API.Internals ;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class PivotPointsExample : Indicator
{
Bars _bars ;
protected override void Initialize ()
{
_bars = MarketData . GetBars ( TimeFrame . Daily , SymbolName );
}
public override void Calculate ( int index )
{
var pivot = ( _bars . HighPrices . Last ( 1 ) + _bars . LowPrices . Last ( 1 ) + _bars . ClosePrices . Last ( 1 )) / 3 ;
var r1 = 2 * pivot - _bars . LowPrices . Last ( 1 );
var s1 = 2 * pivot - _bars . HighPrices . Last ( 1 );
var r2 = pivot + _bars . HighPrices . Last ( 1 ) - _bars . LowPrices . Last ( 1 );
var s2 = pivot - _bars . HighPrices . Last ( 1 ) + _bars . LowPrices . Last ( 1 );
var r3 = _bars . HighPrices . Last ( 1 ) + 2 * ( pivot - _bars . LowPrices . Last ( 1 ));
var s3 = _bars . LowPrices . Last ( 1 ) - 2 * ( _bars . HighPrices . Last ( 1 ) - pivot );
Chart . DrawTrendLine ( "pivot " , _bars . OpenTimes . LastValue , pivot , _bars . OpenTimes . LastValue . AddDays ( 1 ), pivot , Color . White );
Chart . DrawTrendLine ( "r1 " , _bars . OpenTimes . LastValue , r1 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r1 , Color . Green );
Chart . DrawTrendLine ( "r2 " , _bars . OpenTimes . LastValue , r2 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r2 , Color . Green );
Chart . DrawTrendLine ( "r3 " , _bars . OpenTimes . LastValue , r3 , _bars . OpenTimes . LastValue . AddDays ( 1 ), r3 , Color . Green );
Chart . DrawTrendLine ( "s1 " , _bars . OpenTimes . LastValue , s1 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s1 , Color . Red );
Chart . DrawTrendLine ( "s2 " , _bars . OpenTimes . LastValue , s2 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s2 , Color . Red );
Chart . DrawTrendLine ( "s3 " , _bars . OpenTimes . LastValue , s3 , _bars . OpenTimes . LastValue . AddDays ( 1 ), s3 , Color . Red );
}
}
}
Prima Ctrl + B ou clique em Criar , depois adicione o indicador a um gráfico clicando em Adicionar instância .
Deverá ver os pontos pivot desenhados no gráfico.
Criar um indicador fractal Vamos desenvolver um indicador separado que traça fractais num gráfico. Repita os passos da secção anterior e crie outro indicador com um novo nome.
Faça deste indicador um indicador de sobreposição.
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
Desenhe setas acima das barras onde o valor alto é superior às duas barras adjacentes de cada lado no método Calculate().
if ( Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 1 ] && Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index ] &&
Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 3 ] && Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 4 ])
{
Chart . DrawIcon ( Bars . OpenTimes [ index ]. ToString (), ChartIconType . DownArrow , Bars . OpenTimes [ index - 2 ], Bars . HighPrices [ index - 2 ], Color . Red );
}
Desenhe setas para cima abaixo das barras onde o valor baixo é inferior às duas barras adjacentes de cada lado.
if ( Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 1 ] && Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index ] &&
Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 3 ] && Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 4 ])
{
Chart . DrawIcon ( Bars . OpenTimes [ index ]. ToString (), ChartIconType . UpArrow , Bars . OpenTimes [ index - 2 ], Bars . LowPrices [ index - 2 ], Color . Green );
}
Pode copiar o código completo abaixo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 using System ;
using cAlgo.API ;
using cAlgo.API.Collections ;
using cAlgo.API.Indicators ;
using cAlgo.API.Internals ;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
public class FractalsExample : Indicator
{
protected override void Initialize ()
{
}
public override void Calculate ( int index )
{
if ( Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 1 ] && Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index ] &&
Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 3 ] && Bars . HighPrices [ index - 2 ] > Bars . HighPrices [ index - 4 ])
{
Chart . DrawIcon ( Bars . OpenTimes [ index ]. ToString (), ChartIconType . DownArrow , Bars . OpenTimes [ index - 2 ], Bars . HighPrices [ index - 2 ], Color . Red );
}
if ( Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 1 ] && Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index ] &&
Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 3 ] && Bars . LowPrices [ index - 2 ] < Bars . LowPrices [ index - 4 ])
{
Chart . DrawIcon ( Bars . OpenTimes [ index ]. ToString (), ChartIconType . UpArrow , Bars . OpenTimes [ index - 2 ], Bars . LowPrices [ index - 2 ], Color . Green );
}
}
}
}
Crie o indicador e adicione uma instância a um gráfico.
Deverá ver objetos fractais exibidos nas velas relevantes no gráfico.
Este artigo demonstrou como adicionar pontos pivot e fractais aos gráficos, permitindo uma visualização adequada de informações-chave.