How does MC caculate slippage in backtesting?  [SOLVED]

Questions about MultiCharts and user contributed studies.
kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

How does MC caculate slippage in backtesting?

Postby kernel » 22 Feb 2013

hi,

I noticed that even with commission fees set to 0 in backtesting, slippage of 0~2 points occurs, more interestingly, it varies each time, but depending on what? or does MC simply randomly set the slippage in backtesting?

User avatar
TJ
Posts: 7284
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 992 times
Been thanked: 2071 times

Re: How does MC caculate slippage in backtesting?

Postby TJ » 22 Feb 2013

hi,

I noticed that even with commission fees set to 0 in backtesting, slippage of 0~2 points occurs, more interestingly, it varies each time, but depending on what? or does MC simply randomly set the slippage in backtesting?
A lot of factors can a influence the results of your backtesting; your code, your setting, your chart...
You can start your investigation here:
Autotrade / Backtest / Optimization FAQ
viewtopic.php?f=16&t=10811

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby kernel » 22 Feb 2013

hi,

I noticed that even with commission fees set to 0 in backtesting, slippage of 0~2 points occurs, more interestingly, it varies each time, but depending on what? or does MC simply randomly set the slippage in backtesting?
A lot of factors can a influence the results of your backtesting; your code, your setting, your chart...
You can start your investigation here:
Autotrade / Backtest / Optimization FAQ
viewtopic.php?f=16&t=10811
as far as slippage is concerned, I'd like to know how it gets treated and processed in backtesting but not the real world, is it even considered, if so, how it gets set, to what value?
To simplify matters, transaction cost was set to zero in my test.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 22 Feb 2013

Hello Kernel,

If slippage is set to >0 in Strategy Properties, then it will affect both backtesting and auto-trading (limit orders are not affected by slippage since MC 8.5). And TJ is right, there are multiple factors affecting order execution in backtesting.

kernel
Posts: 91
Joined: 19 Feb 2013
Has thanked: 21 times
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby kernel » 22 Feb 2013

Hello Kernel,

If slippage is set to >0 in Strategy Properties, then it will affect both backtesting and auto-trading (limit orders are not affected by slippage since MC 8.5). And TJ is right, there are multiple factors affecting order execution in backtesting.
hi Andrew,

Even with slippage set to 0 in backtesting, slippages from 0 to 2 were observed, fyi, to reduce the number of variables, I also set commissions to 0. That's why I was wondering how splippage got set in MC, randomly set between 0 and 2 each time or by some formula?

Thanks.

User avatar
JoshM
Posts: 2100
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1526 times
Been thanked: 1507 times
Contact:

Re: How does MC caculate slippage in backtesting?

Postby JoshM » 23 Feb 2013

If slippage is set to >0 in Strategy Properties, then it will affect both backtesting and auto-trading (limit orders are not affected by slippage since MC 8.5). And TJ is right, there are multiple factors affecting order execution in backtesting.
Even with slippage set to 0 in backtesting, slippages from 0 to 2 were observed, fyi, to reduce the number of variables, I also set commissions to 0. That's why I was wondering how splippage got set in MC, randomly set between 0 and 2 each time or by some formula?
I'm not sure if I follow you Andrew, but since which MultiCharts version does slippage (the setting in the Strategy Properties window) fluctuate on a per-trade basis? As far as I know, previously the slippage was a fixed value that was added to every transaction, and not something that would fluctuate.

Kernel, if you use limit orders, the Limit Order Execution Assumptions might give varying execution slippage, the Bar Magnifier can help make the backtest result more precise (i.e., less execution slippage with a liquid instrument), and there are also Intra-bar price movement assumption during backtesting.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 26 Feb 2013

Even with slippage set to 0 in backtesting, slippages from 0 to 2 were observed, fyi, to reduce the number of variables, I also set commissions to 0. That's why I was wondering how splippage got set in MC, randomly set between 0 and 2 each time or by some formula?
.
If you have a particular case, you can demonstrate it via remote connection from our live chat and we will be able to answer your questions. JoshM is right, there are some other factors.
I'm not sure if I follow you Andrew, but since which MultiCharts version does slippage (the setting in the Strategy Properties window) fluctuate on a per-trade basis? As far as I know, previously the slippage was a fixed value that was added to every transaction, and not something that would fluctuate.
Since MultiCharts 8.5 slippage setting in Strategy Properties does not affect limit orders (and stop limit orders). With stop orders and market orders it works as it used to.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 279 times

Re: How does MC caculate slippage in backtesting?

Postby MAtricks » 13 Mar 2013

Why are the answers here so vague? It seems like a simple enough question: How does Multicharts calculate the inputted slippage amount during a back-test?

If I input $10 of slippage the result is completely different than if I input $10 of commission. I'm curious about how these are simulated during a back-test as well.

Edit: Looking closer, I see that slippage does change, but it generally is calculated once per round trip and commissions are calculated on each side of the trade which makes sense.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 15 Mar 2013

Commission:
Select per Trade to specify that the dollar amount entered represents slippage per trade, or
Select per Share/Contract to specify that the dollar amount entered represents slippage per share/contract

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 279 times

Re: How does MC caculate slippage in backtesting?

Postby MAtricks » 15 Mar 2013

The question:
Why are the answers here so vague? It seems like a simple enough question: How does Multicharts calculate the inputted slippage amount during a back-test?

If I input $10 of slippage the result is completely different than if I input $10 of commission. I'm curious about how these are simulated during a back-test as well.

Edit: Looking closer, I see that slippage does change, but it generally is calculated once per round trip and commissions are calculated on each side of the trade which makes sense.
The answer:
Commission:
Select per Trade to specify that the dollar amount entered represents slippage per trade, or
Select per Share/Contract to specify that the dollar amount entered represents slippage per share/contract
Misunderstanding?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 15 Mar 2013

The question:
Why are the answers here so vague? It seems like a simple enough question: How does Multicharts calculate the inputted slippage amount during a back-test?

If I input $10 of slippage the result is completely different than if I input $10 of commission. I'm curious about how these are simulated during a back-test as well.

Edit: Looking closer, I see that slippage does change, but it generally is calculated once per round trip and commissions are calculated on each side of the trade which makes sense.
The answer:
Commission:
Select per Trade to specify that the dollar amount entered represents slippage per trade, or
Select per Share/Contract to specify that the dollar amount entered represents slippage per share/contract
Misunderstanding?
I i believe so. What exactly you expect to read?
You put 1 to slippage field and set it to per contract and your slippage for an order will be = number of contracts * 1;
You put 1 to slippage field and set it to per trade and your slippage for an will be = 1.
Works for market and stop orders.

If something is still not clear for you, please specify your question.

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Commission Rule changes my exit signal

Postby amadeu1 » 11 May 2013

Attached are a couple of screenshots. I ran my trading strategy on Tbonds with no slippage and no commission. in screenshot2 you see some of the signals on the chart. Then i created a new Fixed Commission Rule (17.5 USD Cash per contract) and applied that and in screenshot 8 you see the same trading signals on the chart. As you can see it changed the exitshort signal . Can you explain me how that is possible ?
Attachments
Commission settings change the trading signal.zip
(416.8 KiB) Downloaded 671 times

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 12 May 2013

I am trading futures for many years and use limit orders in my trading always. I know for example that when i trade TBond Futures i will encounter around 17 $ one way slippage on my limit orders. When i backtest new trading strategies i need to encode this 17 $ slippage for my backtesting to get meaningful results. What was the reason for you to ignore the slippage in limit orders for backtesting since MC 8.5 ?
If i use instead of slippage 17 $ commission will it reflect the same PL results ? Even when its the same I am very sceptical to use the commission setting because when i use that it even changes trading signals (see my other forum entry here: viewtopic.php?f=1&t=17104)

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 12 May 2013

Here you can see a screenshot when zero commission and zero slippage is applied ( screenshot two) and here you see the same with my commission attached (see screenshot six) ... see how some of the exit signals simply dissappeared ... why is that ?
Attachments
Show error.zip
(421.4 KiB) Downloaded 542 times

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 13 May 2013

I know for example that when i trade TBond Futures i will encounter around 17 $ one way slippage on my limit orders.
Would you be able to explain what exactly you mean by "slippage" for limit orders? Since limit orders are executed at a particular price or a better price, do you mean that slippage = the distance between the price of a limit order and actual price of that limit order execution? Do you use the option to convert unexecuted limit order into market orders in auto trading?
What was the reason for you to ignore the slippage in limit orders for backtesting since MC 8.5 ?
Our customers contacted us multiple times to explain that slippage is not possible for limit orders.
If i use instead of slippage 17 $ commission will it reflect the same PL results ?
Before MultiCharts 8.5, was the slippage set to per trade or per contract? How was set the commission at the same moment?

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 13 May 2013

First of all i want you to know that I am talking here about bachtesting and NOT autotrading. For backtesting, slippage in a limit order is the ASSUMED difference between the price of the limit order and the actual price the order is executed. This assumed difference i have to encode as slippage in MC for backtesting. Right now in backtesting MC assumes that I am filled at all my limit orders at the limit price. This is not realistic ! Backtesting without considering a slippage in limit orders is useless and completely unrealistic.

The people that explain you that there is no slippage in limit orders in backtesting have probably never traded in their lives. Just think about it: Lets say in real trading you buy 10 contracts at 112 limit and there are 5000 contracts in front of you at the same price. The market is above 113 and goes down and 1 contracts trades briefly at 112 and then market goes back up to 115. Then for backtesting purposes the current version of MC assumes that I am filled at 112. This is wrong.

So you had it correctly in MC before MC 8.5 . People that did backtesting could encode a slippage estimate for their trades. Now limit orders are excempt. This is totally unrealistic.

Best would be the following:

The user should be able to encode a slippage estimate in backtesting for limit orders and a different one for Stop orders. This is because stop orders have different slippages as limit orders . That i know out of experience and you want to do your backtesting as realistic as possible. The best would be to have an option to encode the slippage estimate for backtesting in either a fixed amount (as done in pre MC8.5) or as a percentage. The percentage is very good because a market that trades at 100 and then rises to 2000 has another slippage at 2000 than at 100. Here a % slippage estimate would be good to have.

Anyways for the short term its important to have the slippage in limit orders for backtesting back . At least I should have the option to do that.

I tried to work around this and instead of encoding a slippage number i encoded a commission rule. However when i do that then trading signals dissapear from the chart . Why is that ?

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 13 May 2013

... slippage was set per contract --- to answer your last question

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 13 May 2013

First of all i want you to know that I am talking here about bachtesting and NOT autotrading.
Of course i understand this, but since everyone's goal is to make backtesting as realistic as possible, i need to understand what are the settings for your real-time auto trading.
For backtesting, slippage in a limit order is the ASSUMED difference between the price of the limit order and the actual price the order is executed.
A limit order is executed at a price level or better. Slippage in MC is considered to be a dollar amount of loss if an order is executed with a price that is worse. Worse price for limit order execution should not be possible, this is what i mean when i say that slippage for limit order should not be possible. It seems to me that what you are talking is not a slippage, since you describe a scenario, when you get more profit due to better execution price, than loss (that would be slippage). Please correct me if i am wrong.
This assumed difference i have to encode as slippage in MC for backtesting. Right now in backtesting MC assumes that I am filled at all my limit orders at the limit price. This is not realistic ! Backtesting without considering a slippage in limit orders is useless and completely unrealistic.
One of the main points that explains possible difference between backtesting results vs. real-time auto trading is that during backtesting an order is executed immediately and completely when a certain price level (required for its execution) is met, meanwhile during auto trading in real time execution of orders may be performed at a different price due to absence of volume or queue at broker end. Unfortunately it is not possible to take this aspect into account for backtesting.
I tried to work around this and instead of encoding a slippage number i encoded a commission rule. However when i do that then trading signals dissapear from the chart . Why is that ?
If you change commissions or slippage, you should expect difference in backtesting results.
... slippage was set per contract --- to answer your last question
The key point for me in this questions was to find out if both the slippage and commission were set to the same per contract/per trade, or they were set to different ones? So now, was the commission set to per contract at the same time or to per trade?

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 13 May 2013

[/quote]
Of course i understand this, but since everyone's goal is to make backtesting as realistic as possible, i need to understand what are the settings for your real-time auto trading.

I dont use autotrading. I only use backtesting... I only do research, no trading through MC and as a researcher i need to estimate how much money i can really earn with my model


[/quote]
A limit order is executed at a price level or better. Slippage in MC is considered to be a dollar amount of loss if an order is executed with a price that is worse. Worse price for limit order execution should not be possible, this is what i mean when i say that slippage for limit order should not be possible. It seems to me that what you are talking is not a slippage, since you describe a scenario, when you get more profit due to better execution price, than loss (that would be slippage). Please correct me if i am wrong.

I think we have a general misunderstanding about slippage here.

Lets say i have a simple system that buys always at the low of yesterday minus yesterdays range and exits at close of the day.
Now lets assume yesterdays low is 90 and yesterdays range is 10. So the model wants me to buy at 80 . So MC assumes that I am filled at 80 as soon as 80 is traded - even when its only a 1 lot. Now lets further assume that the close of the day is 100 and todays low was indeed 80. That means MC says I made 20. Now lets suppose i have 1000 trades EXACTLY like this. Then MC says i made 20.000. This theoretical profit is completely useless for me because its not realistic. Most likely for every trade i tried to buy at 80 I ended up trading my contracts 1 or two ticks higher (=worse). This "worse" price minus the limit price i call slippage.
So i know from trading that average I pay 1.5 ticks more than my limit prices. So this 1.5 ticks i want to encode in MC so that the theoretical PL does not show 20.000 but 20.000 minus the total slippage. So when i design a model with limit orders i need to know how much of realistic PL can i expect from it. To backtest with 0 slippage does not give me a realistic picture of what i could earn with my model later on.


[/quote]
One of the main points that explains possible difference between backtesting results vs. real-time auto trading is that during backtesting an order is executed immediately and completely when a certain price level (required for its execution) is met, meanwhile during auto trading in real time execution of orders may be performed at a different price due to absence of volume or queue at broker end. Unfortunately it is not possible to take this aspect into account for backtesting.

I think you can take this aspect into account if the user just encodes a "theoretical" slippage that gets deducted from my theoretical PL every time the model trades (in backtesting). It does not give me an exact true picture but an estimation of how much i could earn with a certain model. To assume 0 slippage gives me a PL that is way too optimistic.

[/quote]
If you change commissions or slippage, you should expect difference in backtesting results.


[/quote]
The key point for me in this questions was to find out if both the slippage and commission were set to the same per contract/per trade, or they were set to different ones? So now, was the commission set to per contract at the same time or to per trade?[/quote]

CASH per contract (for commissions and for slippage)

I attach again the two
Attachments
two versions.zip
(306.59 KiB) Downloaded 612 times

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 13 May 2013

I dont use autotrading. I only use backtesting... I only do research, no trading through MC and as a researcher i need to estimate how much money i can really earn with my model
Sir, do you understand that there are multiple ways you can set up auto trading? If you are interested in realistic backtesting, then you should make sure it is set up respectively, because there are multiple ways to set up backtesting, just like auto trading. I do understand you are talking about backtesting, but it is not possible to configure "realistic" backtesting without knowing how you are going to configure real auto trading.
I think we have a general misunderstanding about slippage here.

