Description
hi
Synchronize the thickness and color of the trend line according to the time frame
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ColoriTrendLine : Indicator
{
[Parameter("Day", DefaultValue = 120000)]
public int D { get; set; }
[Parameter("Day Color", DefaultValue = "Blue")]
public string DayColor { get; set; }
[Parameter("4 Hours ", DefaultValue = 70000)]
public int H_4 { get; set; }
[Parameter("H_4 Color", DefaultValue = "Green")]
public string H_4Color { get; set; }
[Parameter("1 Hours ", DefaultValue = 10000)]
public int H_1 { get; set; }
[Parameter("H_1 Color", DefaultValue = "Purple")]
public string H_1Color { get; set; }
[Parameter("15 min ", DefaultValue = 5000)]
public int M_15 { get; set; }
[Parameter("M_15 Color", DefaultValue = "Brown")]
public string M_15Color { get; set; }
[Parameter("5 min ", DefaultValue = 500)]
public int M_5 { get; set; }
[Parameter("M_5 Color", DefaultValue = "Orange")]
public string M_5Color { get; set; }
[Parameter("1 min ", DefaultValue = 0)]
public int M_1 { get; set; }
[Parameter("M_1 Color", DefaultValue = "Red")]
public string M_1Color { get; set; }
ChartTrendLine[] lin;
protected override void Initialize()
{
// Initialize and create nested indicators
lin = null;
}
Color[] co =
{
Color.Blue,
Color.Green
};
public override void Calculate(int index)
{
OptimaizeTrendLine();
}
private void DisplaySpreadOnChart(Double x)
{
var str = Math.Round(x, 2);
string text = string.Format("{0}", str);
ChartObjects.DrawText("Label", "Info:", StaticPosition.TopLeft, Colors.Green);
ChartObjects.DrawText("spread", "\t" + text, StaticPosition.TopLeft, Colors.Blue);
}
public void OptimaizeTrendLine()
{
lin = GetTrendLineList();
TimeSpan dif;
double mifDif = 0;
for (int j = 0; j < lin.Length; j++)
{
dif = lin[j].Time2.Subtract(lin[j].Time1);
mifDif = dif.TotalMinutes;
if (mifDif > D)
{
lin[j].Color = Color.FromName(DayColor);
lin[j].Thickness = 3;
}
else if (mifDif > H_4)
{
lin[j].Color = H_4Color;
lin[j].Thickness = 3;
}
else if (mifDif > H_1)
{
lin[j].Color = H_1Color;
lin[j].Thickness = 2;
}
else if (mifDif > M_15)
{
lin[j].Color = M_15Color;
lin[j].Thickness = 2;
}
else if (mifDif > M_5)
{
lin[j].Color = M_5Color;
lin[j].Thickness = 1;
}
else if (mifDif > M_1)
{
lin[j].Color = M_1Color;
lin[j].Thickness = 1;
}
}
}
public void ColoredTrendLine()
{
Random rang = new Random(0);
int i = 0;
ChartTrendLine[] lin = new ChartTrendLine[100];
foreach (ChartObject o in Chart.Objects)
{
if (ChartObjectType.TrendLine == o.ObjectType)
{
lin[i++] = (ChartTrendLine)o;
}
}
for (int j = 0; j < 100; j++)
{
lin[j].Color = Color.FromArgb(255, rang.Next(1, 255), rang.Next(1, 255), rang.Next(1, 255));
}
}
ChartTrendLine[] GetTrendLineList()
{
int i = 0;
ChartTrendLine[] lin = new ChartTrendLine[GetNumberOfTrendLine()];
foreach (ChartObject o in Chart.Objects)
{
if (ChartObjectType.TrendLine == o.ObjectType)
{
lin[i++] = (ChartTrendLine)o;
}
}
return lin;
}
public int GetNumberOfTrendLine()
{
int ntl = 0;
foreach (ChartObject o in Chart.Objects)
{
if (ChartObjectType.TrendLine == o.ObjectType)
{
ntl++;
}
}
return ntl;
}
}
}
ME
meysam.gharehbagheri
Joined on 13.02.2018
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: ColoriTrendLine.algo
- Rating: 0
- Installs: 2319
- 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.