Fibonacci time zone indicator
Fibonacci time zone indicator
08 Jul 2020, 16:46
hi
i tried to change fibonacci levels to decimals number , but it gave me these errors :
Error CS1502: The best overloaded method match for 'cAlgo.API.ChartArea.DrawVerticalLine(string, System.DateTime, cAlgo.API.Color)' has some invalid arguments
Error CS1503: Argument 2: cannot convert from 'double' to 'System.DateTime'
i know why it gave me these errors( because they must be "int" not "double" , but my fibo levels are decimals so i need double) , but i dont know how to solve it
here the cods , at the end you can see my decimals number and the errors part
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FiboTimeZone : Indicator
{
[Parameter("Color", DefaultValue = "Blue")]
public string col { get; set; }
[Parameter("Transparency %", DefaultValue = 50)]
public int trsp { get; set; }
[Parameter("Magic Number", DefaultValue = 0)]
public int mgc { get; set; }
private int x1;
private int x2;
private string selected = "none";
private Color alphaColor;
private string name;
protected override void Initialize()
{
name = " " + mgc.ToString();
Color color = Color.FromName(col);
alphaColor = Color.FromArgb((int)(trsp * 2.55), color.R, color.G, color.B);
drawCursors();
Chart.ObjectHoverChanged += OnChartObjectHoverChanged;
Chart.MouseUp += OnChartMouseUp;
}
void OnChartMouseUp(ChartMouseEventArgs obj)
{
if (selected == "cycle1")
{
x1 = (int)obj.BarIndex;
drawCycles();
}
if (selected == "cycle2")
{
x2 = (int)obj.BarIndex;
drawCycles();
}
}
void OnChartObjectHoverChanged(ChartObjectHoverChangedEventArgs obj)
{
if (!obj.IsObjectHovered)
selected = "none";
else
try
{
if (obj.ChartObject.Name == "cycle1" + name)
{
selected = "cycle1";
}
else if (obj.ChartObject.Name == "cycle2" + name)
{
selected = "cycle2";
}
else
selected = "none";
} catch (Exception e)
{
return;
}
}
private void drawCursors()
{
int index = Chart.FirstVisibleBarIndex + 10;
Chart.DrawVerticalLine("cycle1" + name, index, alphaColor, 2);
Chart.DrawVerticalLine("cycle2" + name, index, alphaColor, 2, LineStyle.DotsRare);
Chart.FindObject("cycle1" + name).IsInteractive = true;
Chart.FindObject("cycle2" + name).IsInteractive = true;
x1 = index;
x2 = index;
}
private void drawCycles()
{
for (int i = 0; i < Chart.BarsTotal + 1000; i++)
{
Chart.RemoveObject("FIBO_cycle" + i + " " + name);
}
if (Math.Abs(x2 - x1) > 1)
{
int coo1 = Math.Min(x1, x2);
int coo2 = Math.Max(x1, x2);
for (int i = 0; i < fibos.Length; ++i)
{
// errors part
double f = (double)fibos[i];
Chart.DrawVerticalLine("FIBO_cycle" + i + " " + name, coo1 + f * (coo2 - coo1), alphaColor);
double conjCoord = (Chart.TopY - Chart.BottomY) * 0.75 + Chart.BottomY;
Chart.DrawTrendLine("Conj", x1, conjCoord, x2, conjCoord, alphaColor);
Chart.DrawText("fibocyclename" + f, "" + fibos[i], coo1 + f * (coo2 - coo1) + 1, conjCoord, alphaColor);
}
}
}
private double[] fibos = new double[12]
{
1,
1.618,
2,
2.618,
3,
3.618,
21,
34,
55,
89,
144,
233
};
public override void Calculate(int index)
{
}
}
}
Replies
aminc
09 Jul 2020, 14:38
RE:
PanagiotisCharalampous said:
Hi cesafat,
You cannot have an index as a decimal. It just doesn't make sense.
Best Regards,
Panagiotis
thanks for answer Panagiotis
but we have fibo tomezone with decimals lvls in other platforms
i try to figure out to how to make it right
do you know any plans to add fibo timezone tools to ctrader ? because fibo timezone is popular time analyse
we have some indicator users made it in ctrader but they dont work right or they base of their own strategies and we cant change it
@aminc
PanagiotisCharalampous
09 Jul 2020, 14:42
Hi cesafat,
You can do that in cTrader as well but not by using indices. You can consider using
DrawVerticalLine(string name, DateTime time, Color color)
which uses an exact date time instead
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
09 Jul 2020, 08:24
Hi cesafat,
You cannot have an index as a decimal. It just doesn't make sense.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous