Trading from external signals
Author: Petrus3058
Creation Date: 7/10/2014 1:05 PM
profile picture

Petrus3058

#1
Hi, I’m brand new to WLP and need some guidance. I have two tasks I would like to implement:

1) How would I take an external generated list of trades either from excel or ascii and place automated trades in three Fidelity accts.
a. Fidelity said they thought someone had an excel trade list a while back whereby a macro would send orders to Fidelity. I think through WLP.
b. The amount in the three accounts is different. I could take an excel macro to replicate the trade list for each of the three account
to adjust number of shares to correspond to acct size.

2) Similar to above, I would like to import the external (excel or ascii) list but save into a "reusable" dataset and run strategies for further processing prior to executing the trade per the strategy on the dataset.
a. From reading other posts, it sounds like I would need to replicate the strategies, one for each of the three Fidelity accts.
b. I’d like to remove symbols from the dataset after I close the position.

I'm starting from ground zero and haven't coded in a long time. Any extensions/scripts would be greatly appreciated.
Thank you.
profile picture

Eugene

#2
Welcome to the forums.

To start with, you can use this solution from Community Components library:

Import real (historical) trades from a CSV (ASCII) file

Specifying trade size is supported i.e. SimTradeFile/SimTradeFile2 reads your position size from the source file. Note that the input (i.e. your ASCII file) should follow some pattern (the Wiki link contains syntax examples).

QUOTE:
a. From reading other posts, it sounds like I would need to replicate the strategies, one for each of the three Fidelity accts.


Yes. "Save as" three times and then assign an account for each copy as follows:

Selecting account other than the one in settings?

QUOTE:
b. I’d like to remove symbols from the dataset after I close the position.


Not supported by the program and frankly, a programmatic workaround for symbol removal would be too convoluted (takes a WLP restart after each DataSet modification). For simplicity's sake, program your strategy to exclude the symbol from processing further signals with a boolean condition once the position is closed.
profile picture

Petrus3058

#3
Excellent. Thank you Eugene. - I may be back :)
profile picture

gbullr

#4
Hello.

What would be the way to give WL the buy signals and then test different exits using different rules created on WL as oopposed to giving entry and exit signals. ?

Background: I created buy signals with a python webscraper and then put the data on a CSV file. I can obviously create time based exit signals but I was wondering whether once the buy signals were in whether WL code could be used to create exit stategies rather than providing buys AND sells.

Thanks in advance.


profile picture

Eugene

#5
Interesting question. So far everyone was concerned about importing buys and sells (and that makes sense). I think the solution is simple: delete all exit signals from your CSV file before feeding it to ImportHistoricalTrades. This way you make it only handle entries and take care of exits yourself.
profile picture

gbullr

#6
Thanks. I will try. Hopefully, I will not have follow up questions.
profile picture

gbullr

#7
I cannot get my trades to load b/c of a datetime error. However the sample trades provided here (Import real (historical) trades):

QUOTE:
//Short,QQQQ,25-06-2009,36,25-06-2009,35.5
//Long,AAPL,12-05-2009,124,26-05-2009,130.4

even when I change the prices to prices that make sense given splits etc.

Debug Error window contains:

Entry error: Long QQQ 6/25/2009 12:00:00 AM 36
Exit error: Long QQQ 6/25/2009 12:00:00 AM 35.5
Entry error: Long AAPL 5/12/2009 12:00:00 AM 18.01
Exit error: Long AAPL 5/26/2009 12:00:00 AM 18.59

Thanks for your help.


profile picture

Eugene

#8
Besides that you've adjusted the prices in the Wiki sample there is not enough detail for troubleshooting. It's a rule of thumb to assume that everything always works for us technicians - unless something gets really broken by a 3rd party (not the case here). So if you want us to get somewhere with this, please make sure that first you've tried out all the 15 troubleshooting suggestions in the bullet/numbered lists on the Wiki page. If still no go, you might consider passing on a sample of your trade list, your code, and the data/symbols in use (preferably not intraday as I don't work with WLP and won't be able to reproduce).
profile picture

gbullr

#9
Here is the code copied directly from the wiki ladding community components

CODE:
Please log in to see this code.



I am not using my file. I am using a file called Book1.csv which contains these two lines starting at row 1.
QUOTE:
Short,QQQ,25-06-2009,36,25-06-2009,35.5,
Long,AAPL,12-05-2009,18.01,26-05-2009,18.59,


The file excludes headers.

Regarding the checklist.

1) Trade size can be specified in the file, and it is supported using Wealth-Lab version 5.6 and up (optional parameter).
Does not include trade size
2) Here, the separator char is ';' but it also can be any one of these: tab, comma, dot with comma.
separator is comma
3) Here, the date format is dd-MM-yyyy but as stated above, it can be any supported format. Just make sure to pass a correct DateTime description string the method.
Date format is precisely as specified in the wiki
4) The first line of the file can't contain a heading.
See above
5) Empty lines are ignored
Not Applicable
6) The Strategy should be executed in single symbol mode backtest (SSB), not MSB
I don't know what this means.
I have done two things to resolve.
a.) Create a dataset w/ the two symbols (AAPL and QQQ) and I click on that and run backtest and no trades appear.
b.) I open the strategy and click on each symbol individually and no trades appear.
7) Dividend adjustments must be disabled for providers like Yahoo! Finance.
Data provider is FIDO
I also disable the dividend and retry and this does not change the result. (No trades executed)

