Page 1 of 1

Stop loss and Profit target disappearing

Posted: Oct 17 2011
by Jesh
I have a strategy which places an order using the code below. When the code executes the stop loss and profit target are placed on IB, but after 1 to 2 minutes they disappear but the position stays open.

Is there something that I'm doing wrong?

Code: Select all

if MarketPosition = 0 then begin
print ("MarketPosition = 0");
print (OrderText);

if OrderText = "SELL" then begin
print ("SELL LIMIT SHORT");

SellShort ("Sell1") 1 Contracts Next Bar At (OrderEntryPrice) Limit;
SetProfitTarget(500);
Setbreakeven(60);
SetStopLoss(100);

print ("SELL LIMIT SHORT EXECUTED");


end;

if OrderText = "BUY" then begin
print ("BUY LIMIT LONG");

Buy("Buy1") 1 Contracts Next Bar At (OrderEntryPrice) Limit;
SetProfitTarget(500);
Setbreakeven(60);
SetStopLoss(100);
print ("BUY LIMIT LONG EXECUTED");

end;

end;

Re: Stop loss and Profit target disappearing

Posted: Oct 17 2011
by SP
You have packed the whole code into the "if MarketPosition = 0 then begin...end" loop. You need to tell the strategy what should happen next bar if you have a position, ie put the targets and stopps outside the loop.

Re: Stop loss and Profit target disappearing

Posted: Oct 17 2011
by TJ
I have a strategy which places an order using the code below. When the code executes the stop loss and profit target are placed on IB, but after 1 to 2 minutes they disappear but the position stays open.

Is there something that I'm doing wrong?

Code: Select all

if MarketPosition = 0 then begin
print ("MarketPosition = 0");
print (OrderText);

if OrderText = "SELL" then begin
print ("SELL LIMIT SHORT");

SellShort ("Sell1") 1 Contracts Next Bar At (OrderEntryPrice) Limit;
SetProfitTarget(500);
Setbreakeven(60);
SetStopLoss(100);

print ("SELL LIMIT SHORT EXECUTED");


end;

if OrderText = "BUY" then begin
print ("BUY LIMIT LONG");

Buy("Buy1") 1 Contracts Next Bar At (OrderEntryPrice) Limit;
SetProfitTarget(500);
Setbreakeven(60);
SetStopLoss(100);
print ("BUY LIMIT LONG EXECUTED");

end;

end;
see post #3
viewtopic.php?f=16&t=6929

Re: Stop loss and Profit target disappearing

Posted: Oct 18 2011
by Jesh
Thanks, SP & TJ. Moving the code out of the if statement worked.