Reduce infinity value

Created at 17 May 2023, 11:35
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!
Tspring's avatar

Tspring

Joined 11.02.2021

Reduce infinity value
17 May 2023, 11:35


Hello

How can I reduce the calculation of days for this indicator?

It's a forex session indicator, but the person who created it left the days value at infinity. My cTrader cannot support it.

This is the code:

 

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 MultiSessionOpen : Indicator
    {
        [Parameter("London Session", DefaultValue = true)]
        public bool london { get; set; }
        [Parameter("NY Session", DefaultValue = true)]
        public bool NY { get; set; }
        [Parameter("Sydney Session", DefaultValue = true)]
        public bool sydney { get; set; }
        [Parameter("Tokyo Session", DefaultValue = true)]
        public bool tokyo { get; set; }

        [Parameter("Show Open Prices", DefaultValue = true)]
        public bool openPrices { get; set; }

        [Parameter("Show Info", DefaultValue = true)]
        public bool info { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private MarketSeries openSeries;


        protected override void Initialize()
        {
            openSeries = MarketData.GetSeries(TimeFrame.Hour);
        }

        public override void Calculate(int index)
        {
            //London Session
            string today = MarketSeries.OpenTime[index].Day.ToString() + "/" + MarketSeries.OpenTime[index].Month.ToString() + "/" + MarketSeries.OpenTime[index].Year.ToString() + " ";
            if (london)
            {
                DateTime londonOpen, londonClose;
                DateTime.TryParse(today + "07:00:00", out londonOpen);
                DateTime.TryParse(today + "15:00:00", out londonClose);
                double londonMax = 0, londonMin = double.PositiveInfinity;
                londonOpen = londonOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                londonClose = londonClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(londonOpen); i < MarketSeries.OpenTime.GetIndexByTime(londonClose); i++)
                {
                    londonMax = Math.Max(londonMax, MarketSeries.High[i]);
                    londonMin = Math.Min(londonMin, MarketSeries.Low[i]);
                }
                double londonPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)]) / Symbol.PipSize, 2);
                Chart.DrawRectangle("london session " + londonOpen, londonOpen, londonMax, londonClose, londonMin, Color.FromArgb(50, 0, 50, 255)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawTrendLine("_open london" + londonOpen, londonOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], londonClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], Color.Blue);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawStaticText("london info", "Pips From London Open: " + londonPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
                        else
                            Chart.DrawStaticText("london info", "Pips From London Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);

            }

            //NY Session
            if (NY)
            {
                DateTime nyOpen, nyClose;
                DateTime.TryParse(today + "12:00:00", out nyOpen);
                DateTime.TryParse(today + "20:00:00", out nyClose);
                double nyMax = 0, nyMin = double.PositiveInfinity;
                nyOpen = nyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                nyClose = nyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(nyOpen); i < MarketSeries.OpenTime.GetIndexByTime(nyClose); i++)
                {
                    nyMax = Math.Max(nyMax, MarketSeries.High[i]);
                    nyMin = Math.Min(nyMin, MarketSeries.Low[i]);
                }
                double nyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)]) / Symbol.PipSize, 2);
                Chart.DrawRectangle("ny session " + nyOpen, nyOpen, nyMax, nyClose, nyMin, Color.FromArgb(50, 255, 50, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawTrendLine("_open ny" + nyOpen, nyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], nyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], Color.Red);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: " + nyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
                        else
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);


            }

            //Sydney Session
            string yesterday = MarketSeries.OpenTime[index].AddDays(-1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Year.ToString() + " ";
            string tommorow = MarketSeries.OpenTime[index].AddDays(1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Year.ToString() + " ";
            if (sydney)
            {
                DateTime sydneyOpen, sydneyClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? yesterday + "22:00:00" : today + "22:00:00", out sydneyOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? today + "6:00:00" : tommorow + "6:00:00", out sydneyClose);
                double sydneyMax = 0, sydneyMin = double.PositiveInfinity;
                sydneyOpen = sydneyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                sydneyClose = sydneyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(sydneyOpen); i < MarketSeries.OpenTime.GetIndexByTime(sydneyClose); i++)
                {
                    sydneyMax = Math.Max(sydneyMax, MarketSeries.High[i]);
                    sydneyMin = Math.Min(sydneyMin, MarketSeries.Low[i]);
                }
                double sydneyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)]) / Symbol.PipSize, 2);
                Chart.DrawRectangle("sydney session " + sydneyOpen, sydneyOpen, sydneyMax, sydneyClose, sydneyMin, Color.FromArgb(50, 50, 255, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawTrendLine("_open sydney" + sydneyOpen, sydneyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], sydneyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], Color.LawnGreen);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawStaticText("sydney info", "\n\nPips From Sydney Open: " + sydneyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.LawnGreen);

            }

            //Tokyo Session
            if (tokyo)
            {
                DateTime tokyoOpen, tokyoClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? yesterday + "23:00:00" : today + "23:00:00", out tokyoOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? today + "7:00:00" : tommorow + "7:00:00", out tokyoClose);
                double tokyoMax = 0, tokyoMin = double.PositiveInfinity;
                tokyoOpen = tokyoOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                tokyoClose = tokyoClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(tokyoOpen); i < MarketSeries.OpenTime.GetIndexByTime(tokyoClose); i++)
                {
                    tokyoMax = Math.Max(tokyoMax, MarketSeries.High[i]);
                    tokyoMin = Math.Min(tokyoMin, MarketSeries.Low[i]);
                }
                double tokyoPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)]) / Symbol.PipSize, 2);
                Chart.DrawRectangle("tokyo session " + tokyoOpen, tokyoOpen, tokyoMax, tokyoClose, tokyoMin, Color.FromArgb(50, 255, 255, 50)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawTrendLine("_open tokyo" + tokyoOpen, tokyoOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], tokyoClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], Color.Yellow);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawStaticText("tokyo info", "\n\n\nPips From Tokyo Open: " + tokyoPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Yellow);

            }

        }
    }
}

 

 


