Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Export time of the bar in the right format

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

    Export time of the bar in the right format

    Hi, I'm trying to export historical data from NT to metastock.

    If I use standard NT export option, the format of the text file is not understandable by metastock.

    So I created a simple strategy to export data from each bar in the right format

    Code:
    Print(Instrument.FullName+",5,"+Time[0]+","+Open[0]+","+High[0]+","+Low[0]+","+Close[0]);
    And the result is:

    ES 12-12,5,11/29/2012 12:55:00 AM,1406.5,1406.75,1406.5,1406.75

    The problem is, I need to split Time[0] into 2 parts:

    1) date in YYYYMMDD format, followed by
    2) time in HHMMSS format.

    The result should look like

    ES 12-12,5,20121129,125500,1406.5,1406.75,1406.5,1406.75

    How do I exctract those separately from Time[0] ?

    #2
    Hi kosmipt,

    Well, there is a C# method:
    string[] words = text.Split(delimiterChars);

    Clearly Time[0] can be split into three parts: 11/29/2012, 12:55:00, and AM based on the space delimeter. So,

    string[] time = Time[0].Split(' ');

    time[0] will have the 11/29/2012
    time[1] will have 12:55:00
    time[2] will have AM

    Then repeat for the first part using the delimeter /
    string[] date = time[0].Split('/ ');

    So date[0] will have 11
    date[1] will have 29
    date[2] will have 2012

    And do the same for the time.

    string[] actualTime = time[1].Split(': ');
    actualTime[0] will be 12
    actualTime[1] will be 55
    actualTime[2] will be 00

    Then reassemble into the format you want and send then to Metastock.

    string newDate = date[2]+date[0]+date[1];
    string newTime =actualTime[0}+actualTime[1]+actualTime[2];

    There probably is a cleaner way to do this but this should get you started.

    Comment


      #3
      Thanks a lot, it worked!

      Comment


        #4
        Great. Glad it worked for you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by zstheorist, Today, 07:52 PM
        0 responses
        3 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        149 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Started by mattbsea, Today, 05:44 PM
        0 responses
        5 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        33 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        5 views
        0 likes
        Last Post tkaboris  
        Working...
        X