8) Is your trade trying to enter above the high or below the low of bar?
Data for trades from FIDO
AAPL 5/12/2009 Low:17.61 High 18.53
AAPL 5/26/2009 Low:17.79 High 18.69
QQQ 6/25/2009 Low:35.28 High:36.36
Please see above for my prices.

9) If your position isn't exited properly, check if you tried to exit below the low or above the high.
I don't think this is applicable
10)Does the bar exist in your datasource? Refresh it if required.
Went back to dates on chart mode and bar is there
11)Is the bar range correct? Edit the bar if required
I don't think this is applicable .
12) Is the symbol present in the DataSet?
I created a symbol specific dataset w/ the two symbols present.
I also have the strategy open and type in each symbol individually to trigger a trade which has worked for me in the past
13) 'Index out of range' most likely indicates that the symbol requires updating its data.
Not applicable
14) Are trades being duplicated? Ensure it's not running in a multi-symbol backest (MSB).
Not applicable



Thanks.
profile picture

Eugene

#10
Thanks for the thorough problem description.

QUOTE:
Date format is precisely as specified in the wiki

No, it has been altered. This gives me answer to your trouble and unfortunately, it's incurred by your edit of the otherwise working code:
CODE:
Please log in to see this code.

And even if your actual file contains dates in the order different from the Wiki example, the new specifier will still be invalid.

As you might've noticed, the Wiki article contains two links to a Microsoft documentation on date/time formats in MSDN. They were broken so I've just updated the Wiki. You might want to reload the page, visit these links and apply suggestions.

Or here's a more straightforward solution that doesn't require reading. It's as simple as to copy and paste the example code from the Wiki again, but this time please keep from breaking the working code with edits that have no apparent reason.
profile picture

gbullr

#11
Sorry. Formatting got messed up in original code when I was trying to go from my date format to the wikis.

I will now try to get my code to work.

profile picture

KGo

#12
You could also try Historical Trades available in Utilities folder after downloading WL strategies.

1. Add 1 line near bottom where Multifile examples are. This will enter and exit on dates given (Same Day Price):
CODE:
Please log in to see this code.


2. Put a header in row one of the data:
Action,Symbol,EntryDate,EntryPrice,ExitDate,ExitPrice

3. Lastly if desired you can add your own code with exits just before the "} // end execute"

Check the debug window as data errors will print an explanation for the trade failure.
profile picture

gbullr

#13
I have gotten my trades to load however I have several things to resolve.
(As an aside. I was only able to get my trades to enter when the separator was a semicolon (;). A simple comma gave me all sorts of problems.)

1) I would like to know how it would be possible for me not to have to provide the entry price which kind of defeats the purpose. The Entry price is the close of the day of the buy signal or the following morning. (In my case)

Also I would like to know how to create exits.

This code below does not exit trades, unfortunately. Trades remain open.


CODE:
Please log in to see this code.


If I put the this.Import etc line in the for loop it screws up everything.
profile picture

KGo

#14
If you use Historical Trades, eliminate the input prices and replace SDP with either NDO for Next Day Open or SDC for Same Day Close. The data titles needed are Action,Symbol,EntryDate to go long and short or just use Symbol,EntryDate to always enter long.
CODE:
Please log in to see this code.


For exit try:
CODE:
Please log in to see this code.


profile picture

Eugene

#15
QUOTE:
1) I would like to know how it would be possible for me not to have to provide the entry price which kind of defeats the purpose.

If you read the documentation you might have noticed an input data format which goes by "Robert Sucher version":

Import real (historical) trades

It may contain entries and exits on separate lines. This is what I based my initial suggestion on. Adjust the code as the Wiki example suggests i.e. choose TradeFileImportMode.Format2.

QUOTE:
Also I would like to know how to create exits.

I think that a forum search for time-based exit (of which you're after if I read your post #4 correctly) should do the trick. It was discussed extensively so there are lots of pointers. Here's one example of "Exit after N days": TASC 2008-10 | Asymmetric RSI, ARSI (Vervoort)

P.S. KGo referred you to his encompassing solution which you may download: Historical Trades: splits, cash flow, multiple files, shared equity

If you decide to give it a go, here's the discussion thread where you may post your questions:

https://www.wealth-lab.com/Forum/Posts/Historical-Trades-splits-cash-flow-multiple-files-shared-equity-39101
profile picture

gbullr

#16
Eugene please check the function/module.

inputting the data like this:



leads to errors



while using either of these two lines to input the data.

CODE:
Please log in to see this code.


which are suppossedly non legacy code.

if you change to semicolon as separator then this problem does not arise.
profile picture

Eugene

#17
Checked with comma as the separator. Worked out fine for me. The outcome may depend on regional settings I guess.
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).