same position exit twice in intrabar mode?

Questions about MultiCharts and user contributed studies.
yoyo2000
Posts: 26
Joined: 07 Nov 2012

same position exit twice in intrabar mode?

Postby yoyo2000 » 03 Dec 2012

Hi,I met a wired problem when pyramid-out position,but i have no idea about why it happen?

my purpose :
pyramiding-out position in two steps,that's:
1) exit 30% of a position;
2) then exit all the rest of the position.
for example,if a position's size is 80,the exits sequency would be exiting 24 of 80 contracts,then exiting 56 of 80 contracts.

the results:
1) When PyramidMode = 0 or 1 or 2,everything is ok,whether IOG is enable or not;
2) When PyramidMode = 3, intra-bar order regeneration(IOG) is disable,everything is ok;
3) When PyramidMode = 3, IOG = enable, it exits 30% of the position twice,why?from the snapshot in attachment,only first signal in bar could send the order.

the codes are below

Code: Select all

inputs: PyramidMode(0), //which mode to pyramid: 0 - no pyramid in and out, 1 - pyramid in, 2 - pyramid out, 3 - pyramid in and out
PyramidOutPct(0.3); //first pyramid out's percent

var: mp(0), basesize(74), PMode(0), modtest(0), pyramidsize(0), PyramidOutSize(0), totalSize(0);


if LastBarOnChart then begin
mp = marketposition;
modtest = mod(barnumber, 10);
pyramidsize = IntPortion( BaseSize/2 );

if time > 0900 and time < 1459 then begin // in trading time
//if mp > 0 then begin
if (PyramidMode=1 or PyramidMode=3) and modtest=3 then begin
buy ("LEP 1") pyramidsize contracts next bar at market;
totalSize = totalSize + pyramidsize;
end;

if (PyramidMode=2 or PyramidMode=3) and modtest=5 then begin
PyramidOutSize = IntPortion( totalsize*PyramidOutPct );
sell ("LXP 1") PyramidOutSize contracts total next bar at market;
totalSize = totalSize - PyramidOutSize;
end;

if modtest=7 then begin
sell ("LXP 1-2") next bar at market;
totalSize = 0;
end;
//end
//else if mp = 0 then begin
if modtest=1 then begin //spread in's condition trigged
buy ("LE 1") BaseSize contracts next bar at market;
totalSize = BaseSize;
end;
//end;
end
else if time >= 1459 then begin
sell ("EOD LX 1") next bar at market;
buytocover ("EOD SX 1") next bar at market;
end;
end;
Attachments
snapshot.JPG
(39.39 KiB) Downloaded 678 times
IOG.JPG
setting for IOG
(36.82 KiB) Downloaded 682 times

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

Re: same position exit twice in intrabar mode?

Postby Henry MultiСharts » 03 Dec 2012

Hello yoyo2000,

We will check this behavior. Please let me know what your chart resolution is.

yoyo2000
Posts: 26
Joined: 07 Nov 2012

Re: same position exit twice in intrabar mode?

Postby yoyo2000 » 03 Dec 2012

my snapshot's chart resolution is 30 seconds,but it exists on 3 seconds and 15 seconds charts,too.

PS: found new case
IOG = enable,
PyramidMode = 3,
chart data = history data playback,
everything is ok,

IOG = enable,
PyramidMode = 3,
chart data = realtime data,
same exit runs twice in the same position

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: same position exit twice in intrabar mode?

Postby SUPER » 04 Dec 2012

yoyo2000,

Can you change variables to "IntrabarPersist" and see if it makes any difference.
Attachments
mc_2000.jpg
(66.02 KiB) Downloaded 676 times
Last edited by SUPER on 04 Dec 2012, edited 1 time in total.

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

Re: same position exit twice in intrabar mode?

Postby Henry MultiСharts » 04 Dec 2012

