Page 1 of 1

Same Exit-Rule .... Different Action .... Why ?

Posted: 11 Mar 2011
by piranhaxp
Hi,

I'm testing a mechanical system on live data but not connected to a broker.

Sometimes I'm experiencing some different action on the same exit rules on the short & long-side, but with totally different action. Please take a look on the attached screenshot.

Please 1st let me explain how I try to exit to a position on each side (short/long) via code ...

Code: Select all


:
input: lx1(2); // difference for 1st long exit of the entry price
input: lx2(5); // difference for 2nd long exit of the entry price
input: sx1(2); // difference for 1st short exit of the entry price
input: sx2(5); // difference for 2nd short exit of the entry price
:
:
:
var: mp(0); // marketposition
var: ep(0); // entry price for long/short
var: lxd1(0); // transformer to change input in a var
var: lxd2(0); // transformer to change input in a var
var: sxd1(0); // transformer to change input in a var
var: sxd2(0); // transformer to change input in a var
var: lxp1(0); // calculated price for the 1st long exit
var: lxp2(0); // calculated price for the 2nd long exit
var: sxp1(0); // calculated price for the 1st short exit
var: sxp2(0); // calculated price for the 2nd short exit
var: pi(0); // price inc
:
:
:
// ................................................................................................................
// Definition of the position and price of last entry
// ................................................................................................................
mp = marketposition;
pi = minmove/pricescale;
ep = entryprice;
lxd1 = (pi*lx1);
lxd2 = (pi*lx2);
sxd1 = (pi*sx1);
sxd2 = (pi*sx2);
:
:
:
// ................................................................................................................
// Calculations for the exiting the position
// ................................................................................................................
// ... with no position set everything to zero ... because price/order comparison of
// ... the execution plattform

if mp=0 then begin
ep = 0;
lxp1 = 0;
lxp2 = 0;
sxp1 = 0;
sxp2 = 0;
end;

// ... exit rule for long position -------------------------------------------------------------

if mp = (1) then begin
lxp1 = (ep+(1*lxd1)); // define 1st long exit
lxp2 = (ep+(1*lxd2)); // define 2nd long exit
end;

if mp = (1) then begin
sell x contracts next bar at lxp1 limit;
sell x contracts next bar at lxp2 limit;
end;

// ... exit rule for short position -------------------------------------------------------------

if mp = (-1) then begin
sxp1 = (ep+((-1)*sxd1))); // define 1st short exit
sxp2 = (ep+((-1)*sxd2))); // define 2nd short exit
end;

if mp = (-1) then begin
buytocover x contracts next bar at sxp1 limit;
buytocover x contracts next bar at sxp2 limit;
end;

:
:
:
For my understanding upper explained rules are the same code wise.

But as you can see in the attached screenshot, in the left yellow circle a short position was covered as both exit limits were reached in one bar. In the two circles on the right hand, both long position exit limits were executed in different bars, but should have been executed in one bar as well. Why there is a difference like this. I tried ti fix this problem for 4 days now with different code statements for both exits, but I'm unable to fix this.

Would be nice to be shared with some more insider information or ideas how to fix it.

Thanks a lot. I appreciate your help.

Regards.

Mike