Import signal from CSV file?
Author: janu314
Creation Date: 2/14/2017 8:30 PM
profile picture

janu314

#1
New to this forum so forgive any mistakes.

1. I have a strategy coded in Excel which outputs a signal around 3:45 PM everyday, in either Excel or CSV format.


2. All we need to do is have wealthLab read this file and input this trade into the system, everyday.


3. Is this possible to do in WLPro and can you please tell us the easiest way to do this in WealthLabPro 6.9?


4. Perhaps I can use one of the strategy codes available here as starting points to do this?

Thanks a lot,

Janu
profile picture

Eugene

#2
Hello Janu,

Yes, this is possible.
profile picture

Eugene

#3
1. How and when do you plan to execute that signal - "tomorrow" or "today"?
2. If "today", is it important to execute it in WLP precisely or anytime between 3:45pm and 3:59pm should do?
3. Do you need an Alert or just to see it on the chart as a historical trade?
4. Assuming you're free to control how the output CSV file will look like?

Question is if our ImportHistoricalTrades method to import a preformatted CSV file with trades could be used, or it'd take to create a customized Strategy example.

P.S. As Wealth-Lab is very powerful in both backtesting and charting, have you considered porting your algo to our platform?
profile picture

janu314

#4
Thanks Eugene for detailed comments. I am sorry, I was not clear about the distinction between support ticket and the forum.

To answer your questions:

1. The trade is to be executed today (and everyday) before the close.

2. I have to double check, but I believe we want to send it at 3:50 PM precisely.

3. I do need a trade alert and then the order is to be routed live to the market.

4. I will look at ImportHistoricalTrades method, but I think I will need to create a custom method for our purpose.
Is the source code available ? Perhaps, I can use it as a starting point.

5. I started coding (see code snippet below) this up by looking at times of the last few bars and checking for time = 3:50.

Not sure if this is right approach. Also, this is only producing a historical trade, not a trade alert or live trade ?

Code Snippet:

CODE:
Please log in to see this code.



6. At the moment coding everything in WealthLab is not an option as the XL-sheet (belongs to someone else) is not available.

profile picture

Eugene

#5
Janu, thanks for clarifying. Here's rough plan:

1. Use Fidelity's intraday data (1-minute)
2. Make sure the signal is generated
3. Parse the CSV output from your XL sheet
4. Using GetTime (found in Community Components), check if the bar's time is 3:49pm
5. If true, send alert for the next bar for WLP to execute it at 3:50pm

The source code for ImportHistoricalTrades is available after separate registration in the Wiki and "greenlisting" your new account, but I have a feeling that your task does not require it and after finding out the signal file format, could be coded from scratch. Do you have an example of the CSV file already?
profile picture

janu314

#6
Thanks Eugene,


1. I will use 1 min and GetTime as suggested by you.


2. I am able to generate backtest trades but not trade alerts/trades. When I do the code as below: I get trades in my chart but no trade alerts, or Orders in my orders tool bar.

I do not understand how to generate alerts or to send orders to market/paper account. Please help.


CODE:
Please log in to see this code.




3. . I am attaching a sample CSV file below. Perhaps I can code the parser from scratch.
profile picture

Eugene

#7
2 - The code snippet is not enough.

3 - Attachment did not work out.
profile picture

janu314

#8
Eugene,

here is the CSV file, was unable to attach it first time!

here I think is the relevant code for buy order. I can attach the whole file if you like ?

CODE:
Please log in to see this code.



thanks a lot for your help!

Janu
profile picture

Eugene

#9
Thanks, that's better. Not seeing any obvious faults. The whole file would let me evaluate the composition and if the trading loop is used correctly. To attach the CSV, just zip it or rename to TXT.
profile picture

janu314

#10
Eugene,


Here is the whole file. Hope you can tell me my mistake. Or perhaps, the issue is one of my settings on WLPro?

thanks a lot!

PS: there is a lot of debugging (print) code which you can ignore.
janu

CODE:
Please log in to see this code.


Here is the original CSV(txt) file as you asked. I am using a simple one for the code above, as I don't have a parser for this one yet.


many thanks,

J--
profile picture

Eugene

#11
Here's a quick example that parses your file (roughly) and generates trades or alerts depending on file contents:

CODE:
Please log in to see this code.
profile picture

janu314

#12
Great! Thanks Eugene,


I hope that will generate trades/alerts. I will try it and let you know.

I hope there is a not a problem with my settings, not sure why I was not getting any trades before?


thanks again,

janu


profile picture

Eugene

#13
Slightly improved code to parse the "Trade Indication" field (buy/hold/sell).

Note that to get an alert the trade date in the file should be "today" and the script must be running in Streaming mode (or in the Strategy Monitor) before 3:45pm already.

CODE:
Please log in to see this code.