Cómo crear indicadores de punto de pivote y fractal VIDEO
Muchos indicadores y estrategias se basan en objetos de gráfico para presentar información esencial, y cTrader Algo proporciona los métodos de API necesarios para dibujar dichos objetos. Los puntos de pivote y los fractales, en particular, se dibujan en los gráficos de trading para ayudar a identificar niveles de precio crÃticos y puntos de inflexión.
En este artÃculo y el video correspondiente, aprenderá cómo dibujar puntos de pivote y fractales en los gráficos.
Crear un indicador de punto de pivote Los puntos de pivote son niveles de precio calculados a partir de precios anteriores. Estos puntos indican áreas potenciales de soporte o resistencia.
Crearemos un indicador que dibuje puntos de pivote diarios en un gráfico.
En cTrader Algo, navegue hasta la pestaña Indicadores y haga clic en Nuevo . Escriba un nombre para el nuevo indicador y luego haga clic en el botón Crear .
Modifique el indicador en el editor de código para convertirlo en un indicador de superposición.
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
Defina y obtenga las barras diarias en el método Initialize().
Bars _bars ;
protected override void Initialize ()
{
_bars = MarketData . GetBars ( TimeFrame . Daily , SymbolName );
}
Calcule los diferentes niveles de soporte y resistencia conocidos como puntos pivote. Se calculan siete valores que comprenden el punto pivote, tres niveles de resistencia y tres niveles de soporte.
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 );
Una vez calculados los puntos pivote, se pueden dibujar en el gráfico utilizando lÃneas de tendencia.
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 );
Puede copiar el código completo a continuación:
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 );
}
}
}
Pulse Ctrl + B o haga clic en Compilar , luego añada el indicador a un gráfico haciendo clic en Añadir instancia .
DeberÃa ver los puntos pivote dibujados en el gráfico.
Crear un indicador fractal Desarrollaremos un indicador separado que traza fractales en un gráfico. Repita los pasos de la sección anterior y cree otro indicador con un nuevo nombre.
Haga de este indicador un indicador de superposición.
[Indicator(AccessRights = AccessRights.None, IsOverlay = true)]
Dibuje flechas sobre las barras donde el valor alto es superior al de las dos barras adyacentes a cada lado en el 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 );
}
Dibuje flechas hacia arriba debajo de las barras donde el valor bajo es inferior al de las dos barras adyacentes a 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 );
}
Puede copiar el código completo a continuación:
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 );
}
}
}
}
Compile el indicador y añada una instancia a un gráfico.
DeberÃa ver objetos fractales mostrados en las velas relevantes del gráfico.
Este artÃculo ha demostrado cómo añadir puntos pivote y fractales a los gráficos, permitiendo una visualización adecuada de la información clave.