Object Get Price Value By Time

Created at 29 Jan 2019, 19:08
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!
FMogyi's avatar

FMogyi

Joined 13.10.2015

Object Get Price Value By Time
29 Jan 2019, 19:08


Is it possible to get the price data where the object is at the specified time? 

Here is the relevant MT4 code: 


@FMogyi
Replies

PanagiotisCharalampous
30 Jan 2019, 10:03

Hi FMogyi,

You can use GetIndexByTime and then use the index to get a specific value from a Series at a specific time. See an example below

var closePrice15hoursBefore = MarketSeries.Close[MarketSeries.OpenTime.GetIndexByTime(Server.Time.AddHours(-15))];

Best Regards,

Panagiotis


@PanagiotisCharalampous

FMogyi
30 Jan 2019, 11:00 ( Updated at: 21 Dec 2023, 09:21 )

Dear Panagiotis, Unfortunately we do not understand eaach other. So I try to explain on this chart what I want:

Here are 2 trendlines for example. The price is staying between the lines (sideway market). And once a time beakout action will be happen. 

I want to catch this moment. So I need to query by cBot  where the trendline stays (price) at the specified time or bar. When the price (or closed candle ) breaks the trendline.

 

for example:
double trendline1 = ObjectGetValueByTime(cart_ID, UpperTrendLine, Time); //Get the current price
if (Symbol.Bid > trendline1) BREAKOUT();


@FMogyi

PanagiotisCharalampous
30 Jan 2019, 11:25

Hi FMogyi,

Ok now its clear. To get the value of a trend line at a specific point in time, you can use CalculateY. Let me know if this helps.

Best Regards,

Panagiotis


@PanagiotisCharalampous

FMogyi
02 Feb 2019, 12:29

Dear Panagiotis, 

There are some objects in the chart. I don't know how many. I find  them with this code: 

            var _Objects = Chart.FindAllObjects(ChartObjectType.TrendLine);
            foreach (var obj in _Objects)
            {
                 double CalculetY = How?    
            }

So how can I use properly the CalculateY() function to get the Y value for all objects in this example? 

Thanks,


@FMogyi

bart1
02 Feb 2019, 15:03

CalculetY is a method of ChartTrendLine interface:

var line = Chart.DrawTrendLine(...);
var price = CalculateY(someBarIndexOrTime);

Here is an example for drawing icon on each bar along with a trend line:

var line = Chart.DrawTrendLine("line", Chart.BarsTotal - 21, MarketSeries.High.Last(20), Chart.BarsTotal - 1, MarketSeries.High.Last(0), Color.Red);
foreach (var i in Enumerable.Range(-5, 30))
{
    var barIndex = Chart.BarsTotal - i;
    var price = line.CalculateY(barIndex);
    Chart.DrawIcon("icon" + i.ToString(), ChartIconType.Circle, barIndex, price, "#80FFFFFF");
}

 


@bart1

FMogyi
03 Feb 2019, 13:28

RE:

bart1 said:

CalculetY is a method of ChartTrendLine interface:

Thanks, but this is not an answer to my question!

My original question is: how can I get the price data where the object is at the specified time? 


@FMogyi

bart1
04 Feb 2019, 09:33

RE: RE:

So I need to query by cBot  where the trendline stays (price) at the specified time or bar

CalculateY is doing exactly that. 

From your screenshot, I assume that you might use horizontal lines. ChartHorizontalLine interface has Y property that doesn't change from bar to bar.

var lines = Chart.FindAllObjects<ChartHorizontalLine>();
foreach(var line in lines)
{
    Print(line.Y);
}

Cheers


@bart1

FMogyi
05 Feb 2019, 09:57

These are Trendlines (but doesn't matter). I try with HorizontalLine:

var lines = Chart.FindAllObjects(ChartObjectType.HorizontalLine);
            foreach (var line in lines)
            {
                Print(line.Y);
            }

and the Error message is same:

Error CS1061: 'cAlgo.API.ChartObject' does not contain a definition for 'Y' and no extension method 'Y' accepting a first argument of type 'cAlgo.API.ChartObject' could be found (are you missing a using directive or an assembly reference?)


@FMogyi

PanagiotisCharalampous
05 Feb 2019, 10:11

Hi FMogyi,

See below

            var lines = Chart.FindAllObjects(ChartObjectType.HorizontalLine);
            foreach (var line in lines)
            {
                Print((line as ChartHorizontalLine).Y);
            }

Best Regards,

Panagiotis


@PanagiotisCharalampous

bart1
05 Feb 2019, 10:56

Chart.FindAllObjects<ChartHorizontalLine>() is a generic method that returns ChartHorizontalLine[]. Seems it is better to use that, you don't need a cast there.


@bart1

juan.calmet
30 Jun 2020, 01:35

RE: Bro I found out how

   var lines = Chart.FindAllObjects<ChartTrendLine>();
            foreach (var line in lines)
            {
                Print(line.CalculateY(Bars.OpenTimes.Last(0)));
            }

 


@juan.calmet

juan.calmet
30 Jun 2020, 01:36 ( Updated at: 21 Dec 2023, 09:22 )

RE: found the solution

FMogyi said:

Is it possible to get the price data where the object is at the specified time? 

Here is the relevant MT4 code: 

   var lines = Chart.FindAllObjects<ChartTrendLine>();
            foreach (var line in lines)
            {
                Print(line.CalculateY(Bars.OpenTimes.Last(0)));
            }


@juan.calmet

amaral.regis
01 Mar 2021, 20:01

RE: RE: Bro I found out how

juan.calmet said:

   var lines = Chart.FindAllObjects<ChartTrendLine>();
            foreach (var line in lines)
            {
                Print(line.CalculateY(Bars.OpenTimes.Last(0)));
            }

 

Obrigado, Juan!


@amaral.regis