@Tspring
Replies

pick
17 May 2023, 12:56

It looks as if the error is coming from the drawing methods. A quick solution could be to just check if the values are normal before calling the drawing methods. Here is the london session part edited to a state I'd expect it to be working better, you will need to do the same for the other sessions.

 

if (london)
{
	DateTime londonOpen, londonClose;
	DateTime.TryParse(today + "07:00:00", out londonOpen);
	DateTime.TryParse(today + "15:00:00", out londonClose);
	double londonMax = 0, londonMin = double.PositiveInfinity;
	londonOpen = londonOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
	londonClose = londonClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
	
	for (int i = MarketSeries.OpenTime.GetIndexByTime(londonOpen); i < MarketSeries.OpenTime.GetIndexByTime(londonClose); i++)
	{
		londonMax = Math.Max(londonMax, MarketSeries.High[i]);
		londonMin = Math.Min(londonMin, MarketSeries.Low[i]);
	}
	double londonPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)]) / Symbol.PipSize, 2);
	
	if (double.IsNormal(londonMin) && double.IsNormal(londonMax) && double.IsNormal(londonPrice)) //Check all values are normal
	{ //
	
		Chart.DrawRectangle("london session " + londonOpen, londonOpen, londonMax, londonClose, londonMin, Color.FromArgb(50, 0, 50, 255)).IsFilled = true;
		if (openPrices)
			if (TimeFrame <= TimeFrame.Hour)
				if (MarketSeries.OpenTime[index] >= londonOpen)
					Chart.DrawTrendLine("_open london" + londonOpen, londonOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], londonClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], Color.Blue);
		if (info)
			if (TimeFrame <= TimeFrame.Hour)
				if (MarketSeries.OpenTime[index] >= londonOpen)
					Chart.DrawStaticText("london info", "Pips From London Open: " + londonPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
				else
					Chart.DrawStaticText("london info", "Pips From London Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
	} //
}

 


@pick

Tspring
17 May 2023, 14:42

Hi, thanks for your help.

This is my first attempt to modify a code without knowing anything about programming at all.
Comparing the original code with the one you sent me, it seems to me that the only difference is this additional string:

