Problem with Debugging and Chart.DrawRectangle
Problem with Debugging and Chart.DrawRectangle
06 May 2019, 23:49
Hello Community
I started to develop an indicator to draw boxes from different color of the three major sessions(Tokyo, London, New York).
My idea is go n days (by the days parameter) and draw each box(Start, High of the session, Low of the session, End of the session) for the past sessions in x days. I have some intermediate robot skill. I am using the same editor provided by Ctrader, currently I do not have Visual Studio...
I have the following problems:
1- There is no Print() for the indicator no way to get some answer why something is not working.
2- I performed some calculations in the protected override void Initialize() to get the session data to draw the rectangle but nothing is showed in the Chart. Can someone bring some light here....
// These namespaces are required for a cAlgo indicator. // They contain basic classes of the C# language, and the cAlgo API. // The last namespace is required for referencing build-in // indicators such as SimpleMovingAverage, BollingerBands, etc. using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; // Define indicators within the cAlgo.Indicators namespace namespace cAlgo.Indicators { // The Indicator class declaration must be preceded by the indicator attribute, // [Indicator()], and it should be a public // Indicator derived class [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)] public class SessionIndicator : Indicator { // The parameter attribute is necessary if the program will contain user input. [Parameter("TokioTimeStart", DefaultValue = 0)] public int TokioTimeStart { get; set; } [Parameter("TokioTimeEnd", DefaultValue = 7)] public int TokioTimeEnd { get; set; } [Parameter("LondonTimeStart", DefaultValue = 7)] public int LondonTimeStart { get; set; } [Parameter("LondonTimeEnd", DefaultValue = 16)] public int LondonTimeEnd { get; set; } [Parameter("NYTimeStart", DefaultValue = 12)] public int NYTimeStart { get; set; } [Parameter("NYTimeEnd", DefaultValue = 20)] public int NYTimeEnd { get; set; } [Parameter("Days", DefaultValue = 1)] public int Days { get; set; } // The Output attribute is used to display the Output of // an Indicator series on the chart. [Output("Main")] public IndicatorDataSeries Result { get; set; } // The Initialize method is called upon loading of an indicator. // It is typically used to initialize variables and series such as nested indicators. protected override void Initialize() { // Let is clear all the shit of Chart... Chart.RemoveAllObjects(); // First let is get interactive the dates. var actualdate = Server.Time.Date; for (int i = 1; i <= Days; i++) { // We have the Date now we need to get the Sessions data(Tokio,Londres,New York) var dinamycDate = actualdate.Date.AddDays(-1 * i); // Tokio Start and End by DateTime DateTime tok_start = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, TokioTimeStart, 0, 0); DateTime tok_end = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, TokioTimeEnd, 0, 0); DateTime London_start = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, LondonTimeStart, 0, 0); DateTime London_end = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, LondonTimeEnd, 0, 0); DateTime NY_start = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, NYTimeStart, 0, 0); DateTime NY_end = new DateTime(dinamycDate.Year, dinamycDate.Month, dinamycDate.Day, NYTimeEnd, 0, 0); Session TOKIO = getSession(dinamycDate, "TOKIO", tok_start, tok_end); //Session LONDON = getSession(dinamycDate, "LONDON", London_start, London_end); //Session NY = getSession(dinamycDate, "NY", tok_start, tok_end); Print("TOKIO SESSION DATA --> DATE: {0} MAX PRICE:{1}, MIN PRICE:{2}", TOKIO.Date, TOKIO.MaxPrice, TOKIO.MinPrice); // Showing nothing in the chart Chart.DrawRectangle("TOKIX", TOKIO.SesStart, TOKIO.MinPrice, TOKIO.SesDateTimeEnd, TOKIO.MaxPrice, Color.Aquamarine); } } // The calculate method cannot be ommited. // It is the main method of an indicator. // It is called on each historical bar defined by the index and in real time on each incoming tick. public override void Calculate(int index) { } public Session getSession(DateTime date, string ses, DateTime Tstart, DateTime Tend) { Session returner = new Session(); double maxprice = 0; double minprice = 0; double startprice = 0; double endprice = 0; // Let is iterate // We need to find( Max Price, Min Price of the Session) for (int i = 1; i < MarketSeries.High.Count; i++) { var opentime = MarketSeries.OpenTime.Last(i); // We set as reference the minprice and maxprice of the last candle of the session as a way to have a start point to compare. if (opentime == Tend) { minprice = MarketSeries.Low.Last(i); maxprice = MarketSeries.High.Last(i); endprice = MarketSeries.Close.Last(i); } // We will find Min and Max price of the session by recurrent for. if (opentime <= Tend && opentime >= Tstart) { // Let is get the current candle in the i and compare the values var min = MarketSeries.Low.Last(i); var max = MarketSeries.High.Last(i); // We detect a new max in our iteration if (max > maxprice) { maxprice = max; } // We detect a new max in our iteration if (min < minprice) { minprice = min; } } if (opentime == Tstart) { startprice = MarketSeries.Open.Last(i); break; } } // End Bucle For // Let is create our Session Object Session brandnew = new Session(date, ses, Tstart, startprice, maxprice, minprice, endprice, Tend); returner = brandnew; return returner; } } public class Session { public DateTime Date; public string SessionName; public DateTime SesStart; public double StartPrice; public double MaxPrice; public double MinPrice; public double EndPrice; public DateTime SesDateTimeEnd; public Session() { } public Session(DateTime date, string sessionname, DateTime sestart, double startprice, double maxprice, double minprice, double endprice, DateTime sesdatetimend) { this.Date = date; this.SessionName = sessionname; this.SesStart = sestart; this.StartPrice = startprice; this.MaxPrice = maxprice; this.MinPrice = minprice; this.EndPrice = endprice; this.SesDateTimeEnd = sesdatetimend; } } }
Thanks in advance....
PanagiotisCharalampous
07 May 2019, 10:37 ( Updated at: 21 Dec 2023, 09:21 )
Hi erisoftdevelop,
Print function for indicators works only for the Automate section. I tried the indicator and the rectangle seems to draw fine. See below
Best Regards,
Panagiotis
@PanagiotisCharalampous