This website uses cookies to enhance site navigation, analyze site usage, and assist in our marketing efforts. By clicking “Accept All” you are providing your consent to our use of all cookies. Alternatively, please provide your choice by pressing “Customize Cookies”. For more information, please read our Privacy policy
bru34
13 Jun 2020, 17:11
Fixed It in part
Here is the fix Bro.
New Code, i put it in comments.
*****************************************
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
using System.Threading;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
public class CrossHairSync : Indicator
{
[Parameter("LineStyle", Group = "Style for Current Chart", DefaultValue = LineStyle.Solid)]
public LineStyle LS { get; set; }
[Parameter("Thickness", Group = "Style for Current Chart", DefaultValue = 1)]
public int Thc { get; set; }
[Parameter("Color", Group = "Style for Current Chart", DefaultValue = "White")]
public string Col { get; set; }
[Parameter("Opacity", Group = "Style for Current Chart", DefaultValue = 60)]
public int Opc { get; set; }
private Color Colour;
protected override void Initialize()
{
Opc = (int)(255 * 0.01 * Opc);
Colour = Color.FromArgb(Opc, Color.FromName(Col).R, Color.FromName(Col).G, Color.FromName(Col).B);
Crosshair.AddChart(this);
Chart.MouseMove += OnChartMouseMove;
Chart.MouseLeave += OnChartMouseLeave;
}
void OnChartMouseLeave(ChartMouseEventArgs obj)
{
Crosshair.DeleteCrosshair();
}
void OnChartMouseMove(ChartMouseEventArgs obj)
{
Crosshair.DrawCrosshair(Bars.OpenTimes[(int)obj.BarIndex], obj.YValue, LS, Thc, Colour);
}
public override void Calculate(int index)
{
}
}
public static class Crosshair
{
private static List<Indicator> Indicators = new List<Indicator>();
private static object _lock = new object();
public static void DrawCrosshair(DateTime x, double y, LineStyle ls, int thc, Color colour)
{
try
{
lock (_lock)
{
foreach (Indicator i in Indicators)
{
Thread t = new Thread(() =>
{
if (i.Chart.TopY > y && i.Chart.BottomY < y)
{
i.BeginInvokeOnMainThread(() => { i.Chart.DrawHorizontalLine("HCL", y, colour, thc, ls); });
}
System.DateTime xRight = i.Chart.Bars.LastBar.OpenTime;
if (xRight.CompareTo(x) > 0)
{
i.BeginInvokeOnMainThread(() => { i.Chart.DrawVerticalLine("VCL", x, colour, thc, ls); });
}
});
t.Start();
}
}
} catch (Exception)
{
}
}
public static void DeleteCrosshair()
{
try
{
lock (_lock)
{
foreach (Indicator i in Indicators)
{
Thread t = new Thread(() =>
{
i.BeginInvokeOnMainThread(() => { i.Chart.RemoveObject("HCL"); });
i.BeginInvokeOnMainThread(() => { i.Chart.RemoveObject("VCL"); });
});
t.Start();
}
}
} catch (Exception)
{
}
}
public static void AddChart(Indicator indicator)
{
try
{
lock (_lock)
Indicators.Add(indicator);
} catch (Exception e)
{
indicator.Print(e);
}
}
}
}
@bru34