Code to read from TradeHistory.xml ?
Author: kazuna
Creation Date: 12/4/2017 7:21 PM
profile picture

kazuna

#1
Is there a community component or something which provides access to TradeHistory.xml?

I'm occasionally running into the "Stuck Submitted" order problem and found that those orders are not showing up in TradeHistory.xml. I think I can pragmatically detect the problem from the code after placing the order but checking the record in TradeHistory.xml.

Something like this...
CODE:
Please log in to see this code.


profile picture

Eugene

#2
Yes there is: Import real (historical) trades > Import the history of real trades from Wealth-Lab's Accounts tool. If you want to take a look at the code, find CreateCsvFileFromAccountsXml in C.Components.
profile picture

kazuna

#3
I just found out that one of my machine has a corrupted TradeHistory.xml and it hasn't been updating for quite some time.
In this case, what will happen with your code? You will get an exception or not item (record) found?
profile picture

Eugene

#4
Since you already have the corrupt file, wouldn't it be easier and natural for you to run the code and let the community know the outcome? ;)
profile picture

kazuna

#5
I'm getting "Count = 0" with the code below. I confirmed ExportedTradeHistoryFromAccounts.csv has correct trades. Any idea?
CODE:
Please log in to see this code.

Is there any way to have a separate positions rather than strategy's positions by doing something like this? (this code doesn't compile)
CODE:
Please log in to see this code.

profile picture

Eugene

#6
QUOTE:
I'm getting "Count = 0" with the code below. I confirmed ExportedTradeHistoryFromAccounts.csv has correct trades. Any idea?

Rule of thumb: on my end, code that I produced usually keeps on working until some input gets broken by 3rd party (like data feed or external website). If you get unexpected results your CSV cannot be recognized. And since I don't have it I hardly can reproduce. Please read: How to Report Bugs Effectively > "Works for me. So what goes wrong?"
profile picture

kazuna

#7
This is how ImportHistoricalTrades generates ExportedTradeHistoryFromAccounts.csv but Positions.Count returns 0.
QUOTE:
XOP,05-12-2017 00:00:00,Buy,35.96
XOP,05-12-2017 00:00:00,Sell,35.7

I changed the code like this so it bypasses CreateCsvFileFromAccountsXml but Positions.Count still returns 0.
CODE:
Please log in to see this code.

I modified ExportedTradeHistoryFromAccounts.csv as follows then Positions.Count finally returns 1.
QUOTE:
XOP,05-12-2017 09:33:00,Buy,35.96
XOP,05-12-2017 15:44:00,Sell,35.7

The buy and sell prices have to be within the range of the bar price at that time, otherwise EnterAtPrice and ExitAtPrice fail inside SimTradeFile2.

That means SimTradeFile2 doesn't support intraday scale (1 Minute)?
profile picture

kazuna

#8
It seems the problem is coming from TradeHistory.xml.
QUOTE:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfHistoricalTrade xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<HistoricalTrade>
<TimeStamp>2017-12-05T06:31:01.1282715-08:00</TimeStamp>
<AccountNumber>PaperAccount1</AccountNumber>
<TradeType>Buy</TradeType>
<Quantity>2368</Quantity>
<Symbol>XOP</Symbol>
<Price>35.96</Price>
<OrderID>ab042104-8d90-464f-aa95-29314ffd0903</OrderID>
<Scale>
<Scale>Daily</Scale>
<BarInterval>0</BarInterval>
</Scale>
<StrategyID />
<AccountTradeType />
</HistoricalTrade>
<HistoricalTrade>
<TimeStamp>2017-12-05T12:58:15.0353214-08:00</TimeStamp>
<AccountNumber>PaperAccount1</AccountNumber>
<TradeType>Sell</TradeType>
<Quantity>2368</Quantity>
<Symbol>XOP</Symbol>
<Price>35.7</Price>
<OrderID>09389f3e-8e85-4cf9-ae2c-50eb4dfccbad</OrderID>
<Scale>
<Scale>Daily</Scale>
<BarInterval>0</BarInterval>
</Scale>
<StrategyID />
<AccountTradeType />
</HistoricalTrade>
</ArrayOfHistoricalTrade>

Problem #1: Scale is Daily and BarInterval is 0 despite the strategy is set to run at 1 Minuite scale.
Problem #2: Price is out of the range at the bar. Apparently PaparAccount data provider generates wrong price.
profile picture

kazuna

#9
By the way, I was going to try implementing the XML parser by using XmlDocument class but "using System.Xml" fails in the strategy code. Any idea?
profile picture

Eugene

#10
Your TradeHistory.xml works for me:
QUOTE:
Count = 1

You should run this code on a DataSet with XOP in it.


QUOTE:
"using System.Xml" fails in the strategy code.

First you have to add a reference to System.Xml in References... > .NET.
profile picture

kazuna

#11
QUOTE:
You should run this code on a DataSet with XOP in it.

Yes, I do run this code with XOP. In fact, it runs fine if I fix the problem #1 and #2 above described.

QUOTE:
Your TradeHistory.xml works for me:

Interesting...

If the time stamp is left for 00:00:00 as ImportHistoricalTrades generates then EnterAtPrice and ExitAtPrice in SimTradeFile2 don't generate a position.
If the time stamp is modified but the price at the order isn't in the range of the bar price at the time, EnterAtPrice and ExitAtPrice in SimTradeFile2 generate an error.

It makes sense to me why SimTradeFile2 doesn't work with my original TradeHistory.xml.
Now it doesn't make sense why it works for you even if those time stamps are not correct for the trade.

QUOTE:
First you have to add a reference to System.Xml in References... > .NET.

Thank for the info! I have never looked at .NET Preferences or neither noticed it.
Is this .NET Preferences saved somewhere in XML files so that it persists on all chart windows across WLP restarts?
profile picture

Eugene

#12
QUOTE:
Is this .NET Preferences saved somewhere in XML files so that it persists on all chart windows across WLP restarts?

References, not preferences. It applies to the single Strategy window only - after save. To make the change global one has to overwrite the Default strategy template with Edit > Set as Default Template Code.

QUOTE:
Now it doesn't make sense why it works for you even if those time stamps are not correct for the trade.

Maybe a difference in our regional settings?
profile picture

kazuna

#13
QUOTE:
It applies to the single Strategy window only - after save.

Is it saved to the strategy XML files under Data\Strategies?

QUOTE:
Edit > Set as Default Template Code

Where is it saved to? WealthLabConfig.txt or somewhere else?

QUOTE:
Maybe a difference in our regional settings?

Probably but I think the price range mismatch will fail regardless of the regional settings.

Yesterday, XOP never reaches at $35.96 until 09:33 but my TradeHistory.xml indicates that it bought for $35.96 at 09:31.
profile picture

Eugene

#14
QUOTE:
Is it saved to the strategy XML files under Data\Strategies?

Yes.

QUOTE:
Where is it saved to? WealthLabConfig.txt or somewhere else?

To StrategyTemplate.txt in the same folder.

QUOTE:
Yesterday, XOP never reaches at $35.96 until 09:33 but my TradeHistory.xml indicates that it bought for $35.96 at 09:31.

I was running the code on Yahoo! Daily data (default in WLD). Am I correct to assume that the problem occurs on an intraday scale only?
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).