Hello yoyo2000,
PS: found new case
IOG = enable,
PyramidMode = 3,
chart data = history data playback,
everything is ok,
It looks like you are using playback As Is mode. That is why the behavior of playback is different from realtime calculation. In order to have similar results you need to use tick by tick or second by second playback mode.
When PyramidMode = 3, IOG = enable, it exits 30% of the position twice,why?
In As Is playback mode there is one signal calculation. In tick by tick or second by second playback mode there are multiple signal calculations that is why the order is placed twice.

In order to have only two exits in PyramidMode = 3 in realtime and tick by tick or second by second playback please change your code to the following:

Code: Select all

if (PyramidMode=2 or PyramidMode=3) and modtest=5 then begin
PyramidOutSize = IntPortion( totalsize*PyramidOutPct );

if (PyramidMode<>3) or (currentshares>basesize+PyramidOutSize) then
sell ("LXP 1") PyramidOutSize contracts total next bar at market;

totalSize = totalSize - PyramidOutSize;
end;

yoyo2000
Posts: 26
Joined: 07 Nov 2012

Re: same position exit twice in intrabar mode?

Postby yoyo2000 » 05 Dec 2012

thanks,it works.

but here is another problem in IOG mode.

when spread trading backtesting,with IOG setting = enable,and the entry rules are:
1) if spread cross above -7.5 then buy 10 contracts
2) if spread cross under -14.5 then sellshort 10 contracts

each bar would be calculated four times,the results are:
barnumber: 9.00 spread: 7.21 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 9.00 spread: 9.54 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 9.00 spread: -4.44 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 9.00 spread: -2.11 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 10.00 spread: -3.64 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 10.00 spread: -1.31 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 10.00 spread: -15.30 totalsize: -10.00 SX: 0.50 LX: -22.50
barnumber: 10.00 spread: -10.63 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 11.00 spread: -9.37 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 11.00 spread: -9.37 totalsize: 0.00 SX: 0.50 LX: -22.50
barnumber: 11.00 spread: -4.70 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 11.00 spread: -4.70 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 12.00 spread: -5.10 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 12.00 spread: -7.43 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 12.00 spread: 6.55 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 12.00 spread: 1.89 totalsize: 10.00 SX: 0.50 LX: -22.50
barnumber: 13.00 spread: 3.09 totalsize: 10.00 SX: 0.50 LX: -22.50

the problem is,at the 10th bar,1 of 4 calculated results is lower than -14.5,and its previous result is higher than -14.5,so a short position is established,however,next result in the same bar is higher than -14.5,the position disappears.

the relating snapshot is in attachment.

when running the strategy in realtime mode,this trade would be trigged at the 10th bar brfore it finish and the trade arrow would be on the chart,but when the 10th bar finishs,the condition of sellshort wouldn't be fit.
how to avoid this problem?


best regards.
Attachments
snapshot3.JPG
(51.55 KiB) Downloaded 684 times

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

Re: same position exit twice in intrabar mode?

Postby Henry MultiСharts » 05 Dec 2012

Please send me the following information for further investigation ( support@multicharts.com ):
- workspace you are using
- in QuoteManager select the symbols you are using, make a right click on them->Export data->Export instrument. Send me the Qmd export file for analysis.
- in Power Language editor->File->Export->Export with dependent functions the studies you are using the workspaces you are providing. send me the study export file
- attach detailed problem description and highlight the problem on full-sized screenshots
- what version and build numbe of MultiCharts are you using (Help -> About MultiCharts) ?

yoyo2000
Posts: 26
Joined: 07 Nov 2012

Re: same position exit twice in intrabar mode?

Postby yoyo2000 » 06 Dec 2012

a detailed mail has been sent,please check.

thanks

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

Re: same position exit twice in intrabar mode?

Postby Henry MultiСharts » 19 Dec 2012

This case has been checked. Confirmed that MultiCharts is functioning properly.


Return to “MultiCharts”