Sorting objects (horizonal lines) by price value

Created at 08 Jul 2020, 12: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!
KE

Ketu

Joined 09.10.2018

Sorting objects (horizonal lines) by price value
08 Jul 2020, 12:08


I need to sort the chart object by their price value (y1) when there is more than 2 so i can make changes to the highest object, what's the best way to do this?.
I've already got the function to change the line, just need a way to get it.

I'm using this repository

foreach (var signalLine in SignalLineRepository.GetLines())
            {
            
            }


@Ketu
Replies

PanagiotisCharalampous
08 Jul 2020, 12:11

Hi Ketu,

You need to post the complete code for us to be able to help you.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

Ketu
08 Jul 2020, 12:17

RE:

PanagiotisCharalampous said:

Hi Ketu,

You need to post the complete code for us to be able to help you.

Best Regards,

Panagiotis 

Join us on Telegram

 

It's based on your LinesTrader sample

public ProtoSignalLine(Chart chart, SignalType? signalType, DateTime time1, double y1)
        {
            _chart = chart;
            _signalType = signalType;
            double y2 = y1;
            DateTime time2 = time1.AddHours(20);
            _line = _chart.DrawTrendLine(string.Format("1", Guid.NewGuid()), time1, y1, time2, y2, LineColor);

            _line.ExtendToInfinity = false;
            _line.Thickness = 1;
            _line.IsInteractive = true;
        }

 


@Ketu

PanagiotisCharalampous
08 Jul 2020, 12:30

Hi Ketu,

Change 

  private readonly ChartTrendLine _chartTrendLine;

to 

   public ChartTrendLine ChartTrendLine { get; }

and then order the collection accordingly as below

 foreach (var signalLine in SignalLineRepository.GetLines().OrderByDescending(x => x.ChartTrendLine.Y1))

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous