MarketSeries: getting the Date right

Created at 08 Feb 2016, 16:22
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
MaVe's avatar

MaVe

Joined 24.08.2015

MarketSeries: getting the Date right
08 Feb 2016, 16:22


I still don't know how to fix this problem.

The sunday dailyOpen line (Colors.Wheat) should be solid like the other days of the week.

I think the problem is at line 51:

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AutoRescale = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MaveTest : Indicator
    {
        [Parameter("High Color", DefaultValue = "SeaGreen")]
        public string Highcolor { get; set; }
        [Parameter("Low Color", DefaultValue = "Tomato")]
        public string Lowcolor { get; set; }
        [Parameter("Show Open", DefaultValue = false)]
        public bool ShowDailyOpen { get; set; }
        [Parameter("Open Color", DefaultValue = "Wheat")]
        public string Opencolor { get; set; }
        [Parameter("Show Previous Close", DefaultValue = true)]
        public bool ShowPreviousDailyClose { get; set; }
        [Parameter("Previous Close Color", DefaultValue = "Blue")]
        public string Closecolor { get; set; }
        private Colors Ocolor;
        private Colors Hcolor;
        private Colors Lcolor;
        private Colors Ccolor;
// ------------------------------------------------------
        protected override void Initialize()
        {
            Enum.TryParse(Opencolor, out Ocolor);
            Enum.TryParse(Highcolor, out Hcolor);
            Enum.TryParse(Lowcolor, out Lcolor);
            Enum.TryParse(Closecolor, out Ccolor);
        }
// ------------------------------------------------------
        public override void Calculate(int index)
        {
            DateTime today = MarketSeries.OpenTime[index].Date;
            DateTime today1 = today.AddDays(1);
            DateTime today2 = today.AddDays(2);
            DateTime today3 = today.AddDays(3);
            DateTime today4 = today.AddDays(4);
            double open = MarketSeries.Open[MarketSeries.Open.Count];
            double high = MarketSeries.High[MarketSeries.High.Count - 1];
            double low = MarketSeries.Low[MarketSeries.Low.Count - 1];
            double close = MarketSeries.Close[MarketSeries.Close.Count - 1];
// ----- 
            for (int i = MarketSeries.Close.Count - 1; i > 0; i--)
            {
                if (MarketSeries.OpenTime[i].Date == today)
                    break;
                high = Math.Max(high, MarketSeries.High[i]);
                low = Math.Min(low, MarketSeries.Low[i]);
            }
// ----- DailyOpen
            if (ShowDailyOpen)
                ChartObjects.DrawLine("Open" + today, today1, open, today2, open, Ocolor, 1);
            if (ShowDailyOpen)
                ChartObjects.DrawLine("pOpen" + today, today2, open, today3, open, Ocolor, 1, LineStyle.Lines);
            if (ShowDailyOpen)
                ChartObjects.DrawLine("ppOpen" + today, today3, open, today4, open, Ocolor, 1, LineStyle.DotsRare);
// ----- Triple DailyHighLow
            ChartObjects.DrawLine("High" + today, today, high, today1, high, Hcolor, 1);
            ChartObjects.DrawLine("Low" + today, today, low, today1, low, Lcolor, 1);
            ChartObjects.DrawLine("pHigh" + today, today1, high, today2, high, Hcolor, 1, LineStyle.Lines);
            ChartObjects.DrawLine("pLow" + today, today1, low, today2, low, Lcolor, 1, LineStyle.Lines);
            ChartObjects.DrawLine("ppHigh" + today, today2, high, today3, high, Hcolor, 1, LineStyle.LinesDots);
            ChartObjects.DrawLine("ppLow" + today, today2, low, today3, low, Lcolor, 1, LineStyle.LinesDots);
            ChartObjects.DrawText("High-Text", "  High", index, high, VerticalAlignment.Bottom, HorizontalAlignment.Right, Hcolor);
            ChartObjects.DrawText("Low-Text", "  Low", index, low, VerticalAlignment.Top, HorizontalAlignment.Right, Lcolor);
// ----- PreviousClose
            if (ShowPreviousDailyClose)
                ChartObjects.DrawLine("pClose" + today, today1, close, today2, close, Ccolor, 1, LineStyle.Lines);
            if (ShowPreviousDailyClose)
                ChartObjects.DrawLine("ppClose" + today, today2, close, today3, close, Ccolor, 1, LineStyle.DotsRare);
        }
    }
}

 


@MaVe
Replies

MaVe
10 Feb 2016, 10:22

Anybody...to solve this problem.


@MaVe

MaVe
12 Feb 2016, 10:00

Problem solved.


@MaVe