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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      43 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      20 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      30 views
      1 like
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      48 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      38 views
      0 likes
      Last Post CarlTrading  
      Working...
      X