Yes
Yes, here is also an update version of my code. So basically i dont how to convert data from an ema cross into datapoints where the code can draw line in between (index 1, y1, index 2, y2)
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
public class Multitimeframerenkoema : Indicator
{
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("SlowmaPeriods", DefaultValue = 14)]
public int SlowmaPeriods { get; set; }
[Parameter("FastmaPeriods", DefaultValue = 14)]
public int FastmaPeriods { get; set; }
[Output("Slowma", LineColor = "Red")]
public IndicatorDataSeries Resultslowma { get; set; }
[Output("Fastma", LineColor = "Yellow")]
public IndicatorDataSeries Resultfastma { get; set; }
private double slowma;
private double fastma;
protected override void Initialize()
{
slowma = 2.0 / (SlowmaPeriods + 1);
fastma = 2.0 / (FastmaPeriods + 1);
}
public override void Calculate(int index)
{
//Slowma
var previousValueslow = Resultslowma[index - 1];
if (double.IsNaN(previousValueslow))
{
Resultslowma[index] = Source[index];
}
else
{
Resultslowma[index] = Source[index] * slowma + previousValueslow * (1 - slowma);
}
//Fastma
{
var previousValuefast = Resultfastma[index - 1];
if (double.IsNaN(previousValuefast))
{
Resultfastma[index] = Source[index];
}
else
{
Resultfastma[index] = Source[index] * fastma + previousValuefast * (1 - fastma);
}
//Cross draw trendline
//Buy
var Bullishcross = (previousValueslow > previousValuefast && Resultslowma[index] < Resultfastma[index]);
if (previousValueslow > previousValuefast && Resultslowma[index] < Resultfastma[index])
{
Chart.DrawTrendLine("trendLine", Chart.FirstVisibleBarIndex, Bars.ClosePrices[Chart.FirstVisibleBarIndex], Chart.LastVisibleBarIndex, Bars.ClosePrices[Chart.LastVisibleBarIndex], Color.Green, 2, LineStyle.Solid);
}
//Sell
var Bearishcross = (previousValueslow < previousValuefast && Resultslowma[index] > Resultfastma[index]);
if (previousValueslow < previousValuefast && Resultslowma[index] > Resultfastma[index])
{
Chart.DrawTrendLine("trendLine", Chart.FirstVisibleBarIndex, Bars.LowPrices[Chart.FirstVisibleBarIndex], Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Green, 2, LineStyle.Solid);
}
}
}
}
}