Accurate avgentryprice in positiontracker  [SOLVED]

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Accurate avgentryprice in positiontracker

Postby evdl » 21 Sep 2012

I'am using the autotrader and the broker to strategy sync signal.

I know one of the existing issues with the sync strategy is an inaccurately sync of order's prices.

So the avgentryprice in the positiontracker is always a bit of. Sometimes more than other times.

This avgentryprice is used for calculation of profit targets and stoplosses and positionprofit. Now a couple of months later and some MC versions later with new reserved words.

Is it possible to get the avgentryprice exactly the same as the values that are in TWS IB? (IB prices are including commision cost)

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

Re: Accurate avgentryprice in positiontracker

Postby Henry MultiСharts » 21 Sep 2012

Hello Evdl,

Please attach full-sized screenshots demonstrating this behavior:
1) MultiCharts Order and Position Tracker Open positions and Strategy positions tabs
2) IB TWS demonstrating Average Entry Price for the same instrument

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Accurate avgentryprice in positiontracker

Postby evdl » 24 Sep 2012

Hi Henry,

I use the sync to broker signal in my strategy:

Code: Select all

// Sync open broker positie met Multicharts, alleen als the position nog niet gematched is.
// en er realtime data en de autotrader AAN is.

If (GetAppInfo(aiRealTimeCalc)= 1)and (GetappInfo(aiStrategyAuto)=1) then begin;
Sync_status = false;
Mp = marketposition * currentContracts; {multicharts positie}
BrokerPosition = MarketPosition_At_Broker; {broker positie}

// Multicharts positie en broker positie verschillen status

If mp <> brokerposition then begin
Sync_status = true;
_get_tick_count = GetTickCount ;

// Status verschil in posities
If not mp_diff and not mp_corrected then begin
mp_diff = true;
mp_diff_time_start = _get_tick_count;
end;

// Beginnen met vaststellen van de verschillen
If mp_diff and not mp_corrected then begin
_exit_price = close; // uitgangspunt is dat de positie mag sluiten op laatste koers
if _get_tick_count - mp_diff_time_start > TimeOutMS then begin
place_correction_marketorder = true ;
mp_corrected = true ;
mp_corrected_time_start = _get_tick_count ;
end;
end;

// Herstarten van de monitoring van de marktpositie
if mp_corrected then begin
if (_get_tick_count - mp_corrected_time_start) > LatencyMS then begin
mp_corrected_time_start = _get_tick_count ;
mp_diff = false;
mp_corrected = false;
end;
end;

// Plaatsen van correctie order
if place_correction_marketorder then begin
place_correction_marketorder = false ;
//if 0 <> Brokerposition then _exit_price = round2fraction(AvgEntryPrice_at_Broker);
if 0 <> Brokerposition then _exit_price = AvgEntryPrice_at_Broker;
ChangeMarketPosition(brokerposition - mp, _exit_price, "Sync Order");
end;
end
else begin
mp_corrected = false;
mp_diff = false;
end;
end;
The avgentryprice in MC is always a bit different. Today it seems all the entryprices are rounded, but that is not always the case. So I suspect it has something to do with minimum price movement and the actual sell or buy price. It is not a big problem, but I would like to have the exact figures for positionprofit and targets.
Attachments
Avgentryprice MC strategy positions.png
Avgentryprice MC strategy positions
(131.18 KiB) Downloaded 531 times
Avgentryprice MC open positions.png
Avgentryprice MC open positions
(128.28 KiB) Downloaded 525 times
Avgentryprice TWS.png
Avgentryprice TWS
(118.98 KiB) Downloaded 529 times

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Accurate avgentryprice in positiontracker

Postby evdl » 26 Sep 2012

Hi Henry,

Today I noticed that when the autotrader is opening a position and the standard sync signal is syncing the avgentryprice. Then the difference is the greatest.

Please look at the attachments with symbol dcx. It is almost 1 cent difference. With for example 5000 stocks this is 50 euro slippage. And with about 250 trades a year it will add up. When I put autotrade off and on again. The difference is less.

Can I use other reserved words to get the exact avgentryprice?
Attachments
Avgentryprice MC open positions (2).png
(140.53 KiB) Downloaded 522 times
Avgentryprice MC strategy positions (2).png
(129.35 KiB) Downloaded 522 times
Avgentryprice TWS (2).png
(154.77 KiB) Downloaded 513 times

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

Re: Accurate avgentryprice in positiontracker

Postby Henry MultiСharts » 26 Sep 2012

evdl, the average entry price is rounded to the minimum price increment of the instrument (price scale*min move).
For example if ASML was added from the data source then with default settings the minimum price increment is = price scale*min move=1/100 * 1=0.01.

That is why IB average entry price of 40.8382 was rounded to MC price 40.84 (with min increment of 0.01).

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Accurate avgentryprice in positiontracker

Postby evdl » 26 Sep 2012

Thanks Henry for your reply.

If I understand correctly, the avgentryprice with syncing is using the min price movement in quotemanager. So if I remove the min price movement and set this to the smallest value I need (zero if possible) , the syncing will get the same avgentryprice as in TWS.

I then also need to adjust the code for the entry and exit conditions in my strategy with the minimal pricemovement of the symbol (which originaly was in quotemanager), or otherwise the orders will be rejected by TWS.

I will give it a try.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Accurate avgentryprice in positiontracker  [SOLVED]

Postby evdl » 27 Sep 2012

I changed the min movement in quotemanager to the minimum of 1. Now the avgentryprice is exactly the same as in TWS.

Then you need to adjust the entry and exit code (because the min movement will cause errors when sending to TWS).

I found a function at http://www.traderslaboratory.com/forums ... brary.html to round to the nearest min movement, you used before with the old settings in quotemanager. (Thank you to the person who made this, and I hope it is ok to link to it ;))

For example I used this for a profit target:

Code: Select all

Profit_Fixed_Long = RoundTofraction(AvgEntryprice + Profit_Fixed);
The roundtofraction function was using the settings in quotemanager that is not applicable anymore.

Now I use the function JK_Math_RoundToNearest, I found (see link and import this as a new function) and change your code in the strategy:

For example the adjustment of one of the exit code I have:

Code: Select all

Var:
Pricescale_symbolname(1/1000),
MinMove_symbolname(5),
TickSize_symbolname(Pricescale_symbolname * MinMove_symbolname);

Profit_Fixed_Long = JK_Math_RoundToNearest(AvgEntryprice + Profit_Fixed, ticksize_symbolname);
This will round the exit price to the nearest min movement of the symbol. Advantage is that the difference that exist with the autotrader syncing the avgentryprice is gone. Disadvantage is you can not use manual chart trading because it can reject the order due to the min movement settings in quotemanager. So this is only usefull with autotrade strategies.


Return to “MultiCharts”