Bracket Orders returning Error 19. COM method/function call failed

Hi everyone,

I'm sure there's something obvious I'm missing but I can't seem to figure out what the problem is. I want my code to automatically place bracket orders when there is a buy or short signal. I am looking for an initial market order to be placed and then a limit order to sell at a profit of 5% or a stp loss order to sell at a loss of 3%. Since the take profit and loss are percentages rather than at a specific number value every time (they're determined by whatever the market price is). I used the code from Tomasz's ibController and altered it slightly. However when I have a variable in place for my limit price it is returning an error 19 message. Any ideas on how to fix this error would be appreciated. I've tested it by subing in hard data rather than variables and the only issue in the code is the LongProfit and LongLoss variables.

Thank you to anyone that can help!
Owen

LongProfit = close * 1.05 ;
LongLoss = close * 0.97 ;
PositSize = StrToNum(""+(floor ( cash / EntryPrice ) ));

parentID = ibc.PlaceOrder(Symbol, "BUY", PositSize, "MKT", True, 0, "GTC", False); 
ibc.PlaceOrder(Symbol, "SELL", PositSize, "LMT", LongProfit, 0, "GTC", False, "100", "outsideRTH", parentID) ;  
ibc.PlaceOrder(Symbol, "SELL", PositSize, "STP", LongLoss, LongLoss, "GTC", True, "100", "outsideRTH", parentID) ;

LongProfit and LongLoss are arrays. You need to send just one value of the array. Use LastValue() to do this.

1 Like

Thank you Peter, I'm embarassed I didn't put that together! This has fixed my problem.

Owen

1 Like