Stop loss and Profit target disappearing

Questions about MultiCharts and user contributed studies.
Jesh
Posts: 41
Joined: 04 Jan 2011
Has thanked: 12 times
Been thanked: 4 times

Stop loss and Profit target disappearing

Postby Jesh » 17 Oct 2011

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;

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: Stop loss and Profit target disappearing

Postby SP » 17 Oct 2011

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.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Stop loss and Profit target disappearing

Postby TJ » 17 Oct 2011

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

Jesh
Posts: 41
Joined: 04 Jan 2011
Has thanked: 12 times
Been thanked: 4 times

Re: Stop loss and Profit target disappearing

Postby Jesh » 18 Oct 2011

Thanks, SP & TJ. Moving the code out of the if statement worked.


Return to “MultiCharts”