Description
Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp
This is a conversion from TradingView's Fibo TimeZones
For any bug report or suggestion, follow my telegram group or comment below
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)
{
Chart.DrawVerticalLine("FIBO_cycle" + i + " " + name, coo1 + fibos[i] * (coo2 - coo1), alphaColor);
double conjCoord = (Chart.TopY - Chart.BottomY) * 0.75 + Chart.BottomY;
Chart.DrawTrendLine("Conj", x1, conjCoord, x2, conjCoord, alphaColor);
Chart.DrawText("fibocyclename" + fibos[i], "" + fibos[i], coo1 + fibos[i] * (coo2 - coo1) + 1, conjCoord, alphaColor);
}
}
}
private int[] fibos = new int[12]
{
1,
2,
3,
5,
8,
13,
21,
34,
55,
89,
144,
233
};
public override void Calculate(int index)
{
}
}
}
CY
cysecsbin.01
Joined on 10.11.2018 Blocked
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Fibo TimeZone.algo
- Rating: 0
- Installs: 2073
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.