if (double.IsNormal(londonMin) && double.IsNormal(londonMax) && double.IsNormal(londonPrice)) //Check all values are normal
{ //

So following your instructions I took the string in question and copied and pasted it to all the other sessions, replacing only the name of each session.
At the end I clicked on build but some errors came up.


This is the complete modified code:

 

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 MultiSessionOpen2 : Indicator
    {
        [Parameter("London Session", DefaultValue = true)]
        public bool london { get; set; }
        [Parameter("NY Session", DefaultValue = true)]
        public bool NY { get; set; }
        [Parameter("Sydney Session", DefaultValue = true)]
        public bool sydney { get; set; }
        [Parameter("Tokyo Session", DefaultValue = true)]
        public bool tokyo { get; set; }

        [Parameter("Show Open Prices", DefaultValue = true)]
        public bool openPrices { get; set; }

        [Parameter("Show Info", DefaultValue = true)]
        public bool info { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private MarketSeries openSeries;


        protected override void Initialize()
        {
            openSeries = MarketData.GetSeries(TimeFrame.Hour);
        }

        public override void Calculate(int index)
        {
            //London Session
            string today = MarketSeries.OpenTime[index].Day.ToString() + "/" + MarketSeries.OpenTime[index].Month.ToString() + "/" + MarketSeries.OpenTime[index].Year.ToString() + " ";
            if (london)
            {
                DateTime londonOpen, londonClose;
                DateTime.TryParse(today + "07:00:00", out londonOpen);
                DateTime.TryParse(today + "15:00:00", out londonClose);
                double londonMax = 0, londonMin = double.PositiveInfinity;
                londonOpen = londonOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                londonClose = londonClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(londonOpen); i < MarketSeries.OpenTime.GetIndexByTime(londonClose); i++)
                {
                    londonMax = Math.Max(londonMax, MarketSeries.High[i]);
                    londonMin = Math.Min(londonMin, MarketSeries.Low[i]);
                }
                double londonPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(londonMin) && double.IsNormal(londonMax) && double.IsNormal(londonPrice)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("london session " + londonOpen, londonOpen, londonMax, londonClose, londonMin, Color.FromArgb(50, 0, 50, 255)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawTrendLine("_open london" + londonOpen, londonOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], londonClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], Color.Blue);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawStaticText("london info", "Pips From London Open: " + londonPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
                        else
                            Chart.DrawStaticText("london info", "Pips From London Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);

            }

            //NY Session
            if (NY)
            {
                DateTime nyOpen, nyClose;
                DateTime.TryParse(today + "12:00:00", out nyOpen);
                DateTime.TryParse(today + "20:00:00", out nyClose);
                double nyMax = 0, nyMin = double.PositiveInfinity;
                nyOpen = nyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                nyClose = nyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(nyOpen); i < MarketSeries.OpenTime.GetIndexByTime(nyClose); i++)
                {
                    nyMax = Math.Max(nyMax, MarketSeries.High[i]);
                    nyMin = Math.Min(nyMin, MarketSeries.Low[i]);
                }
                double nyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(nyMin) && double.IsNormal(nyMax) && double.IsNormal(nyPrice)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("ny session " + nyOpen, nyOpen, nyMax, nyClose, nyMin, Color.FromArgb(50, 255, 50, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawTrendLine("_open ny" + nyOpen, nyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], nyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], Color.Red);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: " + nyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
                        else
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);


            }

            //Sydney Session
            string yesterday = MarketSeries.OpenTime[index].AddDays(-1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Year.ToString() + " ";
            string tommorow = MarketSeries.OpenTime[index].AddDays(1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Year.ToString() + " ";
            if (sydney)
            {
                DateTime sydneyOpen, sydneyClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? yesterday + "22:00:00" : today + "22:00:00", out sydneyOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? today + "6:00:00" : tommorow + "6:00:00", out sydneyClose);
                double sydneyMax = 0, sydneyMin = double.PositiveInfinity;
                sydneyOpen = sydneyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                sydneyClose = sydneyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(sydneyOpen); i < MarketSeries.OpenTime.GetIndexByTime(sydneyClose); i++)
                {
                    sydneyMax = Math.Max(sydneyMax, MarketSeries.High[i]);
                    sydneyMin = Math.Min(sydneyMin, MarketSeries.Low[i]);
                }
                double sydneyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(sydneyMin) && double.IsNormal(sydneyMax) && double.IsNormal(sydneyPrice)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("sydney session " + sydneyOpen, sydneyOpen, sydneyMax, sydneyClose, sydneyMin, Color.FromArgb(50, 50, 255, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawTrendLine("_open sydney" + sydneyOpen, sydneyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], sydneyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], Color.LawnGreen);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawStaticText("sydney info", "\n\nPips From Sydney Open: " + sydneyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.LawnGreen);

            }

            //Tokyo Session
            if (tokyo)
            {
                DateTime tokyoOpen, tokyoClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? yesterday + "23:00:00" : today + "23:00:00", out tokyoOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? today + "7:00:00" : tommorow + "7:00:00", out tokyoClose);
                double tokyoMax = 0, tokyoMin = double.PositiveInfinity;
                tokyoOpen = tokyoOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                tokyoClose = tokyoClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(tokyoOpen); i < MarketSeries.OpenTime.GetIndexByTime(tokyoClose); i++)
                {
                    tokyoMax = Math.Max(tokyoMax, MarketSeries.High[i]);
                    tokyoMin = Math.Min(tokyoMin, MarketSeries.Low[i]);
                }
                double tokyoPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(tokyoMin) && double.IsNormal(tokyoMax) && double.IsNormal(tokyoPrice)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("tokyo session " + tokyoOpen, tokyoOpen, tokyoMax, tokyoClose, tokyoMin, Color.FromArgb(50, 255, 255, 50)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawTrendLine("_open tokyo" + tokyoOpen, tokyoOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], tokyoClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], Color.Yellow);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawStaticText("tokyo info", "\n\n\nPips From Tokyo Open: " + tokyoPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Yellow);

            }

        }
    }
}

 


@Tspring

pick
17 May 2023, 14:49 ( Updated at: 21 Dec 2023, 09:23 )

RE:

o.o.d.exp said:

Hi, thanks for your help.

This is my first attempt to modify a code without knowing anything about programming at all.
Comparing the original code with the one you sent me, it seems to me that the only difference is this additional string:

if (double.IsNormal(londonMin) && double.IsNormal(londonMax) && double.IsNormal(londonPrice)) //Check all values are normal
{ //

So following your instructions I took the string in question and copied and pasted it to all the other sessions, replacing only the name of each session.
At the end I clicked on build but some errors came up.


This is the complete modified code:

--

 

It looks like you have missed the final closing curly brace. Look in my previous response for the line that is simply just "} //" which comes after the "Chart.DrawStaticText" line. Other than that, it looks good.


@pick

Tspring
17 May 2023, 16:03

Thank you, I succeeded. Now cTrader no longer gives me the error.
However, now it does not always draw the most recent sessions, as you can see in the picture.

And besides that it has a couple of other things to fix.
I don't think I'll be able to fix it completely even with your help, also because it doesn't seem fair to me to monopolize your time.

Do you happen to do programming work in exchange for payment?

 


@Tspring

pick
17 May 2023, 17:13 ( Updated at: 21 Dec 2023, 09:23 )

RE:

o.o.d.exp said:

Thank you, I succeeded. Now cTrader no longer gives me the error.
However, now it does not always draw the most recent sessions, as you can see in the picture.

And besides that it has a couple of other things to fix.
I don't think I'll be able to fix it completely even with your help, also because it doesn't seem fair to me to monopolize your time.

Do you happen to do programming work in exchange for payment?

 

At least there's some progress on the error side. I just ran the indicator for the first time and that also appeared to be the case for me. Removing the normal check for the "londonPrice", "nyPrice" etc brought it back to drawing at current time (on my end, at least) without the error prompting. 

Changing from: 

if (double.IsNormal(londonMin) && double.IsNormal(londonMax) && double.IsNormal(londonPrice))
{

to: 

if (double.IsNormal(londonMin) && double.IsNormal(londonMax))

 

 

At the moment, I don't offer any paid services, but if you require more help: there is a Telegram group for cTrader programming help in which I occasionally look at. Or of course, feel free to post here and if I see it, I'm more than happy to chime in if necessary!


@pick

Tspring
17 May 2023, 18:51

Thanks, it's a real blessing to find helpful people like you!
I also made the last change you made, and it seems to work fine now. It has improved considerably, the first version was constantly causing cTrader to freeze every time I changed timeframe, and I always had to force close it and restart it.
I think the problem is due to the fact that the sessions drawn on the chart by the indicator are infinite! The person who created the indicator did not provide a parameter for setting a customised number of sessions. In fact, although it is much better now, it always seems a bit cumbersome for the platform to have to calculate infinite sessions backwards in time, when it could calculate three or four at most.
So going back to the title of my first post, what would it take to reduce that infinite value and be able to enter a custom value of sessions, so that everything runs smoother?
For example, I have a pivot point indicator that has a parameter to select the number of days back in time on which to calculate pivots (see image). Could I copy and paste that part of the code from the pivot indicator to the forex session indicator?

 


@Tspring

pick
17 May 2023, 19:11 ( Updated at: 21 Dec 2023, 09:23 )

RE:

o.o.d.exp said:

Thanks, it's a real blessing to find helpful people like you!
I also made the last change you made, and it seems to work fine now. It has improved considerably, the first version was constantly causing cTrader to freeze every time I changed timeframe, and I always had to force close it and restart it.
I think the problem is due to the fact that the sessions drawn on the chart by the indicator are infinite! The person who created the indicator did not provide a parameter for setting a customised number of sessions. In fact, although it is much better now, it always seems a bit cumbersome for the platform to have to calculate infinite sessions backwards in time, when it could calculate three or four at most.
So going back to the title of my first post, what would it take to reduce that infinite value and be able to enter a custom value of sessions, so that everything runs smoother?
For example, I have a pivot point indicator that has a parameter to select the number of days back in time on which to calculate pivots (see image). Could I copy and paste that part of the code from the pivot indicator to the forex session indicator?

 

Apologies - I didn't realise that's what you wanted! 

If you add a parameter:

[Parameter("MaxDays", DefaultValue = 5)]
public int maxDays { get; set; }

Add a global variable (it can be right below the line above, it just needs to be outside of a method - but inside the class):

DateTime newestTime; //Track newest time

Then, in the Initialize function, set a starting value:

protected override void Initialize()
{
	openSeries = MarketData.GetSeries(TimeFrame.Hour);
	newestTime = Bars[^1].OpenTime; //Set starting value
}

Then, at the top of the Calculate function, check if the bar calculating is too old:

public override void Calculate(int index)
{
	DateTime time = Bars[index].OpenTime; //Get time of bar calculating

	if (time > newestTime) //If it's newer than the newest time
		newestTime = time; //Update newest time

	if (time < newestTime.AddDays(-maxDays)) //Check if it's too old
		return; //Return out of method

	//Below is code that was already there...
	//London Session
	string today = Bars.OpenTimes[index].Day.ToString() + "/" + Bars.OpenTimes[index].Month.ToString() + "/" + Bars.OpenTimes[index].Year.ToString() + " ";
	if (london)
	{
     .........

 

That should hopefully provide you with some filtering. Keep in mind that this count will include weekends, so it won't show 5 trading days. 


@pick

Tspring
17 May 2023, 19:54

Even though you didn't realise what I wanted, the indicator has improved a lot thanks to your advice!
I have now tried to add the code you told me, trying to be as precise as possible, but I get errors...


@Tspring

pick
17 May 2023, 19:59 ( Updated at: 21 Dec 2023, 09:23 )

RE:

o.o.d.exp said:

Even though you didn't realise what I wanted, the indicator has improved a lot thanks to your advice!
I have now tried to add the code you told me, trying to be as precise as possible, but I get errors...

Sorry, I didn't realise what version of C# you were compiling. Change:

newestTime = Bars[^1].OpenTime;

to:

newestTime = Bars[Bars.Count - 1].OpenTime;

Also, it looks like you have an extra opening curly brace on line 52 in your screenshot - just delete that and the rest looks good.


@pick

Tspring
17 May 2023, 20:38

Great, I was able to successfully modify the indicator thanks to your help! Once it is perfected I will post the code so anyone who wants can download it.
I have one more question: the indicator draws horizontal opening session lines on the traditional candlestick chart, but when I change to heiken ashi candlesticks, the opening price lines disappear.
I assume this is because heiken ashi candles have a different calculation method to regular candles, so there is probably nothing to do about it.

Do you think this is the problem, or is it possible to fix this?


@Tspring

pick
18 May 2023, 19:26 ( Updated at: 21 Dec 2023, 09:23 )

RE:

o.o.d.exp said:

Great, I was able to successfully modify the indicator thanks to your help! Once it is perfected I will post the code so anyone who wants can download it.
I have one more question: the indicator draws horizontal opening session lines on the traditional candlestick chart, but when I change to heiken ashi candlesticks, the opening price lines disappear.
I assume this is because heiken ashi candles have a different calculation method to regular candles, so there is probably nothing to do about it.

Do you think this is the problem, or is it possible to fix this?


You posted just after I went off yesterday - so I've just seen this. I've never worked with Heiken Ashi charts, but I'd assume it's due to the timeframe check:

if (openPrices)
	if (TimeFrame <= TimeFrame.Hour) //Here
		if (MarketSeries.OpenTime[index] >= londonOpen)
			Chart.DrawTrendLine("_open london" + londonOpen, londonOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], londonClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], Color.Blue);

If you change that to include Heikin timeframes, it may provide you a result:

if (TimeFrame <= TimeFrame.Hour || TimeFrame <= TimeFrame.HeikinHour)

Having not used Heikin Ashi charts before, but just having a light read about them, I'd assume this will produce a different value than if it were ran off of a standard timeframe. Give it a go and let me know how it goes!


@pick

Tspring
18 May 2023, 19:57

Hi, don't worry, I too disconnected from the computer shortly after the last post.
I tried replacing the string with the one you pointed out to me without success, the session opening prices keep disappearing on the H.A. chart.
This is the complete modified code in case I did something wrong:

 

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 MultiSessionOpen22 : Indicator
    {
        [Parameter("London Session", DefaultValue = true)]
        public bool london { get; set; }
        [Parameter("NY Session", DefaultValue = true)]
        public bool NY { get; set; }
        [Parameter("Sydney Session", DefaultValue = true)]
        public bool sydney { get; set; }
        [Parameter("Tokyo Session", DefaultValue = true)]
        public bool tokyo { get; set; }

        [Parameter("Show Open Prices", DefaultValue = true)]
        public bool openPrices { get; set; }

        [Parameter("Show Info", DefaultValue = true)]
        public bool info { get; set; }
        
        [Parameter("MaxDays", DefaultValue = 5)]
        public int maxDays { get; set; }
        DateTime newestTime; //Track newest time

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private MarketSeries openSeries;


        protected override void Initialize()
        {
            openSeries = MarketData.GetSeries(TimeFrame.Hour);
            newestTime = Bars[Bars.Count - 1].OpenTime;
        }

        public override void Calculate(int index)
        {
                DateTime time = Bars[index].OpenTime; //Get time of bar calculating

                if (time > newestTime) //If it's newer than the newest time
                        newestTime = time; //Update newest time

                if (time < newestTime.AddDays(-maxDays)) //Check if it's too old
                        return; //Return out of method
        
            //London Session
            string today = MarketSeries.OpenTime[index].Day.ToString() + "/" + MarketSeries.OpenTime[index].Month.ToString() + "/" + MarketSeries.OpenTime[index].Year.ToString() + " ";
            if (london)
            {
                DateTime londonOpen, londonClose;
                DateTime.TryParse(today + "07:00:00", out londonOpen);
                DateTime.TryParse(today + "15:00:00", out londonClose);
                double londonMax = 0, londonMin = double.PositiveInfinity;
                londonOpen = londonOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                londonClose = londonClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(londonOpen); i < MarketSeries.OpenTime.GetIndexByTime(londonClose); i++)
                {
                    londonMax = Math.Max(londonMax, MarketSeries.High[i]);
                    londonMin = Math.Min(londonMin, MarketSeries.Low[i]);
                }
                double londonPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(londonMin) && double.IsNormal(londonMax)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("london session " + londonOpen, londonOpen, londonMax, londonClose, londonMin, Color.FromArgb(50, 0, 50, 255)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour || TimeFrame <= TimeFrame.HeikinHour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawTrendLine("_open london" + londonOpen, londonOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], londonClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(londonOpen)], Color.Blue);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= londonOpen)
                            Chart.DrawStaticText("london info", "Pips From London Open: " + londonPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
                        else
                            Chart.DrawStaticText("london info", "Pips From London Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.RoyalBlue);
                } //           

            }

            //NY Session
            if (NY)
            {
                DateTime nyOpen, nyClose;
                DateTime.TryParse(today + "12:00:00", out nyOpen);
                DateTime.TryParse(today + "20:00:00", out nyClose);
                double nyMax = 0, nyMin = double.PositiveInfinity;
                nyOpen = nyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                nyClose = nyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(nyOpen); i < MarketSeries.OpenTime.GetIndexByTime(nyClose); i++)
                {
                    nyMax = Math.Max(nyMax, MarketSeries.High[i]);
                    nyMin = Math.Min(nyMin, MarketSeries.Low[i]);
                }
                double nyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(nyMin) && double.IsNormal(nyMax)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("ny session " + nyOpen, nyOpen, nyMax, nyClose, nyMin, Color.FromArgb(50, 255, 50, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour || TimeFrame <= TimeFrame.HeikinHour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawTrendLine("_open ny" + nyOpen, nyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], nyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(nyOpen)], Color.Red);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= nyOpen)
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: " + nyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
                        else
                            Chart.DrawStaticText("ny info", "\nPips From NY Open: Waiting for Open", VerticalAlignment.Top, HorizontalAlignment.Right, Color.Red);
                } //           


            }

            //Sydney Session
            string yesterday = MarketSeries.OpenTime[index].AddDays(-1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(-1).Year.ToString() + " ";
            string tommorow = MarketSeries.OpenTime[index].AddDays(1).Day.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Month.ToString() + "/" + MarketSeries.OpenTime[index].AddDays(1).Year.ToString() + " ";
            if (sydney)
            {
                DateTime sydneyOpen, sydneyClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? yesterday + "22:00:00" : today + "22:00:00", out sydneyOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 6 ? today + "6:00:00" : tommorow + "6:00:00", out sydneyClose);
                double sydneyMax = 0, sydneyMin = double.PositiveInfinity;
                sydneyOpen = sydneyOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                sydneyClose = sydneyClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(sydneyOpen); i < MarketSeries.OpenTime.GetIndexByTime(sydneyClose); i++)
                {
                    sydneyMax = Math.Max(sydneyMax, MarketSeries.High[i]);
                    sydneyMin = Math.Min(sydneyMin, MarketSeries.Low[i]);
                }
                double sydneyPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(sydneyMin) && double.IsNormal(sydneyMax)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("sydney session " + sydneyOpen, sydneyOpen, sydneyMax, sydneyClose, sydneyMin, Color.FromArgb(50, 50, 255, 0)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour || TimeFrame <= TimeFrame.HeikinHour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawTrendLine("_open sydney" + sydneyOpen, sydneyOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], sydneyClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(sydneyOpen)], Color.LawnGreen);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= sydneyOpen)
                            Chart.DrawStaticText("sydney info", "\n\nPips From Sydney Open: " + sydneyPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.LawnGreen);
                } //            

            }

            //Tokyo Session
            if (tokyo)
            {
                DateTime tokyoOpen, tokyoClose;
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? yesterday + "23:00:00" : today + "23:00:00", out tokyoOpen);
                DateTime.TryParse(MarketSeries.OpenTime[index].Hour <= 7 ? today + "7:00:00" : tommorow + "7:00:00", out tokyoClose);
                double tokyoMax = 0, tokyoMin = double.PositiveInfinity;
                tokyoOpen = tokyoOpen.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                tokyoClose = tokyoClose.AddHours(MarketSeries.OpenTime[index].IsDaylightSavingTime() ? 1 : 0);
                for (int i = MarketSeries.OpenTime.GetIndexByTime(tokyoOpen); i < MarketSeries.OpenTime.GetIndexByTime(tokyoClose); i++)
                {
                    tokyoMax = Math.Max(tokyoMax, MarketSeries.High[i]);
                    tokyoMin = Math.Min(tokyoMin, MarketSeries.Low[i]);
                }
                double tokyoPrice = Math.Round((MarketSeries.Close[index] - openSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)]) / Symbol.PipSize, 2);
                
                if (double.IsNormal(tokyoMin) && double.IsNormal(tokyoMax)) //Check all values are normal
                { //
                
                Chart.DrawRectangle("tokyo session " + tokyoOpen, tokyoOpen, tokyoMax, tokyoClose, tokyoMin, Color.FromArgb(50, 255, 255, 50)).IsFilled = true;
                if (openPrices)
                    if (TimeFrame <= TimeFrame.Hour || TimeFrame <= TimeFrame.HeikinHour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawTrendLine("_open tokyo" + tokyoOpen, tokyoOpen, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], tokyoClose, MarketSeries.Open[MarketSeries.OpenTime.GetIndexByTime(tokyoOpen)], Color.Yellow);
                if (info)
                    if (TimeFrame <= TimeFrame.Hour)
                        if (MarketSeries.OpenTime[index] >= tokyoOpen)
                            Chart.DrawStaticText("tokyo info", "\n\n\nPips From Tokyo Open: " + tokyoPrice, VerticalAlignment.Top, HorizontalAlignment.Right, Color.Yellow);
                } //            

            }

        }
    }
}


