Indicator incompatibility on Mac
Indicator incompatibility on Mac
24 Oct 2024, 08:22
Trading Sessions indicator:
https://ctrader.com/algos/indicators/show/3974/
Hello friends, this is the indicator that I have designed to manage the sessions. But it seems that it does not work properly in Mac operating system.
In case I wrote it with .NET 6 and no error or warning is observed during compilation.
How can I fix the indicator problem?
Replies
AlgoCreators
24 Oct 2024, 13:05
RE: Indicator incompatibility on Mac
PanagiotisCharalampous said:
Hi there,
Can you explain what is the exact problem?
Best regards,
Panagiotis
One of the users who installed the indicator on Mac sent me this message
@AlgoCreators
PanagiotisCharalampous
24 Oct 2024, 13:11
RE: RE: Indicator incompatibility on Mac
AlgoCreators said:
PanagiotisCharalampous said:
Hi there,
Can you explain what is the exact problem?
Best regards,
Panagiotis
One of the users who installed the indicator on Mac sent me this message
Unfortunately it doesn't help. You need to provide us with source code and exact steps to reproduce the problem
@PanagiotisCharalampous
AlgoCreators
24 Oct 2024, 15:48
RE: RE: RE: Indicator incompatibility on Mac
This is the source code of the indicator:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Globalization;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.FullAccess, IsOverlay = true, TimeZone = TimeZones.UTC)]
public class TradingSessions : Indicator
{
[Parameter("Version:", DefaultValue = "1.0.1")]
public string Version { get; set; }
[Parameter("Show for how many days", Group = "Sessions", DefaultValue = 15, MinValue = 0)]
public int Back_days { get; set; }
[Parameter("Filled Zones", DefaultValue = true, Group = "Sessions")]
public bool Filled_Zones { get; set; }
[Parameter("Show Labels", DefaultValue = true, Group = "Sessions")]
public bool Show_Labels { get; set; }
[Parameter("Infinitie range", DefaultValue = Infinite_Range.None, Group = "Sessions")]
public Infinite_Range InfiniteRange { get; set; }
public enum Infinite_Range
{
Up,
Down,
Both,
None
}
[Parameter("Show Session 1", DefaultValue = true, Group = "Session 1")]
public bool S1_Show { get; set; }
[Parameter("Session Label", DefaultValue = "Sydney", Group = "Session 1")]
public string S1_Label { get; set; }
[Parameter("Start time", DefaultValue = "21:00", Group = "Session 1")]
public string S1_open { get; set; }
[Parameter("End time", DefaultValue = "06:00", Group = "Session 1")]
public string S1_close { get; set; }
[Parameter("Color", Group = "Session 1", DefaultValue = "#20BEBF00")]
public Color S1_Color { get; set; }
[Parameter("Line Style", Group = "Session 1", DefaultValue = LineStyle.DotsRare)]
public LineStyle S1_LineStyle { get; set; }
[Parameter("Show Session 2", DefaultValue = true, Group = "Session 2")]
public bool S2_Show { get; set; }
[Parameter("Session Label", DefaultValue = "Tokyo", Group = "Session 2")]
public string S2_Label { get; set; }
[Parameter("Start time", DefaultValue = "00:00", Group = "Session 2")]
public string S2_open { get; set; }
[Parameter("End time", DefaultValue = "09:00", Group = "Session 2")]
public string S2_close { get; set; }
[Parameter("Color", Group = "Session 2", DefaultValue = "#2001AF50")]
public Color S2_Color { get; set; }
[Parameter("Line Style", Group = "Session 2", DefaultValue = LineStyle.DotsRare)]
public LineStyle S2_LineStyle { get; set; }
[Parameter("Show Session 3", DefaultValue = true, Group = "Session 3")]
public bool S3_Show { get; set; }
[Parameter("Session Label", DefaultValue = "London", Group = "Session 3")]
public string S3_Label { get; set; }
[Parameter("Start time", DefaultValue = "07:00", Group = "Session 3")]
public string S3_open { get; set; }
[Parameter("End time", DefaultValue = "16:00", Group = "Session 3")]
public string S3_close { get; set; }
[Parameter("Color", Group = "Session 3", DefaultValue = "#2033C1F3")]
public Color S3_Color { get; set; }
[Parameter("Line Style", Group = "Session 3", DefaultValue = LineStyle.DotsRare)]
public LineStyle S3_LineStyle { get; set; }
[Parameter("Show Session 4", DefaultValue = true, Group = "Session 4")]
public bool S4_Show { get; set; }
[Parameter("Session Label", DefaultValue = "New York", Group = "Session 4")]
public string S4_Label { get; set; }
[Parameter("Start time", DefaultValue = "13:00", Group = "Session 4")]
public string S4_open { get; set; }
[Parameter("End time", DefaultValue = "22:00", Group = "Session 4")]
public string S4_close { get; set; }
[Parameter("Color", Group = "Session 4", DefaultValue = "#20FF3334")]
public Color S4_Color { get; set; }
[Parameter("Line Style", Group = "Session 4", DefaultValue = LineStyle.DotsRare)]
public LineStyle S4_LineStyle { get; set; }
[Parameter("Show Session 5", DefaultValue = false, Group = "Session 5")]
public bool S5_Show { get; set; }
[Parameter("Session Label", DefaultValue = "", Group = "Session 5")]
public string S5_Label { get; set; }
[Parameter("Start time", DefaultValue = "00:00", Group = "Session 5")]
public string S5_open { get; set; }
[Parameter("End time", DefaultValue = "09:00", Group = "Session 5")]
public string S5_close { get; set; }
[Parameter("Color", Group = "Session 5", DefaultValue = "#75939695")]
public Color S5_Color { get; set; }
[Parameter("Line Style", Group = "Session 5", DefaultValue = LineStyle.DotsRare)]
public LineStyle S5_LineStyle { get; set; }
public List<Session> _sessions = new();
protected override void Initialize()
{
if (Bars.TimeFrame > TimeFrame.Hour4) return;
if (S1_Show && S1_Label != "")
_sessions.Add(new Session { name = S1_Label, Open = TimeSpan.Parse(S1_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S1_close), Color = S1_Color, LineStyle = S1_LineStyle });
if (S2_Show && S1_Label != "")
_sessions.Add(new Session { name = S2_Label, Open = TimeSpan.Parse(S2_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S2_close), Color = S2_Color, LineStyle = S2_LineStyle });
if (S3_Show && S1_Label != "")
_sessions.Add(new Session { name = S3_Label, Open = TimeSpan.Parse(S3_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S3_close), Color = S3_Color, LineStyle = S3_LineStyle });
if (S4_Show && S1_Label != "")
_sessions.Add(new Session { name = S4_Label, Open = TimeSpan.Parse(S4_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S4_close), Color = S4_Color, LineStyle = S4_LineStyle });
if (S5_Show && S1_Label != "")
_sessions.Add(new Session { name = S5_Label, Open = TimeSpan.Parse(S5_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S5_close), Color = S5_Color, LineStyle = S5_LineStyle });
foreach (var session in _sessions)
{
Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
}
var bars_m1 = MarketData.GetBars(TimeFrame.Minute, Symbol.Name);
bars_m1.BarOpened += bars_m1_BarOpened;
var Current_bars = MarketData.GetBars(Bars.TimeFrame, Symbol.Name);
Current_bars.BarOpened += Current_bars_BarOpened; ;
}
private void Current_bars_BarOpened(BarOpenedEventArgs obj)
{
RemoveAllobjects();
foreach (var session in _sessions)
{
Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
}
}
private void bars_m1_BarOpened(BarOpenedEventArgs args)
{
foreach (var session in _sessions)
{
if (args.Bars.Last(0).OpenTime.AddMinutes(5) == (DateTime)(args.Bars.Last(0).OpenTime.Date + session.Open))
{
Print("open " + session.name);
};
}
}
private void RemoveAllobjects()
{
foreach (var element in Chart.FindAllObjects(ChartObjectType.Text))
if (element.Name.Contains(this.ToString()))
Chart.RemoveObject(element.Name);
foreach (var element in Chart.FindAllObjects(ChartObjectType.Rectangle))
if (element.Name.Contains(this.ToString()))
Chart.RemoveObject(element.Name);
}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] =
}
public TimeSpan NormalizeTime(string STime)
{
DateTime TimeWithDate = Time.Date + TimeSpan.Parse(STime);
return TimeSpan.Parse(TimeWithDate.ToString("HH:mm"));
}
private void Draw_rect(string session, TimeSpan Opentime, TimeSpan Closetime, Color color, LineStyle lineStyle)
{
double Min = 0.0;
double Max = 0.0;
DateTime OpenDate, CloseDate;
int index, Openindex, Closeindex;
bool validation = true;
if (Closetime < Opentime)
{
OpenDate = Time.Date + Opentime;
CloseDate = (Time.Date + Closetime).AddDays(1);
}
else
{
OpenDate = Time.Date + Opentime;
CloseDate = Time.Date + Closetime;
}
for (int j = 0; j < Back_days; j++)
{
validation = true;
Openindex = Bars.OpenTimes.GetIndexByExactTime(OpenDate);
Closeindex = Bars.OpenTimes.GetIndexByExactTime(CloseDate);
if (Openindex < 0)
validation = false;
if (CloseDate.DayOfWeek == DayOfWeek.Saturday || CloseDate.DayOfWeek == DayOfWeek.Sunday)
validation = false;
if (validation)
{
Min = Bars[Openindex].Low;
Max = Bars[Openindex].High;
int i = Openindex;
for (i = Openindex; i < Bars.Count; i++)
{
if (Bars[i].OpenTime >= CloseDate) break;
Min = Math.Min(Bars[i].Low, Min);
Max = Math.Max(Bars[i].High, Max);
}
ChartRectangle rectangle = Chart.DrawRectangle(session + i + this.ToString(), OpenDate, Min, Bars[i - 1].OpenTime, Max, color, 1, lineStyle);
if (InfiniteRange == Infinite_Range.Up)
rectangle.Y2 *= 2;
else if (InfiniteRange == Infinite_Range.Down)
rectangle.Y1 /= 2;
else if (InfiniteRange == Infinite_Range.Both)
{
rectangle.Y1 /= 2;
rectangle.Y2 *= 2;
}
if (Filled_Zones)
rectangle.IsFilled = true;
if (Show_Labels)
{
ChartText text = Chart.DrawText("text" + rectangle.Name, session, OpenDate, Max, color);
text.VerticalAlignment = VerticalAlignment.Top;
text.FontSize = 10;
text.ZIndex = 10;
}
}
OpenDate = OpenDate.AddDays(-1);
CloseDate = CloseDate.AddDays(-1);
}
}
}
public class Session
{
public string name { get; set; }
public TimeSpan Open { get; set; }
public TimeSpan Close { get; set; }
public Color Color { get; set; }
public LineStyle LineStyle { get; set; }
}
}
@AlgoCreators
PanagiotisCharalampous
25 Oct 2024, 06:31
( Updated at: 25 Oct 2024, 06:32 )
RE: RE: RE: RE: Indicator incompatibility on Mac
AlgoCreators said:
This is the source code of the indicator:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using System.Globalization;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.FullAccess, IsOverlay = true, TimeZone = TimeZones.UTC)]
public class TradingSessions : Indicator
{
[Parameter("Version:", DefaultValue = "1.0.1")]
public string Version { get; set; }[Parameter("Show for how many days", Group = "Sessions", DefaultValue = 15, MinValue = 0)]
public int Back_days { get; set; }
[Parameter("Filled Zones", DefaultValue = true, Group = "Sessions")]
public bool Filled_Zones { get; set; }
[Parameter("Show Labels", DefaultValue = true, Group = "Sessions")]
public bool Show_Labels { get; set; }
[Parameter("Infinitie range", DefaultValue = Infinite_Range.None, Group = "Sessions")]
public Infinite_Range InfiniteRange { get; set; }
public enum Infinite_Range
{
Up,
Down,
Both,
None
}[Parameter("Show Session 1", DefaultValue = true, Group = "Session 1")]
public bool S1_Show { get; set; }
[Parameter("Session Label", DefaultValue = "Sydney", Group = "Session 1")]
public string S1_Label { get; set; }
[Parameter("Start time", DefaultValue = "21:00", Group = "Session 1")]
public string S1_open { get; set; }
[Parameter("End time", DefaultValue = "06:00", Group = "Session 1")]
public string S1_close { get; set; }
[Parameter("Color", Group = "Session 1", DefaultValue = "#20BEBF00")]
public Color S1_Color { get; set; }
[Parameter("Line Style", Group = "Session 1", DefaultValue = LineStyle.DotsRare)]
public LineStyle S1_LineStyle { get; set; }[Parameter("Show Session 2", DefaultValue = true, Group = "Session 2")]
public bool S2_Show { get; set; }
[Parameter("Session Label", DefaultValue = "Tokyo", Group = "Session 2")]
public string S2_Label { get; set; }
[Parameter("Start time", DefaultValue = "00:00", Group = "Session 2")]
public string S2_open { get; set; }
[Parameter("End time", DefaultValue = "09:00", Group = "Session 2")]
public string S2_close { get; set; }
[Parameter("Color", Group = "Session 2", DefaultValue = "#2001AF50")]
public Color S2_Color { get; set; }
[Parameter("Line Style", Group = "Session 2", DefaultValue = LineStyle.DotsRare)]
public LineStyle S2_LineStyle { get; set; }[Parameter("Show Session 3", DefaultValue = true, Group = "Session 3")]
public bool S3_Show { get; set; }
[Parameter("Session Label", DefaultValue = "London", Group = "Session 3")]
public string S3_Label { get; set; }
[Parameter("Start time", DefaultValue = "07:00", Group = "Session 3")]
public string S3_open { get; set; }
[Parameter("End time", DefaultValue = "16:00", Group = "Session 3")]
public string S3_close { get; set; }
[Parameter("Color", Group = "Session 3", DefaultValue = "#2033C1F3")]
public Color S3_Color { get; set; }
[Parameter("Line Style", Group = "Session 3", DefaultValue = LineStyle.DotsRare)]
public LineStyle S3_LineStyle { get; set; }[Parameter("Show Session 4", DefaultValue = true, Group = "Session 4")]
public bool S4_Show { get; set; }
[Parameter("Session Label", DefaultValue = "New York", Group = "Session 4")]
public string S4_Label { get; set; }
[Parameter("Start time", DefaultValue = "13:00", Group = "Session 4")]
public string S4_open { get; set; }
[Parameter("End time", DefaultValue = "22:00", Group = "Session 4")]
public string S4_close { get; set; }
[Parameter("Color", Group = "Session 4", DefaultValue = "#20FF3334")]
public Color S4_Color { get; set; }
[Parameter("Line Style", Group = "Session 4", DefaultValue = LineStyle.DotsRare)]
public LineStyle S4_LineStyle { get; set; }[Parameter("Show Session 5", DefaultValue = false, Group = "Session 5")]
public bool S5_Show { get; set; }
[Parameter("Session Label", DefaultValue = "", Group = "Session 5")]
public string S5_Label { get; set; }
[Parameter("Start time", DefaultValue = "00:00", Group = "Session 5")]
public string S5_open { get; set; }
[Parameter("End time", DefaultValue = "09:00", Group = "Session 5")]
public string S5_close { get; set; }
[Parameter("Color", Group = "Session 5", DefaultValue = "#75939695")]
public Color S5_Color { get; set; }
[Parameter("Line Style", Group = "Session 5", DefaultValue = LineStyle.DotsRare)]
public LineStyle S5_LineStyle { get; set; }
public List<Session> _sessions = new();
protected override void Initialize()
{
if (Bars.TimeFrame > TimeFrame.Hour4) return;if (S1_Show && S1_Label != "")
_sessions.Add(new Session { name = S1_Label, Open = TimeSpan.Parse(S1_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S1_close), Color = S1_Color, LineStyle = S1_LineStyle });
if (S2_Show && S1_Label != "")
_sessions.Add(new Session { name = S2_Label, Open = TimeSpan.Parse(S2_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S2_close), Color = S2_Color, LineStyle = S2_LineStyle });
if (S3_Show && S1_Label != "")
_sessions.Add(new Session { name = S3_Label, Open = TimeSpan.Parse(S3_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S3_close), Color = S3_Color, LineStyle = S3_LineStyle });
if (S4_Show && S1_Label != "")
_sessions.Add(new Session { name = S4_Label, Open = TimeSpan.Parse(S4_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S4_close), Color = S4_Color, LineStyle = S4_LineStyle });
if (S5_Show && S1_Label != "")
_sessions.Add(new Session { name = S5_Label, Open = TimeSpan.Parse(S5_open, CultureInfo.InvariantCulture), Close = TimeSpan.Parse(S5_close), Color = S5_Color, LineStyle = S5_LineStyle });foreach (var session in _sessions)
{
Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
}
var bars_m1 = MarketData.GetBars(TimeFrame.Minute, Symbol.Name);
bars_m1.BarOpened += bars_m1_BarOpened;var Current_bars = MarketData.GetBars(Bars.TimeFrame, Symbol.Name);
Current_bars.BarOpened += Current_bars_BarOpened; ;
}private void Current_bars_BarOpened(BarOpenedEventArgs obj)
{
RemoveAllobjects();
foreach (var session in _sessions)
{
Draw_rect(session.name, session.Open, session.Close, session.Color, session.LineStyle);
}
}private void bars_m1_BarOpened(BarOpenedEventArgs args)
{
foreach (var session in _sessions)
{
if (args.Bars.Last(0).OpenTime.AddMinutes(5) == (DateTime)(args.Bars.Last(0).OpenTime.Date + session.Open))
{
Print("open " + session.name);
};
}
}
private void RemoveAllobjects()
{
foreach (var element in Chart.FindAllObjects(ChartObjectType.Text))
if (element.Name.Contains(this.ToString()))
Chart.RemoveObject(element.Name);
foreach (var element in Chart.FindAllObjects(ChartObjectType.Rectangle))
if (element.Name.Contains(this.ToString()))
Chart.RemoveObject(element.Name);}
public override void Calculate(int index)
{
// Calculate value at specified index
// Result[index] =
}
public TimeSpan NormalizeTime(string STime)
{
DateTime TimeWithDate = Time.Date + TimeSpan.Parse(STime);
return TimeSpan.Parse(TimeWithDate.ToString("HH:mm"));
}
private void Draw_rect(string session, TimeSpan Opentime, TimeSpan Closetime, Color color, LineStyle lineStyle)
{
double Min = 0.0;
double Max = 0.0;
DateTime OpenDate, CloseDate;
int index, Openindex, Closeindex;
bool validation = true;
if (Closetime < Opentime)
{
OpenDate = Time.Date + Opentime;
CloseDate = (Time.Date + Closetime).AddDays(1);
}
else
{
OpenDate = Time.Date + Opentime;
CloseDate = Time.Date + Closetime;
}
for (int j = 0; j < Back_days; j++)
{
validation = true;
Openindex = Bars.OpenTimes.GetIndexByExactTime(OpenDate);
Closeindex = Bars.OpenTimes.GetIndexByExactTime(CloseDate);
if (Openindex < 0)
validation = false;
if (CloseDate.DayOfWeek == DayOfWeek.Saturday || CloseDate.DayOfWeek == DayOfWeek.Sunday)
validation = false;
if (validation)
{
Min = Bars[Openindex].Low;
Max = Bars[Openindex].High;
int i = Openindex;
for (i = Openindex; i < Bars.Count; i++)
{
if (Bars[i].OpenTime >= CloseDate) break;
Min = Math.Min(Bars[i].Low, Min);
Max = Math.Max(Bars[i].High, Max);
}ChartRectangle rectangle = Chart.DrawRectangle(session + i + this.ToString(), OpenDate, Min, Bars[i - 1].OpenTime, Max, color, 1, lineStyle);
if (InfiniteRange == Infinite_Range.Up)
rectangle.Y2 *= 2;
else if (InfiniteRange == Infinite_Range.Down)
rectangle.Y1 /= 2;
else if (InfiniteRange == Infinite_Range.Both)
{
rectangle.Y1 /= 2;
rectangle.Y2 *= 2;
}
if (Filled_Zones)
rectangle.IsFilled = true;
if (Show_Labels)
{
ChartText text = Chart.DrawText("text" + rectangle.Name, session, OpenDate, Max, color);
text.VerticalAlignment = VerticalAlignment.Top;
text.FontSize = 10;
text.ZIndex = 10;
}
}
OpenDate = OpenDate.AddDays(-1);
CloseDate = CloseDate.AddDays(-1);
}
}
}public class Session
{
public string name { get; set; }
public TimeSpan Open { get; set; }
public TimeSpan Close { get; set; }
public Color Color { get; set; }
public LineStyle LineStyle { get; set; }
}
}
Hi there,
It looks fine on our side. If the issue persists for the user, please ask him send us some troubleshooting info and quote the link to this discussion.
Best regards,
Panagiotis
@PanagiotisCharalampous
AlgoCreators
25 Oct 2024, 17:20
( Updated at: 26 Oct 2024, 05:45 )
RE: RE: RE: RE: RE: Indicator incompatibility on Mac
PanagiotisCharalampous said:
AlgoCreators said:
This is the source code of the indicator:
Hi there,
It looks fine on our side. If the issue persists for the user, please ask him send us some troubleshooting info and quote the link to this discussion.
Best regards,
Panagiotis
Thank you, Your presence with the programmers of CTrader is encouraging :-)
@AlgoCreators
PanagiotisCharalampous
24 Oct 2024, 11:30
Hi there,
Can you explain what is the exact problem?
Best regards,
Panagiotis
@PanagiotisCharalampous