Save open trades in CSV file
Author: aphelps7
Creation Date: 9/14/2008 10:14 AM
profile picture

aphelps7

#1
I tried to follow the code sample(from WIKI) for exporting to an excel file. It compiles successfully, but I get the following error in the debug window when running the script.

The process cannot access the file 'C:\Test\Stocks\Data\81208.csv' because it is being used by another process.

It creates the file successfully but never writes any lines.

Also, I am new to C. Is there a way instead of hard coding the date for the file name, you can put the system date instead?

CODE:
Please log in to see this code.

profile picture

Eugene

#2
QUOTE:
The process cannot access the file 'C:\Test\Stocks\Data\81208.csv' because it is being used by another process.

It creates the file successfully but never writes any lines.


The wiki sample is complete and is designed to save closed trades. As you approach open positions, the code needs a little tweak:

CODE:
Please log in to see this code.


This was removed:
CODE:
Please log in to see this code.


QUOTE:
Is there a way instead of hard coding the date for the file name, you can put the system date instead?


Yes. Obtain current DateTime, convert it to string or combine d, m, y extracted from the DateTime structure any way you like.
profile picture

aphelps7

#3
Eugene,

Thank you. That worked great.
profile picture

sf631

#4
I'm looking to do something different with the System.IO namespace - in a sense the reverse of what's mentioned above. I'd like to use WLP as a way to analyze and chart my actual trades placed manually, and maybe down the road use this to overlay my actual historical trades with what my mechanical strategy would have said to do.

So, the part I need help with is using a method in System.IO (File.ReadAllLines? StreamReader ReadLine?) to import my list of trades (a few thousand, spread over 100 or so symbols) in a way that my WLP code can use it to "place trades" in the simulation that match what I actually did.

I can put the trades into a CSV in just about any format needed, but was thinking of:

CODE:
Please log in to see this code.



Then when charting a symbol within my strategy, use a basic logic of (pseudocode)
CODE:
Please log in to see this code.


Basically making the WLP strategy a "don't think, just trade" approach.

My key question is what's the best way to pull the data in from a CSV into a WLP data structure that makes this easy to manipulate? Can I create a new Bars series like you did in the 3M Libor example I found on the forum? Will I have any difficulty getting WLP to view the price fields or date fields as numbers and dates rather than text? Would I be better to think of some hack that used the ASCII dataseries file importer to do the work of parsing and converting the fields?

Thanks for a point in the right direction. Thought it'd be better to ask now than after having written spaghetti code.

profile picture

Eugene

#5
You can start right here:

Community.Components > Import real (historical) trades
profile picture

sf631

#6
That is EXACTLY what I was looking for. Thanks!
profile picture

Eugene

#7
Discussion continues here: Import a trade list
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).