inaccurate entries/exits  [SOLVED]

Questions about MultiCharts and user contributed studies.
moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

inaccurate entries/exits

Postby moreno » 01 Jul 2020

hi,
I have one simple strategy based on stochastic for long entries, one strategy for position loss management/exits. both work together
on the same instrument MES. IB DEMO mode.
most of the exits/new entries are not accurate with too much slippage although not volatile market.
using MES future regular chart, IOG enabled, the data stream from IB seems OK.
example - buy entry at 3112.25 - accurate according to entry signal.
next - inaccurate position management - first "recovery 1" failed with -22.19 loss (instead of -15), second "recovery 2" failed with -29.38 (instead of -15), and so on...
does someone know what may be the problem?
The recovery strategy as follows -

Code: Select all

[IntrabarOrderGeneration = True] if marketposition = 1 and openpositionprofit < -15 then sellshort ("recovery 1" ) 2 contracts this bar at close; if marketposition = -1 and openpositionprofit < -15 then buy ("recovery 2") 2 contracts this bar at close; setprofittarget(30);

Mydesign
Posts: 177
Joined: 15 Feb 2017
Has thanked: 32 times
Been thanked: 39 times

Re: inaccurate entries/exits

Postby Mydesign » 01 Jul 2020

Hi,

Try "next bar market" instead of "this bar close".

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

Re: inaccurate entries/exits

Postby TJ » 01 Jul 2020

What is your chart resolution?

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

Re: inaccurate entries/exits

Postby TJ » 01 Jul 2020


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

Re: inaccurate entries/exits

Postby JoshM » 01 Jul 2020

most of the exits/new entries are not accurate with too much slippage although not volatile market.
using MES future regular chart, IOG enabled, the data stream from IB seems OK.
example - buy entry at 3112.25 - accurate according to entry signal.
next - inaccurate position management - first "recovery 1" failed with -22.19 loss (instead of -15), second "recovery 2" failed with -29.38 (instead of -15), and so on...
In addition to what the previous posters said, you can also try and run the strategy with the 'Bar Magnifier' feature enabled. That way MultiCharts can perform several calculations on historical bars, which should make your strategy faster to respond in the backtest.

Unfortunately, I don't think it's possible with your code to really ensure that the 'recovery signal' happens at exactly -15 loss. That's because the strategy first has to register that loss, and then determine its next action. But at that point the market may have already moved a couple more ticks, giving you a worse loss.

Can perhaps your strategy send a buy stop and short stop at the price level that defines a -15 loss? That should make the strategy a bit faster to respond. You might even want to send the stop at the -14 level to account for one tick of slippage.

moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

Re: inaccurate entries/exits

Postby moreno » 02 Jul 2020

Guys thanks for your wise reference,
the phenomena still occur with less slippage but I have noticed something...I'll try to explain -
it seems that the system refers to the new amount of contracts (2 contracts, in the take profit/recovery strategy)
instead of the first original long order (buy 1 contract)...
for this example - buy 1 contract (in the original entry long strategy) with an allowed stop of -5$ (1 point loss)
is referring to the next flips (in the recovery strategy) as it was -10$ stop loss (1 point loss * 2 contracts).
it may be seen again when the profit target of 15$ is finally achieved (3 points gain)
in the closed position with 28.12$ gain instead. ( 3 points gain * 2 contracts - 1.88 commission).
that means that from the second step of the recovery strategy the first original entry strategy is forgotten...

this happens even after changing orders from "this bar at close" to "next bar at market"
of the same recovery strategy code here -

Code: Select all

[IntrabarOrderGeneration = True] if marketposition = 1 and openpositionprofit < -5 then sellshort ("recovery 1" ) 2 contracts next bar at market; if marketposition = -1 and openpositionprofit < -5 then buy ("recovery 2") 2 contracts next bar at market; setprofittarget(15);
IB relevant trades table here
recovery.png
.

is this the right explanation for these "big slippages"?

moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

Re: inaccurate entries/exits

Postby moreno » 02 Jul 2020

IB relevant trades table here -
recovery.png
(157.23 KiB) Not downloaded yet

moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

Re: inaccurate entries/exits  [SOLVED]

Postby moreno » 06 Jul 2020

just to close this session I found after recommendation above:
1. defining a stop level (price) makes more accurate trades then calculating openpositionprofit function. (in my case)
2. "next bar at market" order is the way to trade candles on-line, "this bar at close" for backtests.
3. "IntrabarOrderGeneration = True" to refine entries/exits

thanks: TJ, JoshM, Mydesign


Return to “MultiCharts”