Extracción de datos de un indicador
Extracción de datos de un indicador
07 Mar 2022, 13:59
Buenos días.
Estoy utilizando el indicador SwingHighLow y no logro extraer los datos que calcula para imprimirlos en el registro de mi CBot.
Codigo del indicador:
========================================================
using System;
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, AutoRescale = false, AccessRights = AccessRights.None)]
public class SwingHigh : Indicator
{
[Parameter("Fuente")]
public DataSeries Source { get; set; }
[Parameter("Periodo", DefaultValue = 13, MinValue = 3)]
public int Period { get; set; }
[Parameter("Escala de Precision", DefaultValue = 5)]
public int ScalePrecision { get; set; }
[Parameter("Color del Texto", DefaultValue = "Pink")]
public string TextColor { get; set; }
private Colors color = Colors.White;
private Colors colorSell = Colors.Red;
private Colors colorBuy = Colors.Green;
private string format;
protected override void Initialize()
{
// Parse color from string, e.g. "Yellow", "Green", "Red". string must start with large letter, "Red" is valid, "red" - not.
Enum.TryParse(TextColor, out color);
// create string format based on scale precision, e.g "0.000" for scale precision = 3
format = "0." + new string('0', ScalePrecision);
UpdateLabels(true);
}
public override void Calculate(int index)
{
if (IsRealTime)
UpdateLabels(false);
}
private void UpdateLabels(bool fastUpdate)
{
ChartObjects.RemoveAllObjects();
int startIndex = fastUpdate ? Source.Count - 350 : 0;
int index;
int index2;
index = Source.Count - 2;
while (index >= startIndex)
{
if (IsLocalExtremum(index, true))
{
ChartObjects.DrawText("max_" + index, Source[index].ToString(format), index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, colorSell);
index = index - Period;
}
else
index--;
}
index2 = Source.Count - 2;
while (index2 >= startIndex)
{
if (IsLocalExtremumM(index2, true))
{
ChartObjects.DrawText("min_" + index2, Source[index2].ToString(format), index2, Source[index2], VerticalAlignment.Bottom, HorizontalAlignment.Center, colorBuy);
index2 = index2 - Period;
}
else
index2--;
}
var lastIndex = Source.Count - 1;
}
private bool IsLocalExtremum(int index, bool findMax)
{
int end = Math.Min(index + Period, Source.Count - 1);
int start = Math.Max(index - Period, 0);
double value = Source[index];
for (int i = start; i <= end; i++)
{
if (findMax && value < Source[i])
return false;
if (!findMax && value > Source[i])
return false;
}
return true;
}
private bool IsLocalExtremumM(int index2, bool findMin)
{
int start = Math.Min(index2 + Period, Source.Count - 1);
int end = Math.Max(index2 - Period, 0);
double value = Source[index2];
for (int i = start; i <= end; i++)
{
if (findMin && value < Source[i])
return false;
if (!findMin && value > Source[i])
return false;
}
return true;
}
}
}
============================================================
En mi CBot agregué
PARAMETROS
...
protected override void OnStart()
{
Swing = Indicators.GetIndicator<SwingHighLow>(Source, Period, ScalePrecision, TextColor);
...
protected override void OnBar()
{
Print("SWING= " + cAlgo.Indicators.SwingHighLow.Result);
================================================================
No logro que imprima en el registro.
Alguna ayuda ?
amusleh
08 Mar 2022, 09:06
Hola,
Solo brindamos soporte en inglés, el indicador que está utilizando no tiene la propiedad "Output", por lo que no hay datos que se puedan usar en su cBot.
@amusleh