Does Applystop send usable sell signal to IBController?

I am trying to use profit target stop and a trailing stop loss to exit positions as below via IB controller.

Sell = 0;
Applystop (stoptypeprofit, stopmodepercent, 3, 1, False, 0, 1, -1, 0);
Applystop (stoptypetrailing, stopmodepercent, 5, 1, False, 0, 1, -1, 0); 

 . . . 
If (LastValue (Sell) 
{
ibc.placeorder (Ticker, "Sell", ibc.getpositionsize (Ticker), "MKT", 0, 0, True ); 
}
 . . . 

When applystop is triggered, will a sell signal be sent to IBC? If not, is there a good workaround to use stops with IBC?

thanks in advance

1 Like

I would like to know too.

It has been written and told many times that ApplyStop is the switch for the BACKTESTER to appy the stop during backtesting. It is intended to simulate stops that are implemented at the brokerage level. Therefore it does not generate any "signals" to the outside world.

Now, in Interactive Brokers, like in ANY other brokerage there are STOP and LIMIT ORDERS that implement stops AUTOMATICALLY at the level of brokerage. So you don't really need to send any signal. They "just work" once appropriate bracket order is placed. Once they are placed they are active for as long as they are not cancelled and you don't even have to run AmiBroker. You can close AmiBroker. Interactive Brokers would execute those orders on their own when limit/stop is hit. More information about bracket orders is available from Interactive Brokers web site https://www.interactivebrokers.com/en/index.php?f=583 and from http://www.amibroker.com/at/

// create instance of trading interface
ibc = GetTradingInterface("IB");
if( ibc )
{
 parentID = ibc.PlaceOrder("MSFT", "BUY", 1000, "LMT", 27, 0, "GTC", False );
 ibc.PlaceOrder("MSFT", "SELL", 1000, "LMT", 28, 0, "GTC", False, 100, "", parentID );
 ibc.PlaceOrder("MSFT", "SELL", 1000, "STP", 26, 26, "GTC", True, 100, "", parentID );
}

Note that TRANSMIT flag is set to FALSE on all bracket orders except the last one. This ensures that orders wait until bracket order set is completed. Setting Transmit flag to TRUE on the very last one transmits entire bracket.

9 Likes