Monitor Account Size and trading results  [SOLVED]

Questions about MultiCharts and user contributed studies.
Wally_AD
Posts: 47
Joined: 28 Jan 2014
Has thanked: 8 times
Been thanked: 7 times

Monitor Account Size and trading results

Postby Wally_AD » 03 Jan 2015

Hi,
Running an intraday system I would like to monitor account size and trading results in this manner:

- write results into a file and make this file available to other devices (e.g. by copying it into a Dropbox folder)
- output current account size and trade results after closing trades
- using a paper trading account
- if nothing happens then write the file once per hour
- data feed is IQFeed and my broker is IB

My intention is to see whether real trading results meet backtest results.

I use this code:

Code: Select all

If (ATS_Monitoring and Date=CurrentDate and RegularMarketHours and BarStatus(1) = 2) and
( MP <> MP[1] or NetProfit <> NP or Mod(TimeToMinutes(time),60) = 0) then begin
value1=GetRTAccountNetWorth("DU16****");
value2=GetRTUnrealizedPL("DU16***");
TraceOutStr = DateToString(DateToJulian(Date)) + " " + TimeToString(ELTimeToDateTime(Time))+
" Account=" + NumToStr(value1,2) +
" open Trade=" + NumToStr(value2,2) +
" NetProfit=" + NumToStr(NetProfit,2);
FileAppend(Trace_path+"Account_Size.txt",TraceOutStr+NewLine);
end;
The results from last Friday do not look correct. This output was produced:
29.12.2014 10:00:00 Account=816645.00 open Trade=0.00 NetProfit=0.00
29.12.2014 11:00:00 Account=816627.00 open Trade=-38.00 NetProfit=0.00
29.12.2014 12:00:00 Account=816970.00 open Trade=-58.00 NetProfit=-164.00
29.12.2014 13:00:00 Account=818190.00 open Trade=-48.00 NetProfit=-164.00
29.12.2014 14:00:00 Account=818144.00 open Trade=3.00 NetProfit=-164.00
02.01.2015 09:00:00 Account=827690.00 open Trade=0.00 NetProfit=0.00
02.01.2015 10:00:00 Account=826805.00 open Trade=0.00 NetProfit=0.00
02.01.2015 11:00:00 Account=827901.00 open Trade=-21.00 NetProfit=-264.00
02.01.2015 12:00:00 Account=827802.00 open Trade=0.00 NetProfit=-407.00
02.01.2015 13:00:00 Account=827584.00 open Trade=-42.00 NetProfit=-407.00
02.01.2015 14:00:00 Account=828033.00 open Trade=0.00 NetProfit=-286.00
The account size could not change so much according to the netprofits.
And I am not sure to which time frame the netprofit belongs. How to make sure that it belongs only to one day?
Is the code ok?

Backtesting shows anyway totaly different results.
Backtesting shows two trades, which made $121 each.
This is the major problem.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Monitor Account Size and trading results

Postby TJ » 03 Jan 2015

not into debugging yet...

First step:

Get rid of those value1 value2, condition1, etc.,
and replace them with meaningful variable names.

Variable names are free...
Meaningful variable names can help you avoid errors, and speed up debugging.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Monitor Account Size and trading results

Postby TJ » 03 Jan 2015

Have you read this article in Wiki?

Why is Data Playback strategy performance different from Backtesting results?

Wally_AD
Posts: 47
Joined: 28 Jan 2014
Has thanked: 8 times
Been thanked: 7 times

Re: Monitor Account Size and trading results

Postby Wally_AD » 03 Jan 2015

Thanks TJ.

Those variable names were used exceptionally. It is not an issue in a small if condition.

I think I roughly read the article in the Wiki. But will consider it again.

I am testing a system with the ES and use target limit and stop loss orders.
I would understand if the results differ in ticks, but they are far away from each other.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Monitor Account Size and trading results

Postby TJ » 03 Jan 2015

Thanks TJ.
Those variable names were used exceptionally. It is not an issue in a small if condition.
I think I roughly read the article in the Wiki. But will consider it again.
I am testing a system with the ES and use target limit and stop loss orders.
I would understand if the results differ in ticks, but they are far away from each other.
Testing for stops might be tricky... a lot is depend on how you code your stops.

You might also be interested in this Wiki article:

Backtesting vs Live Trading


Lots of helpful info here:
viewtopic.php?f=16&t=10811

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Monitor Account Size and trading results  [SOLVED]

Postby JoshM » 04 Jan 2015