Lets say i have a simple system that buys always at the low of yesterday minus yesterdays range and exits at close of the day.
Now lets assume yesterdays low is 90 and yesterdays range is 10. So the model wants me to buy at 80 . So MC assumes that I am filled at 80 as soon as 80 is traded - even when its only a 1 lot. Now lets further assume that the close of the day is 100 and todays low was indeed 80. That means MC says I made 20. Now lets suppose i have 1000 trades EXACTLY like this. Then MC says i made 20.000. This theoretical profit is completely useless for me because its not realistic. Most likely for every trade i tried to buy at 80 I ended up trading my contracts 1 or two ticks higher (=worse). This "worse" price minus the limit price i call slippage.
So i know from trading that average I pay 1.5 ticks more than my limit prices. So this 1.5 ticks i want to encode in MC so that the theoretical PL does not show 20.000 but 20.000 minus the total slippage. So when i design a model with limit orders i need to know how much of realistic PL can i expect from it. To backtest with 0 slippage does not give me a realistic picture of what i could earn with my model later on.
A Buy Limit order with price 100 is to buy at 100 or any lower price. "Worse" for this buy limit order would be execution at 101 or any higher price, that is of course not possible.
If Bar Magnifier is not used, MultiCharts can only assume how the price was moving inside a bar. So the buy limit order can be filled both at 80 or at 100 from your example, depending on which of the prices is reached first according to the intrabar price movement assumption, it doesn't matter what is the Low price, without knowing what is Open, High and Close of the current bar where the order is supposed to be executed.
If you want to get realistic intrabar price sequence and actual prices the 1 tick Bar Magnifier feature should be used.
This article explains the difference in calculation and order execution for both backtesting and real-time trading.
I think you can take this aspect into account if the user just encodes a "theoretical" slippage that gets deducted from my theoretical PL every time the model trades (in backtesting). It does not give me an exact true picture but an estimation of how much i could earn with a certain model. To assume 0 slippage gives me a PL that is way too optimistic.
If you want, you can hardcode the slippage within your script, for example by changing limit order price taking into account the slippage.
CASH per contract (for commissions and for slippage)
If both commissions and slippage were set to per contract in MC prior current version, then starting with MC 8.5 you can emulate slippage by adding it to commission rules, so it should be working ok.

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 14 May 2013

"If both commissions and slippage were set to per contract in MC prior current version, then starting with MC 8.5 you can emulate slippage by adding it to commission rules, so it should be working ok."

This is exactly my problem... when i try to do that some signals just dissappear. See my Posts above (post#14 and below again)

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 14 May 2013

"
This is exactly my problem... when i try to do that some signals just dissappear. See my Posts above (post#14 and below again)
In your test you compare the following (please correct me if i am wrong):
  • MC 8.5: Chart + Strategy
    vs.
  • MC 8.5: Chart + Strategy + Commission (including slippage).
Such test is not relevant.

You can perform the following test:
  • MC 8.0: Chart + Strategy + Commission A (set to per contract) + Slippage B (set to per contract)
    vs.
  • MC 8.5: Chart + Strategy + Commission C (commission A + slippage B) set to per contract.
These 2 scenarios should match.

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?

Postby amadeu1 » 14 May 2013

http://www.youtube.com/watch?v=T5ILIqFQ ... e=youtu.be


Here you see what i mean. I apply a signal to a chart - first with zero slippage and no commission. After that you see some buy and sell and exit signals on the chart. After that i apply my commission rule and then suddenly some more exit signals appear. Why is that ?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 14 May 2013

Dear Amadeu1,

As i have mentioned previously, one should expect different results in backtesting if he changes commission settings, especially comparing 0 commission vs. any different commission rules. If it is not 0, it is taken into account for script calculation and order execution, affecting strategy behavior.

amadeu1
Posts: 64
Joined: 11 Feb 2008
Has thanked: 1 time
Been thanked: 4 times

Re: How does MC caculate slippage in backtesting?  [SOLVED]

Postby amadeu1 » 14 May 2013

I do understand now how it works.

I had the following exits:

if marketposition=-1 and barssinceentry>5 and openpositionprofit<0 then begin
buy to cover stk contracts next BAR at low limit;

end;
if marketposition=1 and barssinceentry>5 and openpositionprofit<0 then begin
SELL stk contracts next BAR at high limit;
end;

This meant that when you counted in commissions then openpositionprofit is different and thus exitsignals may appear or not.

So for me the workaround is to use Commissions instead of slippage settings

Thanks for the help

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 558 times

Re: How does MC caculate slippage in backtesting?

Postby Andrew MultiCharts » 15 May 2013

You are welcome, Amadeu1.
Please let us know if you have any further questions.


Return to “MultiCharts”