Limit Order Failing for TradeType.Sell but not TradeType.Buy "INVALID_REQUEST" Works fine in Backtest but not Live
Limit Order Failing for TradeType.Sell but not TradeType.Buy "INVALID_REQUEST" Works fine in Backtest but not Live
31 Mar 2015, 10:17
I have been using limit orders for TradeType.Buy successfully for quite some time but am struggling with the .Sell due to a "INVALID_REQUEST" message as shown below. The same code runs fine in a backtest but fails when running live in a virtual account. From the cAlgo journal it looks like it sent the order to the server with the right set of parameters or at least about what I would have expected.
Snippet of Code
var orderResult = PlaceLimitOrder(TradeType.Sell, Symbol, orderVolume, targetLimitPrice, StratLabel, stopPips, profitPips, expireTime, cmt);
Can anybody see what I am doing wrong?
Error from CAlgo Journal
31/03/2015 06:24:00.857 | Limit order to Sell 0.03 Lot(s) EURUSD (Price: 1.07831, SL: 1.08081, TP: 1.07461, ExpireDate: 31/03/2015 06:24) is sent to server
31/03/2015 06:24:01.029 | ? Limit order to Sell 0.03 Lot(s) EURUSD (Price: 1.07831, SL: 1.08081, TP: 1.07461, ExpireDate: 31/03/2015 06:24) is REJECTED with error "INVALID_REQUEST"
Values from my External Log File
L513: 2015-03-31 06:24:00.826: Bid=1.07831 Ask=1.07838 targetLimitPrice=1.07831 stopPips=24.80113 profitPips=37.20170 Account.FreeMargin=984.62 Account.Equity=984.62 PipSize=0.0001 Symbol.PipValue=0.0001
Replies
joeatbayes
31 Mar 2015, 23:45
RE: Modified for null stop limit and null take profit and same order worked.
March-31 13:37
I modified the code to set the stopPips and ProfitPips to null and the order executed as expected but since the stop limit and target price are null the order to add missing stop limits had to kick in to modify the position to add them. There is some extra latency when used this way that leaves the position exposed to greater risk than desired. Next I will modify to try just setting the profitPips and see if it still works.
I modified the code From (FAILS):
var orderResult = PlaceLimitOrder(TradeType.Sell, Symbol, orderVolume, targetLimitPrice, StratLabel, stopPips, profitPips, expireTime, cmt);
TO: (WORKS)
var orderResult = PlaceLimitOrder(TradeType.Sell, Symbol, orderVolume, targetLimitPrice, StratLabel, null, null, expireTime, null);
From The Journal
31/03/2015 20:26:08.276 | Limit order to Sell 0.03 Lot(s) EURUSD (Price: 1.07478, ExpireDate: 31/03/2015 20:26) is sent to server
31/03/2015 20:26:08.495 | → Limit order OID5366660 to Sell 0.03 Lot(s) EURUSD (Price: 1.07478, ExpireDate: 31/03/2015 20:26) is ACCEPTED (31/03/2015 20:26:08.357 UTC+0)
31/03/2015 20:26:08.792 | → Limit order to SELL 0.03 Lot(s) EURUSD OID5366660 is FILLED at 1.07478, position PID3227196 (31/03/2015 20:26:08.645 UTC+0)
31/03/2015 20:26:08.839 | Request to amend position PID3227196 (SL: 1.07725, TP: 1.07231) is sent to server
31/03/2015 20:26:09.042 | → Request to amend position PID3227196 (SL: 1.07725, TP: 1.07231) is ACCEPTED
@joeatbayes
joeatbayes
03 Apr 2015, 02:27
Final work around / resolution
Taking the standard debugging approach of removing complexity until it worked and then adding things back in until it stopped I found that the failure point occurred when I added the comment string parameter. It worked fine with the stopPips and takeProfitPips which I previously thought was causing the issue. I have not tried to figure out exactly what it was about my comment string the server had a problem with and there is no documentation I can find about the limits of what can be put in a comment string. This documentation would be very helpful.
@joeatbayes
Spotware
06 Apr 2015, 12:20
Unfortunately we cannot reproduce this issue. Please specify the exact parameters that you pass to PlaceLimitOrder command.
The following code successfully places the order:
PlaceLimitOrder(TradeType.Sell, Symbol, Symbol.VolumeMin, Symbol.Bid + 20 * Symbol.PipSize, "some label", 10, 10, Time.AddHours(5), "some comment");
@Spotware
joeatbayes
06 Apr 2015, 19:37
exact call as requested
PlaceLimitOrder(TradeType.Sell, Symbol, Symbol.VolumeMin, 1.07478, "EMACrosX1", 24 37, Time.AddMinutes(0.25), "Bid=1.07406 Ask=1.07413 targetLimitPrice=1.07406 stopPips=24.00000 profitPips=37.00000 LimitPriceEMA=1.07406 VeryShortEMA=1.07417 ShortEMA=1.07423275951391 LongEMA=1.07425 stopLimitPriceAdj=0.002470338 atRiskPerShare=0.00254444814 MaxCapitalAtRiskForSingleTrade=9.8989 maxShares=3890.39172950092 totalMaxRisk=7.63334442 orderVolume=3000 stopPips=24 profitPips=37 Account.FreeMargin=989.89 Account.Equity=989.89 PipSize=0.0001 Symbol.PipValue=0.0001 workingLongStopLimitPort=0.0023");
@joeatbayes
joeatbayes
31 Mar 2015, 22:40
RE:
joeatbayes said:
March-31 - Trade result is showing "Error: TechnicalError"
I modified the SL and take profit to require a Minimum of 1 Pip in the PlaceLimitOrderCall. Also converted them to Integer values since that was shown in the examples. I am now printing out the TradeResult and get the following Error:
L527: 2015-03-31 18:54:07.628: OrderResult=TradeResult (Error: TechnicalError)
Request: When the server rejects and order it would be nice to print out all the Order parameters the server thinks it rejected and would be even better if we got an indication of which parameters the server finds unsuitable.
For the same Trade the Journal is still showing:
31/03/2015 18:54:07.456 | Limit order to Sell 0.03 Lot(s) EURUSD (Price: 1.07406, SL: 1.07646, TP: 1.07036, ExpireDate: 31/03/2015 18:54) is sent to server
31/03/2015 18:54:07.628 | → Limit order to Sell 0.03 Lot(s) EURUSD (Price: 1.07406, SL: 1.07646, TP: 1.07036, ExpireDate: 31/03/2015 18:54) is REJECTED with error "INVALID_REQUEST"
The extract from my Text log file with parameters we are sending in the API call.
L513: 2015-03-31 18:54:07.456: CheckOpenShort: OPEN SELL cmt=Bid=1.07406 Ask=1.07413
targetLimitPrice=1.07406 stopPips=24.00000 profitPips=37.00000 LimitPriceEMA=1.07406
VeryShortEMA=1.07417 ShortEMA=1.07423275951391 LongEMA=1.07425 stopLimitPriceAdj=0.002470338
atRiskPerShare=0.00254444814 MaxCapitalAtRiskForSingleTrade=9.8989 maxShares=3890.39172950092
totalMaxRisk=7.63334442 orderVolume=3000 stopPips=24 profitPips=37 Account.FreeMargin=989.89
Account.Equity=989.89 PipSize=0.0001 Symbol.PipValue=0.0001 workingLongStopLimitPort=0.0023
Advice on diagnosing this would be greatly appreciated.
@joeatbayes