Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

export historical data from strategy

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

    export historical data from strategy

    Hello,

    I need that my strategy export historical data to a text file, only for specific periods of time, while running in strategy analyzer. Any idea?

    Is there some code to export data to a text file?

    Thanks

    #2
    This link may helps You to save text to file.
    https://ninjatrader.com/support/foru...ead.php?t=3475

    Most general approaches, I believe are:

    PHP Code:
    StreamWriter Output_File;

    OnStateChange()
    {
        if (
    State == State.Active)
        {                
            
    StreamWriter Output_File= new StreamWriterOutput_Dir +Output_File_Name)            
        }        

        if (
    State == State.Terminated)
        {                
            
    Output_File.Close();            
        }        
    }

    OnBarUpdate()
    {
        if( 
    Data_Selection_Condition_Is_Ok 
        {
             
    output_file.WriteLineTime.ToStringyyyyMMdd HH:mm:ss ) +";"Open[0] +";"High[0] +";"Low[0] +";"Close[0] );
        }



    and

    PHP Code:
    List<stringData_Lines = new List<string>();

    OnStateChange()
    {
        if (
    State == State.Terminated)
        {                
            
    usingStreamWriter output_file = new StreamWriterOutput_Dir +Output_File_Name )) 
            {
                foreach( var 
    line in Data_Lines )                
                    
    output_file.WriteLineline );
            }                            
        }        
    }

    OnBarUpdate()
    {
        if( 
    Data_Selection_Condition_Is_Ok 
        {
             
    Data_Lines.AddTime.ToStringyyyyMMdd HH:mm:ss ) +";"Open[0] +";"High[0] +";"Low[0] +";"Close[0] );
        }

    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    Comment


      #3
      Thank you fx.practic, but I'm using NT 7, I think OnStateChange() is only for NT 8...

      Comment


        #4
        Hello federicoo,

        Thank you for your note.

        You could use streamwriter. Please see the following example,

        https://ninjatrader.com/support/foru...ead.php?t=3475

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          In this example, only Date and OHLC data are acquired, but I need: Time, Last and Vol data too, in the following format: 20180513 141358;70.47;5 (date time;last;vol).

          How can I get this? I try with the example file but getting an error.

          Thanks

          Comment


            #6
            Hello federicoo,

            Date would be the same as time, for the time rather than date and time you could use Time[0].TimeOfDay.

            Close would be the last price if you run the indicator with Calculate set to OnEachTick.
            See Calculate section of our helpguide,

            https://ninjatrader.com/support/help...?calculate.htm

            If you wanted to add volume you would use Volume[0].

            Please see the following sections of our helpguide,

            https://ninjatrader.com/support/help...-us/volume.htm
            https://ninjatrader.com/support/help...eries_time.htm
            https://ninjatrader.com/support/help...riceseries.htm

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your response.

              Added to the file format, I am trying to add a condition to the sample file, because I want to write down the data to the text file only for some days/times, for example, I want to export data from the chart for 3 specific dates, between 090000 to 150000. Adding the "if" sentence for this, I'm getting the "object reference not set..." error.

              Any ideas?

              Thanks

              Comment


                #8
                Hello federicoo,

                Thank you for your response.

                Can you provide the full code of the 'if' condition that is generating the error?

                I also recommend taking a look at our time filter condition at the following link: https://ninjatrader.com/support/help...to_limit_t.htm

                I look forward to your response.

                Comment


                  #9
                  I already fix the issue, thank you!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Lance El Camino, Today, 04:14 PM
                  1 response
                  13 views
                  0 likes
                  Last Post s.kinra
                  by s.kinra
                   
                  Started by jtrading82, Today, 04:56 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by dmking, Today, 06:00 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_EricB  
                  Started by WHICKED, Today, 03:23 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by demarcog, Today, 02:24 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Kate  
                  Working...
                  X