Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Transform the period of a DataSeries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Transform the period of a DataSeries

    Hey guys, how are you?

    I'm developing an add-on and i'm trying something new..

    I have the object
    Code:
    public class Ohlc : Bar
    {
    
        public int Id { get; set; }
        public DateTime Time { get; set; }
        public double Open { get; set; }
        public double High { get; set; }
        public double Low { get; set; }
        public double Close { get; set; }
        public long Volume { get; set; }
    
    }
    These objects have different periods.
    The thing is that i want to parse that data which can be in minutes to 5 minutes, or 1 hour.

    Any idea what can i do? Maybe some expert in Linq can give me a hand.

    Thank you.

    #2
    Hello Fernand0,

    Thank you for the post.

    I am not certain I understand the question as written.

    These objects have different periods.
    The thing is that i want to parse that data which can be in minutes to 5 minutes, or 1 hour.
    I only see the Ohlc object that you have created but that does not contain any period information, are you asking how to append the period information to that class? To know what period of data that class represents you would have to design the class to contain that type of information and then set that information when you create an instance of the class.

    If you have a slightly more complete sample that shows how you used the class that would be helpful here as well.


    I look forward to being of further assistance.




    Comment


      #3
      The idea is to change the period for example.


      Code:
      var index = 0;
                  var TickInterval = new TimeSpan(0, 5, 0).Ticks;
                  var hour = from ohlc in list
      
                                 // Calculate the chronological, natural-time, intra-day index 
                                 // of the bar associated with a tick.
                             let Index = ohlc.Time.TimeOfDay.Ticks / TickInterval
      
                             // Calculate the begin-time of the bar associated with a tick.
                             // For example, turn 2011/04/28 14:23.45 
                             // into 2011/04/28 14:20.00, assuming 5 min bars.
                             let Start = ohlc.Time.Date.AddTicks(Index * TickInterval)
      
                             // Produce raw tick-data for each bar by grouping.
                             group ohlc by Start into DataSeries
      
                             select new Ohlc
                             {
                                 Id = index++,
                                 Time = DataSeries.Key,
                                 //Time = tickGroup.Key.AddTicks(barSizeInTicks),
                                 Open = DataSeries.First().Bid,
                                 High = DataSeries.Select(p => p.Bid).Max(),
                                 Low = DataSeries.Select(p => p.Bid).Min(),
                                 Close = DataSeries.Last().Bid,
                                 Volume = DataSeries.Sum(p => p.Volume)
                             };
      I found this code.
      This reads tick data and creates BarsPeriodType.Minute, 5

      But using DataContext is slower than creating every object manually to a List. (this Linq statement requires "list" to be a List or an Array)
      So, there is a way to pass this Linq to an SQL query? how would that be?

      Comment


        #4
        Hello Fernand0,

        It is not clear what you are trying to do with the given information however It appears you are asking a Linq question and not a NinjaScript question. You will likely be able to locate more helpful information for this question by searching online for C# Linq related educational information. NinjaTrader support can assist with NinjaScript questions, linq and sql would be outside what I can assist with.

        The data format will not be in a list like linq is expecting, NinjaScript deals with data in Series<T> format. If you specifically want to use Linq you would need to figure out how to convert the series data to a list, keep in mind the list wont be updated with new data so that will also fall on your plate.

        If you want to see how the existing bars type convert data to various periods you could look at the Minute BarsType to see how it does that for each data point.


        Please let me know if I may be of further assistance.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        23 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        120 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        63 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        45 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X