@Tspring

eduardomendes9209@gmail.com
23 Jan 2024, 21:29

Could you help with this indicator

Hello. Can anyone help me with this indicator.

I want to load this indicator only in a day or two because its weighing too much on my pc. It's loading to infinity and I don't have ram enough

I tried to set a max day count but didn't work.

here is the code

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class ColorMA : Indicator
    {
        [Parameter("Periods", DefaultValue = 200)]
        public int period { get; set; }

        [Parameter("MA Type")]
        public MovingAverageType maType { get; set; }
        
        [Parameter("MaxDays", DefaultValue = 1)]
        public int maxDays { get; set; }
        
       
        [Output("Main", Color = Colors.Cyan)]
        public IndicatorDataSeries Result { get; set; }

        private SimpleMovingAverage sma;
        private ExponentialMovingAverage ema;
        private TimeSeriesMovingAverage ts;
        private WeightedMovingAverage wma;
        private Vidya vid;
        private TriangularMovingAverage trn;
        private WellesWilderSmoothing wds;
        private int thc;

        protected override void Initialize()
        {
            Thickness();
            if (maType == MovingAverageType.Simple)
                sma = Indicators.SimpleMovingAverage(MarketSeries.Close, period);

            else if (maType == MovingAverageType.Exponential)
                ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, period);

            else if (maType == MovingAverageType.TimeSeries)
                ts = Indicators.TimeSeriesMovingAverage(MarketSeries.Close, period);

            else if (maType == MovingAverageType.Weighted)
                wma = Indicators.WeightedMovingAverage(MarketSeries.Close, period);

            else if (maType == MovingAverageType.VIDYA)
                vid = Indicators.Vidya(MarketSeries.Close, period, 0.65);

            else if (maType == MovingAverageType.Triangular)
                trn = Indicators.TriangularMovingAverage(MarketSeries.Close, period);

            else if (maType == MovingAverageType.WilderSmoothing)
                wds = Indicators.WellesWilderSmoothing(MarketSeries.Close, period);

            Chart.ZoomChanged += OnChartZoomChanged;
        }

        void OnChartZoomChanged(ChartZoomEventArgs obj)
        {
            Thickness();
            for (int i = 0; i < Chart.BarsTotal; i++)
            {
                Chart.RemoveObject("smaColorBody" + i);
                Calculate(i);
            }
        }

        public override void Calculate(int index)
        {
            if (maType == MovingAverageType.Simple)
                Result[index] = sma.Result[index];
            else if (maType == MovingAverageType.Exponential)
                Result[index] = ema.Result[index];
            else if (maType == MovingAverageType.TimeSeries)
                Result[index] = ts.Result[index];
            else if (maType == MovingAverageType.Weighted)
                Result[index] = wma.Result[index];
            else if (maType == MovingAverageType.VIDYA)
                Result[index] = vid.Result[index];
            else if (maType == MovingAverageType.Triangular)
                Result[index] = trn.Result[index];
            else if (maType == MovingAverageType.WilderSmoothing)
                Result[index] = wds.Result[index];

            Chart.DrawTrendLine("smaColorHL" + index, index, MarketSeries.High[index], index, MarketSeries.Low[index], MarketSeries.High[index] < Result[index] ? Color.Red : MarketSeries.Low[index] > Result[index] ? Color.LawnGreen : Color.Orange);
            Chart.DrawTrendLine("smaColorBody" + index, index, MarketSeries.Close[index], index, MarketSeries.Open[index], MarketSeries.High[index] < Result[index] ? Color.Red : MarketSeries.Low[index] > Result[index] ? Color.LawnGreen : Color.Orange, thc);
        }

        private void Thickness()
        {
            if (Chart.Zoom == 0)
            {
                thc = 1;
            }
            if (Chart.Zoom == 1)
            {
                thc = 2;
            }
            if (Chart.Zoom == 2)
            {
                thc = 3;
            }
            if (Chart.Zoom == 3)
            {
                thc = 5;
            }
            if (Chart.Zoom == 4)
            {
                thc = 11;
            }
            if (Chart.Zoom == 5)
            {
                thc = 25;
            }
            return;
        }
    }
}

 

Thank you!

 

 


@eduardomendes9209@gmail.com