I found sometimes when i use 'Total' keyword to close position,the 'currentcontracts' will not change. Can anybody help?
Please see the log following:
Short 2 ShortQuantity: 2 currentcontracts 0 at time 1100701 91207
Short 2 ShortQuantity: 4 currentcontracts 2 at time 1100701 91208
Short 2 ShortQuantity: 6 currentcontracts 4 at time 1100701 91208
Short 2 ShortQuantity: 8 currentcontracts 6 at time 1100701 91209
Short 2 ShortQuantity: 10 currentcontracts 8 at time 1100701 91209
Short 1 ShortQuantity: 11 currentcontracts 10 at time 1100701 91210
Short 1 ShortQuantity: 12 currentcontracts 11 at time 1100701 91210
Short 1 ShortQuantity: 13 currentcontracts 12 at time 1100701 91211
Short 3 ShortQuantity: 16 currentcontracts 13 at time 1100701 91213
Short 3 ShortQuantity: 19 currentcontracts 16 at time 1100701 91213
Short 3 ShortQuantity: 22 currentcontracts 19 at time 1100701 91214
Short 3 ShortQuantity: 25 currentcontracts 22 at time 1100701 91214
Short 1 ShortQuantity: 26 currentcontracts 25 at time 1100701 91215
Short 1 ShortQuantity: 27 currentcontracts 26 at time 1100701 91215
Short 2 ShortQuantity: 29 currentcontracts 27 at time 1100701 91218
Short 1 ShortQuantity: 30 currentcontracts 29 at time 1100701 91256
Short 1 ShortQuantity: 31 currentcontracts 30 at time 1100701 91317
ShortClose 1 ShortQuantity: 30 currentcontracts 31 at time 1100701 91325
ShortClose 1 ShortQuantity: 29 currentcontracts 30 at time 1100701 91332
ShortClose 1 ShortQuantity: 28 currentcontracts 29 at time 1100701 91333
ShortClose 1 ShortQuantity: 27 currentcontracts 28 at time 1100701 91333
ShortClose 1 ShortQuantity: 26 currentcontracts 27 at time 1100701 91334
ShortClose 1 ShortQuantity: 25 currentcontracts 26 at time 1100701 91334
ShortClose 3 ShortQuantity: 22 currentcontracts 25 at time 1100701 91724
ShortClose 7 ShortQuantity: 15 currentcontracts 22 at time 1100701 91735
ShortClose 7 ShortQuantity: 8 currentcontracts 15 at time 1100701 91736
ShortClose 3 ShortQuantity: 5 currentcontracts 9 at time 1100701 91736
ShortClose 5 ShortQuantity: 0 currentcontracts 9 at time 1100701 91743
Exits using the ‘Total’ keyword do not work correctly MC 6
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Exits using the ‘Total’ keyword do not work correctly MC
you have to give more information, eg. post the snippet of code that caused the problem.I found sometimes when i use 'Total' keyword to close position,the 'currentcontracts' will not change. Can anybody help?
Please see the log following:
...
Re: Exits using the ‘Total’ keyword do not work correctly MC
Open position code:
Close position code:
Code: Select all
sellshort OrderEntryNum contract this bar at Close;
ShortQuantity = ShortQuantity + OrderEntryNum;
FileAppend("d:\TradeRecord.log"," Short " + NumToStr(OrderEntryNum,0) + " " + " ShortQuantity: " + NumToStr(ShortQuantity,0)+ " currentcontracts " + NumToStr(currentcontracts,0) +" at time " + NumToStr(date,0) + " " + NumToStr(time_s,0) + NewLine);
Code: Select all
if CloseNum <> 0 then
begin
buytocover CloseNum contract total this bar at close;
FileAppend("d:\TradeRecord.log"," ShortClose " + NumToStr(CloseNum ,0) + " " + " ShortQuantity: " + NumToStr(ShortQuantity ,0)+ " currentcontracts " + NumToStr(currentcontracts,0) +" at time " + NumToStr(date,0) + " " + NumToStr(time_s,0) + NewLine);
Actioned = True;
end;
Re: Exits using the ‘Total’ keyword do not work correctly MC
Hi,TJ. If you think the code is still not enough, I will try to give more information.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Exits using the ‘Total’ keyword do not work correctly MC
is this a back test ? or a live sim test?
see EasyLanguage Essentials Programmers Guide
pg 80: Strategy Order Syntax
see EasyLanguage Essentials Programmers Guide
pg 80: Strategy Order Syntax
this bar on Close: Market order on the close of this bar, generally used for historical backtesting
purposes only. This will not generate a market on close order.
Re: Exits using the ‘Total’ keyword do not work correctly MC
It's a tick data back test in extended mode.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: Exits using the ‘Total’ keyword do not work correctly MC
some suggestions:
1. I would take out the "this bar on Close". This is a legacy testing method. Nobody uses this statement anymore. Besides, once you have decided to go live, you have to change it anyway, so might as well code the strategy properly to start with.
2. try a forward live test on the sim/paper account. Print statements can be tricky in backtests.
1. I would take out the "this bar on Close". This is a legacy testing method. Nobody uses this statement anymore. Besides, once you have decided to go live, you have to change it anyway, so might as well code the strategy properly to start with.
2. try a forward live test on the sim/paper account. Print statements can be tricky in backtests.
Re: Exits using the ‘Total’ keyword do not work correctly MC
Hi,TJ.
I don't know why
And this bug only occurs when I close more than one position once.
If i close only one position once,just no problem.
I don't know why
It just works well for me.Nobody uses this statement 'this bar on Close' anymore.
And this bug only occurs when I close more than one position once.
If i close only one position once,just no problem.
Re: Exits using the ‘Total’ keyword do not work correctly MC
I think this bar on close doesn't relate to real-time trading. The following is taken from one of the user guides ELreference2000i.pdf:
"The execution method this bar on close is provided for backtesting purposes only; it enables
you to backtest ‘market at close’ orders, which you cannot automate using
TS. Given that all orders are evaluated and executed at the end of each bar,
TS reads and issues the this bar on close order once the bar has closed (e.g., once
the daily trading session has ended). TS fills the order using the close of the current
bar, but you must place an order at market for execution on the next bar. This invariably
introduces slippage."
So, has this changed with MultiCharts? If it has, what does it mean? Does it mean at market when applied in real-time, or some sort of limit order? If it hasn't changed then I would discourage the use of this bar on close as it means you have to have two versions of the code, one for backtesting and one for real-time trading. One might as well use the next bar at market or some limit order type to be consistent.
"The execution method this bar on close is provided for backtesting purposes only; it enables
you to backtest ‘market at close’ orders, which you cannot automate using
TS. Given that all orders are evaluated and executed at the end of each bar,
TS reads and issues the this bar on close order once the bar has closed (e.g., once
the daily trading session has ended). TS fills the order using the close of the current
bar, but you must place an order at market for execution on the next bar. This invariably
introduces slippage."
So, has this changed with MultiCharts? If it has, what does it mean? Does it mean at market when applied in real-time, or some sort of limit order? If it hasn't changed then I would discourage the use of this bar on close as it means you have to have two versions of the code, one for backtesting and one for real-time trading. One might as well use the next bar at market or some limit order type to be consistent.
Re: Exits using the ‘Total’ keyword do not work correctly MC
Thank you,janus.
Now i know that maybe 'this bar on close' is not suitable for real-time trading.
For me, i use multicharts just for back test.
I trade through self-designed software.
So i still care about how to make the 'Total' keyword work correctly in back test.
And i have to use ' this bar on close'.
Or is there any replaceable solution?
Now i know that maybe 'this bar on close' is not suitable for real-time trading.
For me, i use multicharts just for back test.
I trade through self-designed software.
So i still care about how to make the 'Total' keyword work correctly in back test.
And i have to use ' this bar on close'.
Or is there any replaceable solution?
Re: Exits using the ‘Total’ keyword do not work correctly MC
I don't do much backtesting. I prefer forward testing using real-time data. So, I use total next bar at market, and I haven't come across any problem so far. I suggest you try it for backtesting to see if it helps.
Re: Exits using the ‘Total’ keyword do not work correctly MC
Thank you, janus.
I have to use this bar on close.
For me, use next bar will completely change my strategy because i am doing statistical arbitrage.
I have to use this bar on close.
For me, use next bar will completely change my strategy because i am doing statistical arbitrage.
Re: Exits using the ‘Total’ keyword do not work correctly MC
Maybe in most markets it's true.I'm not certain but next bar at market may end up being the same for backtesting since open nearly always = close[1] in most markets.
But spread tick data is a little different.
Re: Exits using the ‘Total’ keyword do not work correctly MC
Yes,I will try it.I see - using tick data does prevent you using the approach I suggested. I'll have to give it some more thought.
Re: Exits using the ‘Total’ keyword do not work correctly MC
If you are plotting tick data then using next bar at market will give you different results, but may not be too different for your purposes as sometimes it will higher and sometimes will be lower so over time things may average out somewhat.Yes,I will try it.