Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

gathering data from each trading session of S&P futures going back one year

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

    gathering data from each trading session of S&P futures going back one year

    not sure if this is a strategy, but i would like to run a backtest in which i only print out data to a file. i want to capture data from each full trading session (from the 6pm open to the 5pm close the next day) of the S&P futures for one year. i don't know how to start running the strategy from 1 year ago and iterate one session at a time until today, saving data as i go along. Also, not sure where to put my method, OnBarUpdate() seems like overkill because i just need data on a per session basis. some pseudo code like the following:

    public class SomeStrategy : Strategy
    {
    var List<MyData> data = new List<MyData>();

    public void runIt()
    {
    for(var int i = 1; i < anArrayContainingEachTradingSessionForThePastYear. length; i++)
    {
    var someData = new MyData();
    someData.priorClose = anArrayContainingEachTradingSessionForThePastYear[i-1].closePrice; // 5pm close prior session
    someData.currentOpen = anArrayContainingEachTradingSessionForThePastYear[i].openPrice; // 6pm open current session
    someData.currentLow = anArrayContainingEachTradingSessionForThePastYear[i].lowPrice; // low of current session

    data.add(someData);
    }

    foreach (var d in data)
    {
    using (var fw = new FileWriter("c:\testdata.csv"))
    {
    fw.writeLine(d.priorClose + "," + d.currentOpen + "," + d.currentLow);
    }
    }
    }
    }

    class MyData
    {
    public double priorClose {get;set;}
    public double currentOpen {get;set;}
    public double currentLow {get;set;}
    }

    i don't know how to fill anArrayContainingEachTradingSessionForThePastYear with data, then iterate through it. each index in the array contains a trading session. is it even possible?

    thanks
    john

    #2
    Hello johng964,

    Thanks for your post.

    The strategy will backtest the historical data of the data series it is applied to. You could for example, load 1 years worth of data and run the strategy against it. Within the strategy's OnBarUpdate method, you could then check if Bars.IsFirstBarOfSession is true which would reflect when a new session is created. This could be where you decide to reset variables and output the information to file.

    IsFirstBarOfSession - https://ninjatrader.com/support/help...rofsession.htm

    Please let us know if we can be of further assistance.

    Comment


      #3
      thanks Jim, that did the trick

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      119 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      62 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  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      82 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X