Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT7 Strategy: ExportData

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

    NT7 Strategy: ExportData

    Attached a strategy that exports csv text files in the format DateTime,Open,High,Low,Close,Volume with a few options to change the output data types and file destinations via the Strategy dialog box (ie you don't have to go into the code to change stuff).

    I do a lot of offline analysis and this is handy for that. DateTime output format is currently limited to POSIX (I use it with R), but if anyone wants to have a go at changing the output DateTime options to an enum and manipulate the DateTime strings it might be more useful.

    Feel free to make it better!
    Attached Files

    #2
    thanks MXAJX,
    btw, have you played with
    Code:
    base.MarketData
    seems lot of functions there, but no one seems exploited it.

    Comment


      #3
      ver 3.01 deletes the Print statements I was using for debugging and changes an if/if chain to an if/else to save a bit of processor power. Sorry I should have cleaned it up before posting earlier.
      Attached Files

      Comment


        #4
        It was suggested I use the OnStartUp() method and move some of the code out of OnBarUpdate(). The key sections are below:

        PHP Code:
        protected override void Initialize()/////////////////////////////////////////////////////////////////////////////////////////////////////////
        {
        CalculateOnBarClose = true;
         
        }
         
        protected override void OnStartUp()/////////////////////////////////////////////////////////////////////////////////////////////////////////
        {
        string dest = path+filename;
        string defname = path + @"\" +Instrument.FullName+"_"+BarsPeriod.Value+"_"+BarsPeriod.Id+".txt";
        defname = defname.Replace(' ','_'); // Replaces non-ISO file characters in Futures names
        defname = defname.Replace('-','_'); // Replaces non-ISO file characters in Futures names
         
        // If file at 'path' doesn't exist it will create the file. If it does exist it will append the file.
         
        if (useDefaultFilename == false)
        {
        sw = File.AppendText(dest);
        } 
        else
        {
        sw = File.AppendText(defname);
        }
        }
         
        protected override void OnBarUpdate()///////////////////////////////////////////////////////////////////////////////////////////////////////
        {
         
        string sep = DataSeparator.ToString();// Cast required so the Date/Time separator and normal data separator are the same
         
        // This is the output of all lines. The output format is: DateTime Open High Low Close Volume
        string data = (Time[0] + sep + Open[0] + sep + High[0] + sep + Low[0] + sep + Close[0] + sep + Volume[0]);
         
        if (splitDateTime == true)
        {//Replace the space in DateTime with the DataSeparator
        data = data.Replace(' ',DataSeparator);
        }
         
        sw.WriteLine(data);
         
        } 
         
        protected override void OnTermination()//////////////////////////////////////////////////////////////////////////////////////////////////////
        {
        sw.Close();
        } 
        
        This compiles and works fine, but I'd like to ask if this is the right use for OnStartUp(). Not much documentation on that yet .

        Thanks

        Comment


          #5
          It is correctly used. In addition I would move the following code line to OnStartUp():

          string sep = DataSeparator.ToString();//

          Comment


            #6
            Thanks! Better code attached. v3.10.
            Attached Files

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            597 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            343 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            556 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            555 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X