Rectangle (ray) Casting?

Created at 02 Mar 2021, 13:30
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!
SM

SmartArtsStudio

Joined 30.10.2020

Rectangle (ray) Casting?
02 Mar 2021, 13:30


Hello

Is there a way to cast a Rectangle horizontally to infinity. Similar to trendLine.ExtendToInfinity = true?

What DateTime value is internally passed to ChartArea.DrawTrendLine(... time2... ) when trendLine.ExtendToInfinity = true? (DateTime.MaxValue?)
Can I just pass in the same value to ChartArea.DrawRectangle(... time2... ) ...or is their a way I can apply the internal implimentation of trendLine.ExtendToInfinity as a work around to ChartArea.DrawRectangle?

Trying to project rectangle (regions) into the future until price intersects with it again. Then convert the ray cast rectangle into a regular rectangle with a time2 value matching the intersecting price once it is known.

Thanks


@SmartArtsStudio
Replies

PanagiotisCharalampous
02 Mar 2021, 14:33

Hi SmartArtsStudio,

There is no such option in the API to achieve that. The only way to achieve it is to set your time2 variable in a distant future time and keep the distance far away as the chart moves to the right.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

SmartArtsStudio
02 Mar 2021, 21:39

RE:

PanagiotisCharalampous said:

Hi SmartArtsStudio,

There is no such option in the API to achieve that. The only way to achieve it is to set your time2 variable in a distant future time and keep the distance far away as the chart moves to the right.

Best Regards,

Panagiotis 

Join us on Telegram

That will work.
What would be the simplest method to add the ChartArea.Width to Chart.LastVisibleBarIndex to come up with a DateTime or X value in the future?
Thanks


@SmartArtsStudio

amusleh
03 Mar 2021, 09:44

RE: RE:

SmartArtsStudio said:

PanagiotisCharalampous said:

Hi SmartArtsStudio,

There is no such option in the API to achieve that. The only way to achieve it is to set your time2 variable in a distant future time and keep the distance far away as the chart moves to the right.

Best Regards,

Panagiotis 

Join us on Telegram

That will work.
What would be the simplest method to add the ChartArea.Width to Chart.LastVisibleBarIndex to come up with a DateTime or X value in the future?
Thanks

The chart width unit is not in number of bars, its the width of chart, try this:

using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class InfinitRectangle : Indicator
    {
        // Use this later if you want to extend the rectangle more as user zoom in/out or scroll
        private ChartRectangle _rectangle;

        protected override void Initialize()
        {
            var numberOfVisibleBars = Chart.LastVisibleBarIndex - Chart.FirstVisibleBarIndex;

            var lastVisibleBarIndex = Chart.FirstVisibleBarIndex + Chart.MaxVisibleBars;

            _rectangle = Chart.DrawRectangle("rect", Chart.FirstVisibleBarIndex, Bars.HighPrices.Maximum(numberOfVisibleBars),
                lastVisibleBarIndex, Bars.LowPrices.Minimum(numberOfVisibleBars), Color.Red);
        }

        public override void Calculate(int index)
        {
        }
    }
}

 


@amusleh