The results from last Friday do not look correct. This output was produced:
29.12.2014 10:00:00 Account=816645.00 open Trade=0.00 NetProfit=0.00
29.12.2014 11:00:00 Account=816627.00 open Trade=-38.00 NetProfit=0.00
29.12.2014 12:00:00 Account=816970.00 open Trade=-58.00 NetProfit=-164.00
29.12.2014 13:00:00 Account=818190.00 open Trade=-48.00 NetProfit=-164.00
29.12.2014 14:00:00 Account=818144.00 open Trade=3.00 NetProfit=-164.00
02.01.2015 09:00:00 Account=827690.00 open Trade=0.00 NetProfit=0.00
02.01.2015 10:00:00 Account=826805.00 open Trade=0.00 NetProfit=0.00
02.01.2015 11:00:00 Account=827901.00 open Trade=-21.00 NetProfit=-264.00
02.01.2015 12:00:00 Account=827802.00 open Trade=0.00 NetProfit=-407.00
02.01.2015 13:00:00 Account=827584.00 open Trade=-42.00 NetProfit=-407.00
02.01.2015 14:00:00 Account=828033.00 open Trade=0.00 NetProfit=-286.00
The account size could not change so much according to the netprofits.
I'm also not sure if the NetProfit is correct here. If I add up the individual trades, I end up with -204 and not -286. Or aren't these all the trades?
And I am not sure to which time frame the netprofit belongs. How to make sure that it belongs only to one day?
NetProfit returns the profit of all completed trades, so irrespective of a time frame.

If you want to only have a daily netprofit (or any other time frame), you'll need to manually create a variable for that, like this rough example:

Code: Select all

Variables:
dailyNetProfit(0);

if (Date <> Date[1]) then begin

dailyNetProfit = NetProfit - dailyNetProfit;

Print("Net profit for date ",
FormatDate("d-M-yyyy", DateTime[1]),
" is ",
dailyNetProfit);

dailyNetProfit = NetProfit;

end;
Backtesting shows anyway totaly different results.
Backtesting shows two trades, which made $121 each.
This is the major problem.
Which backtesting settings did you use? (Intra-bar order generation, Bar magnifier)

Code: Select all

value1=GetRTAccountNetWorth("DU16****");
(...)
The account size could not change so much according to the netprofits.
GetRTAccountNetWorth returns the 'Net Liquidation Value' as you would see in IB TWS, in base currency. If I recall correctly (can't test it now), this value is also influenced by margin and other open positions. GetRTAccountEquity, on the other hand, returns the regular account equity.

Wally_AD
Posts: 47
Joined: 28 Jan 2014
Has thanked: 8 times
Been thanked: 7 times

Re: Monitor Account Size and trading results

Postby Wally_AD » 04 Jan 2015

The listed trade results were not complete. But for the day "02.01." they were complete.

If margin is included I can see the problem - will be changed to GetRTAccountEquity.

I used IOG = off and Bar Magnifier was not used.

I understand now, to get meaningful back testing results I have to use Bar Magnifier.
I used 2 minute bars, but have to backtest on a tick-by-tick basis.

(otherwise with OHLC points it can't be determined whether target price or stop loss price is reached).

I have to study more seriously the available backtesting information in the Wiki/forum.

I previously used IOG and two time frames, but got an issue with writing files (but this is another topic).

Thanks so far.

Wally_AD
Posts: 47
Joined: 28 Jan 2014
Has thanked: 8 times
Been thanked: 7 times

Re: Monitor Account Size and trading results

Postby Wally_AD » 05 Jan 2015

Using 2 minutes bars I now used Bar Magnifier (switched it on) and selected - 1 tick - .
This provided no different results as without Bar Magnifier. I assume this is because still the chart resolution is used. How can I obtain the tick resolution now? Changing on the chart the resolution would mean I need two time frames in the signal script (tick and 2 minutes) and had to adapt the software. Or is is sufficient to turn IOG on?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Monitor Account Size and trading results

Postby JoshM » 05 Jan 2015

This provided no different results as without Bar Magnifier. I assume this is because still the chart resolution is used. How can I obtain the tick resolution now? Changing on the chart the resolution would mean I need two time frames in the signal script (tick and 2 minutes) and had to adapt the software. Or is is sufficient to turn IOG on?
I don't think this is caused by the chart resolution. Personally, I haven't run into a situation where I needed to add a second data series to get a fine(r) granularity that the Bar Magnifier couldn't deliver (but your usage case can differ, of course).

But given the time it costs to rewrite your code, I'd suggest to first experiment with IOG to see if that brings you closer to a solution.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Monitor Account Size and trading results

Postby Henry MultiСharts » 06 Jan 2015

Wally_AD, please study the following article: How Signals are Calculated and let us know in case you have any specific questions.


Return to “MultiCharts”