Description
hi
this is indicator that have been wroten by devman and i change it a little (fibo timezone made by devman)
with this new update you can change Fibonacci levels to what you want
How to use:
1. Draw any trendline.
2. Open trendline settings (right click).
3. Type `ftz` in comment.
4. Type `ftz|7` to create 7 levels.
5. first 2 lvls are base lvls
thanks to devman to wrote main codes and allow me to share it
you can contact me in instagram : bourse_blinders
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using System.Linq;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FibonacchiTimezone : Indicator
{
private const string LevelSuffix = "ftzl";
[Parameter("Draw method", DefaultValue = Method.ByBars, Group = "Levels")]
public Method Method { get; set; }
[Parameter("Default count", DefaultValue = 10, MinValue = 0, MaxValue = 100, Group = "Levels")]
public int DefaultLevelCount { get; set; }
[Parameter("lvl1", DefaultValue = 1, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl1 { get; set; }
[Parameter("lvl2", DefaultValue = 2, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl2 { get; set; }
[Parameter("lvl3", DefaultValue = 2.382, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl3 { get; set; }
[Parameter("lvl4", DefaultValue = 2.618, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl4 { get; set; }
[Parameter("lvl5", DefaultValue = 3, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl5 { get; set; }
[Parameter("lvl6", DefaultValue = 3.618, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl6 { get; set; }
[Parameter("lvl7", DefaultValue = 4, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl7 { get; set; }
[Parameter("lvl8", DefaultValue = 4.618, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl8 { get; set; }
[Parameter("lvl9", DefaultValue = 5, MinValue = 0, MaxValue = 100, Group = "Levels")]
public double lvl9 { get; set; }
[Parameter("Base line opacity", DefaultValue = 0.8, MinValue = 0, MaxValue = 1, Group = "Base line")]
public double BaseLineOpacity { get; set; }
[Parameter("Base line trigger", DefaultValue = "ftz", Group = "Base line")]
public string BaseLineTrigger { get; set; }
[Parameter("Show instructions", DefaultValue = true, Group = "Other")]
public bool ShowHelp { get; set; }
protected override void Initialize()
{
var lines = Chart.FindAllObjects<ChartTrendLine>().Where(CanDrawLevels).ToArray();
foreach (var line in lines)
UpdateLevels(line);
Chart.ObjectAdded += Chart_ObjectAdded;
Chart.ObjectRemoved += Chart_ObjectRemoved;
Chart.ObjectUpdated += Chart_ObjectUpdated;
if (ShowHelp)
{
Chart.DrawStaticText("ftz-help", string.Format("\r\n1. Draw any trendline.\r\n2. Open trendline settings (right click).\r\n3. Type `{0}` in comment.\r\n4. Type `{0}|7` to create 7 levels.\r\n5.first 2 lvls are base lvls , you can change all lvls", BaseLineTrigger), VerticalAlignment.Top, HorizontalAlignment.Left, Chart.ColorSettings.ForegroundColor);
}
}
private void Chart_ObjectUpdated(ChartObjectUpdatedEventArgs args)
{
if (args.ChartObject is ChartTrendLine)
{
var line = (ChartTrendLine)args.ChartObject;
if (CanDrawLevels(line))
UpdateLevels(line);
else
RemoveLevels(line);
}
}
private void Chart_ObjectAdded(ChartObjectAddedEventArgs args)
{
if (args.ChartObject is ChartTrendLine && CanDrawLevels((ChartTrendLine)args.ChartObject))
{
UpdateLevels((ChartTrendLine)args.ChartObject);
}
}
private void Chart_ObjectRemoved(ChartObjectRemovedEventArgs args)
{
if (args.ChartObject is ChartTrendLine && CanDrawLevels((ChartTrendLine)args.ChartObject))
{
RemoveLevels((ChartTrendLine)args.ChartObject);
}
}
private void RemoveLevels(ChartTrendLine line)
{
var levels = Chart.FindAllObjects<ChartVerticalLine>().Where(vl => !vl.IsInteractive && vl.Name.StartsWith(line.Name + LevelSuffix)).ToArray();
foreach (var level in levels)
{
Chart.RemoveObject(level.Name);
}
}
private void UpdateLevels(ChartTrendLine line)
{
RemoveLevels(line);
line.Color = Color.FromArgb((int)(BaseLineOpacity * byte.MaxValue), line.Color);
var levelCount = GetLevelCount(line);
if (levelCount <= 0)
return;
var size = GetSize(line);
double lastLevel = 0;
double currentLevel = 1;
double[] names = new double[12]
{
lvl1,
lvl2,
lvl3,
lvl4,
lvl5,
lvl6,
lvl7,
lvl8,
lvl9,
89,
144,
233
};
for (var i = 0; i < levelCount; i++)
{
var tempLevel = currentLevel;
currentLevel = lastLevel + currentLevel;
lastLevel = tempLevel;
DrawLevel(line, currentLevel = names[i], size);
}
}
private void DrawLevel(ChartTrendLine line, double level, double size)
{
var lineName = line.Name + LevelSuffix + level;
var lineColor = Color.FromArgb(byte.MaxValue, line.Color);
var levelSize = (int)Math.Round((level - 1) * size);
ChartVerticalLine levelLine;
switch (Method)
{
case Method.ByBars:
var barIndex = MarketSeries.OpenTime.GetIndexByTime(line.Time1) + levelSize;
levelLine = Chart.DrawVerticalLine(lineName, barIndex, lineColor);
break;
case Method.ByTime:
var time = line.Time1.AddSeconds(levelSize);
levelLine = Chart.DrawVerticalLine(lineName, time, lineColor);
break;
default:
throw new ArgumentOutOfRangeException();
}
levelLine.LineStyle = line.LineStyle;
levelLine.Thickness = line.Thickness;
}
private double GetSize(ChartTrendLine line)
{
switch (Method)
{
case Method.ByBars:
return MarketSeries.OpenTime.GetIndexByTime(line.Time2) - MarketSeries.OpenTime.GetIndexByTime(line.Time1);
case Method.ByTime:
return (line.Time2 - line.Time1).TotalSeconds;
default:
throw new ArgumentOutOfRangeException();
}
}
private int GetLevelCount(ChartTrendLine line)
{
int levelCount = 0;
if (!line.Comment.Contains("|") || !int.TryParse(line.Comment.Split('|')[1], out levelCount))
{
levelCount = DefaultLevelCount;
}
return levelCount;
}
private bool CanDrawLevels(ChartTrendLine line)
{
return line.Comment != null && line.Comment.StartsWith(BaseLineTrigger);
}
public override void Calculate(int index)
{
// do nothing
}
}
public enum Method
{
ByBars,
ByTime
}
}
AM
aminc
Joined on 08.06.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Fibonacchi Timezone.algo
- Rating: 0
- Installs: 2055
- 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.