Invalid request when submit stop order
Invalid request when submit stop order
31 Aug 2018, 04:11
Hi There,
I recieved these error message while submitting stop order. May you have a hint to fix the error?
Regards,
Noppanon
Replies
PanagiotisCharalampous
31 Aug 2018, 10:49
Ηi noppanon,
I cannot provide a definite answer for this, since I do not have enough information. but usually these issues occur when the price for the order is not valid e.g. within the spread.
Best Regards,
Panagiotis
@PanagiotisCharalampous
noppanon
31 Aug 2018, 15:51
Hi,
Now I can reproduce the problem. It relates to symbol and take profit or stop loss has decimal points with conditions.
According to the code below,
This code works with EURUSD, GBPUSD, XAUAUD. on both backtest and live, no matter take profit / stop loss has decimal point
This code works with XAUUSD, XAUEUR. on backtest no matter take profit / stop loss has decimal point .
This code does NOT work on live if symbol is XAUUSD, XAUEUR and take profit / stop loss has decimal points.
I didn't test all symbols. Just pick the symbol I trade.
Regards,
Noppanon
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class DecimalTP : Robot { [Parameter("Take Profit", DefaultValue = 0.0)] public double TakeProfit { get; set; } [Parameter("Stop Loss", DefaultValue = 0.0)] public double StopLoss { get; set; } protected override void OnStart() { TradeResult r; double p = 5.0 * Symbol.PipSize; r = PlaceStopOrder(TradeType.Sell, Symbol, 1000, Symbol.Bid - p, "test", StopLoss, TakeProfit); if (r.IsSuccessful) { Print("Successfully submit {0} order target price {1} SL {2} TP {3}", r.PendingOrder.TradeType, r.PendingOrder.TargetPrice, r.PendingOrder.StopLossPips, r.PendingOrder.TakeProfitPips); } else { Print("Fail to submit {0} order target price {1} SL {2} TP {3}", r.PendingOrder.TradeType, r.PendingOrder.TargetPrice, r.PendingOrder.StopLossPips, r.PendingOrder.TakeProfitPips); } } } }
@noppanon
PanagiotisCharalampous
31 Aug 2018, 16:28
Hi Noppanon,
If your SL and TP have decimal places please make sure to round them to the Symbol's digits. See below
TakeProfit = Math.Round(TakeProfit, Symbol.Digits);
It is a known issue that non rounded values might be the cause of such messages and we will fix it in a future release.
Best Regards,
Panagiotis
@PanagiotisCharalampous
noppanon
01 Sep 2018, 19:30
Hi Panagiotis,
It may not work to round take profit to symbol digits because
1. Symbol.Digits of XAUUSD is "2", so round to 2 decimal point, it will fail
2. On PlaceStopOrder, it takes stop loss and take profit as number of pips, not a price. While ModifyPosition takes stop loss and take profit as price.
Regards,
Noppanon
@noppanon
PanagiotisCharalampous
03 Sep 2018, 11:34
Hi noppanon,
When placing the stop order and setting SL and TP in pips, try rounding to one decimal place.
Best Regards,
Panagiotis
@PanagiotisCharalampous
noppanon
05 Sep 2018, 11:44
Hi Panagiotis,
Thanks for your suggestion. I think I should restate my problem.
I found cTrader has inconsitancy behavior which relates to symbol, backtest vs. live and number of decimal points in stop loss & take profit when submitting PlaceStopOrder
1. Bot will return "Invalid Request" if and only if symbol is XAUUSD, XAUEUR and take profit / stop loss has decimal points on live trade. The workaround is making sure take profit / stop loss has ZERO decimal point.
2. Bot will work fine if and only if symbol is XAUUSD, XAUEUR and take profit / stop loss has decimal points (no matter how many decimal) on back testing.
3. Bot will work fine if and only if symbol is EURUSD, GBPUSD, XAUAUD. on both backtest and live, no matter take profit / stop loss has decimal point.
So is it the known problem and pending to fix in the future?
Regards,
Noppanon
@noppanon
noppanon
31 Aug 2018, 04:22 ( Updated at: 21 Dec 2023, 09:20 )
Hi There,
In a few minute later, same Bot, same code section, it could submit another open stop order. Bot was not restarted to submit another order.
Regards,
Noppanon
@noppanon