using the following test code I am trying to have a stop issued as soon as the order is filled. The stop is not issued until the bar is closed. Please advise.
Code: Select all
var:mp(0),dntarg(0),uptarg(0);
var:opencontracts(0);
if time>=630+barinterval and barstatus(1)=2 then begin
uptarg=h+.25;
dntarg=l-.25;
end;
[IntrabarOrderGeneration=true]
mp=marketposition;
opencontracts=(GetPositionQuantity( getsymbolname,getaccountid)) ;
if time>=630+barinterval
then begin
if mp <> -1
then begin
sellshort ("Sht") the next bar at uptarg limit;
end;
if mp <> 1
then begin
buy ("Lng") the next bar at dntarg limit;
end;
if mp=1 then Sell ("stoplong") from entry ("Lng") next bar entryprice-(1) stop;
if mp=-1 then Buy to cover ("stopshort") from entry ("Sht") next bar entryprice+(1) stop;
end;
[IntrabarOrderGeneration=false]
setexitonclose;