Difference between Chart Backtest and Portfolio Backtest  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Difference between Chart Backtest and Portfolio Backtest

Postby GTrader » 26 Jan 2016

Hi,
I'm comparing the results between a chart backtest and a backtest run in the Portfolio Trader application. The strategy is identical in both as well as the security ( SPY ). The signals are identical (i.e. the trade dates and prices), but the size of the trades differ.

I believe all the settings are identical.
a) I'm using fixed cash per trade in both
b) Portfolio Settings, Exposure 100%, Max % of Capital at Risk 100%, Potential Loss per Contract is set to Absolute Max Potential Loss 0.001 (which according to the help turns it off).

Any ideas?

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

Re: Difference between Chart Backtest and Portfolio Backtest

Postby Henry MultiСharts » 27 Jan 2016

Hello GTrader,

Your script should generate the same results in MultiCharts and Porfolio Trader if the settings are the same.
You need to have one instrument in your portfolio for the results to match with the chart. Just 1 trading instrument (data 1). 

You need to have IOG and bar magnifier disabled for your strategy in MultiCharts. 
Extended backtesting is also not available in Portfolio Trader, therefore you need to disable it in MultiCharts.
All instrument settings (resolution, quote field, data range ) should be the same in both applications. On the chart the Data Range should be specified as From_To and not Days/Bars Back. 
MultiCharts has no money management, therefore you need to configure the portfolio to have no money management limits for orders.      
In the Money Management Settings section Max % of Capital at Risk per Position should be set to 100%.  
In the Money Management Settings section Initial Portfolio Capital should be set to the highest value ($1 000 000 000).

GTrader
Posts: 83
Joined: 30 Oct 2012
Has thanked: 24 times
Been thanked: 8 times

Re: Difference between Chart Backtest and Portfolio Backtest

Postby GTrader » 27 Jan 2016

Hi Henry,
Thanks for getting back so quick. I did what you said but it still doesn't match up. I've attached the strategy and a screenshot of my Portfolio Settings. I can't get the trade sizes to match up. The problem is definitely on the Portfolio Backtester size as the trade sizes should just be based on fixed amount, but they aren't.

I don't mean to be a pain with this but I am just starting to use the Portfolio Backtester and I want to ensure I fully understand how it works. Perhaps you can see if they match on your side.
[+] See the code below

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy
{
public class m_BarHighLow : SignalObject
{
private Function.AverageFC slowAvg;
private Function.AverageFC fastAvg;

private IOrderMarket buy_onclose;
private IOrderMarket sell_onclose;
private IOrderMarket buy_nextopen;
private IOrderMarket sell_nextopen;

public m_BarHighLow(object _ctx) : base(_ctx)
{
LongSmaLength = 200;
ShortSmaLength = 5;
OrderType = OrderTypes.OnClose;
}

protected override void Create()
{
slowAvg = new AverageFC(this);
fastAvg = new AverageFC(this);
buy_onclose = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
sell_onclose = OrderCreator.MarketThisBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
buy_nextopen = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
sell_nextopen = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Sell));
}

protected override void StartCalc()
{
slowAvg.price = Bars.Close;
slowAvg.length = LongSmaLength;
fastAvg.price = Bars.Close;
fastAvg.length = ShortSmaLength;
}

protected override void CalcBar()
{

bool rule05 = Bars.Close[0] > fastAvg[0];

if (rule05)
{
switch (OrderType)
{
case OrderTypes.OnClose:
sell_onclose.Send();
break;
case OrderTypes.NextOpen:
sell_nextopen.Send();
break;
}
}

bool rule01 = Bars.High[2] < Bars.High[3] && Bars.High[1] < Bars.High[2] && Bars.High[0] < Bars.High[1];
bool rule02 = Bars.Low[2] < Bars.Low[3] && Bars.Low[1] < Bars.Low[2] && Bars.Low[0] < Bars.Low[1];
bool rule03 = Bars.Close[0] < fastAvg[0];
bool rule04 = Bars.Close[0] > slowAvg[0];

if (rule01 && rule02 && rule03 && rule04)
{
switch (OrderType)
{
case OrderTypes.OnClose:
buy_onclose.Send();
break;
case OrderTypes.NextOpen:
buy_nextopen.Send();
break;
}
}
}

[Input]
public int LongSmaLength { get; set; }

[Input]
public int ShortSmaLength { get; set; }

[Input]
public OrderTypes OrderType { get; set; }

public enum OrderTypes
{
OnClose,
NextOpen,
}
}
}
Attachments
two.JPG
(55.17 KiB) Downloaded 2054 times
one.JPG
(121.2 KiB) Downloaded 2045 times

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

Re: Difference between Chart Backtest and Portfolio Backtest

Postby Henry MultiСharts » 28 Jan 2016

Hello GTrader,

Please send us the following information for analysis of this case to support@multicharts.com:
- MultiCharts workspace you are using;
- Portfolio Trader workspace you are using;
- in QuoteManager select the symbols you are using, make a right click on the selection->Export data->Export instruments (with data). Send us the QMD export file for analysis; 
- in PowerLanguage .NET editor->File->Export->export the studies you are using for replicating this behavior; send us the pln file;
- specify the version and build number of MultiCharts you are running (in MultiCharts go to Help tab-> About).

If the file size is >10 mb please upload it to any file sharing hosting and send us the download link.

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

Re: Difference between Chart Backtest and Portfolio Backtest  [SOLVED]

Postby Henry MultiСharts » 02 Feb 2016

Hello GTrader,

Our engineers have identified the issue and forwarded it to the development team.
At the moment the fix is targeted to MultiCharts 9.1 Release 3.
There is no ETA for the version yet. Please follow our blog to get the latest updates:
https://www.multicharts.com/traders-blog/


Return to “MultiCharts .NET”