'***************************** START OF  SCRIPT ******************************************
'********* Convert MetaTrader4 export file format to Ninja Trader import format **********
'*****************************************************************************************
Option Explicit
On Error Resume Next

Dim vPathToFileIn   '**********  MUST CHANGE THIS TO MATCH YOUR PATH ******************
Dim vPathToFileOt   '**********  MUST CHANGE THIS TO MATCH YOUR PATH ******************

vPathToFileIn = "C:\mydir\subdir\EURUSD1.csv"
vPathToFileOt = "C:\mydir\subdir\$EURUSD-new.txt"
'rename the output file to the standard Ninja Trader file name, then Import

Dim oFSO, oFileIn, oFileOt, vLineIn, vLineCnt, vLineOt

'get link to file system support
Set oFSO = CreateObject("Scripting.FileSystemObject")
'open both files (in and out)
Err = 0
Set oFileIn = oFSO.OpenTextFile(vPathToFileIn, 1)      '1=read
Set oFileOt = oFSO.CreateTextFile(vPathToFileOt, True) 'true=overwrite
If Err <> 0 Then
   Wscript.Echo "Error on file open: " & Err.Number & ", " & Err.Description
   Wscript.Echo "stopping"
   Wscript.Quit
End If
'
'do the reformat
'input format
'2009.08.21,20:17,1.4327,1.4328,1.4326,1.4328,10
'output format
'20090819 230600;1.4225;1.4225;1.4223;1.4224;171100000

vLineCnt = 0 
Do Until oFileIn.AtEndOfStream
   vLineIn = ""
   vLineIn = oFileIn.ReadLine
   vLineCnt = vLineCnt + 1
   'if vLineCnt > 10 Then Exit Do
   vLineOt = ""
   vLineOt = Mid(vLineIn,1,4) & Mid(vLineIn,6,2) & Mid(vLineIn,9,2) & " "  'date
   vLineOt = vLineOt & Mid(vLineIn,12,2) & Mid(vLineIn,15,2) & "00" & ";"  'time
   vLineOt = vLineOt & Mid(vLineIn,18,99)                                  'O,H,L,C,V
   'Wscript.Echo "about to write: " & vLineOt
   Err = 0
   oFileOt.WriteLine(vLineOt)
   If Err <> 0 Then
      Wscript.Echo "Error on file write: " & Err.Number & ", " & Err.Description
      Wscript.Echo "stopping"
      Wscript.Quit
   End If
Loop
'
'close the files
oFileIn.Close
oFileOt.Close
'
'tell user count and quit
Wscript.Echo "transferred " & vLineCnt & " lines. stopping now."
Wscript.Quit
'
' **************************** END OF  SCRIPT ******************************************