Description
A simple indicator (built on request) that separates out the days of the week on timeframes below the daily chart.
At FXTS we can do dev work on request, just get in contact via: fxtradersystems.com/support/
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 DayChanges : Indicator
{
[Parameter("Show Instructions?", DefaultValue = true)]
public bool ShowInstructions { get; set; }
protected override void Initialize()
{
if (Bars.TimeFrame >= TimeFrame.Daily)
{
Chart.DrawStaticText("Warning", "Indicator only suitable for below daily timeframe", VerticalAlignment.Bottom, HorizontalAlignment.Left, Color.Red);
}
string[] days = new string[]
{
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};
if (ShowInstructions)
{
for (int i = 0; i < days.Length; i++)
{
string day = days[i];
string msg = "";
for (int buffer = 0; buffer < i; buffer++)
msg += "\n";
msg += day;
Chart.DrawStaticText(day, msg, VerticalAlignment.Top, HorizontalAlignment.Left, GetColor(day));
}
}
}
public override void Calculate(int index)
{
if (Bars.TimeFrame < TimeFrame.Daily)
{
Chart.RemoveObject("Vertical " + index);
DayOfWeek prevDay = GetDay(1);
DayOfWeek today = GetDay(0);
if (today != prevDay)
Chart.DrawVerticalLine("Vertical " + index, index, GetColor(today), 1, LineStyle.Dots);
}
}
private DayOfWeek GetDay(int dayToGet)
{
if (dayToGet == 0)
return Bars.OpenTimes.LastValue.DayOfWeek;
else
return Bars.OpenTimes.Last(dayToGet).DayOfWeek;
}
private Color GetColor(string day)
{
switch (day)
{
case "Monday":
return Color.ForestGreen;
case "Tuesday":
return Color.Cyan;
case "Wednesday":
return Color.Gold;
case "Thursday":
return Color.Red;
case "Friday":
return Color.Orange;
case "Saturday":
return Color.Lavender;
case "Sunday":
return Color.Lime;
default:
throw new ArgumentException("Get Color does not have an option for: " + day.ToString() + " of type: " + day.GetType().ToString());
}
}
private Color GetColor(DayOfWeek day)
{
switch (day)
{
case DayOfWeek.Monday:
return Color.ForestGreen;
case DayOfWeek.Tuesday:
return Color.Cyan;
case DayOfWeek.Wednesday:
return Color.Gold;
case DayOfWeek.Thursday:
return Color.Red;
case DayOfWeek.Friday:
return Color.Orange;
case DayOfWeek.Saturday:
return Color.Lavender;
case DayOfWeek.Sunday:
return Color.Lime;
default:
throw new ArgumentException("Get Color does not have an option for: " + day.ToString() + " of type: " + day.GetType().ToString());
}
}
}
}
fxtradersystems
Joined on 10.09.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: DayChanges.algo
- Rating: 0
- Installs: 2155
- 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.
FC
ohh nice! but poopy no options to change colors of days, ok if you are using a black chart.
@fcarabat you can change the color from the source code