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;