• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    JimNinjaTrader Customer Service

    Comment


      #3
      thanks Jim, that did the trick

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NinjaCustomer, Today, 01:48 AM
      0 responses
      2 views
      0 likes
      Last Post NinjaCustomer  
      Started by aligator, Yesterday, 10:11 PM
      0 responses
      2 views
      0 likes
      Last Post aligator  
      Started by psquare, Yesterday, 03:11 PM
      4 responses
      20 views
      0 likes
      Last Post psquare
      by psquare
       
      Started by ballboy11, Yesterday, 03:20 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by tonynt, Yesterday, 02:18 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_JoshG  
      Working...
      X