Order OID0 is REJECTED with error "Relative stop loss has invalid precision"

Created at 10 Apr 2019, 08:29
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
FI

firemyst

Joined 26.03.2019

Order OID0 is REJECTED with error "Relative stop loss has invalid precision"
10 Apr 2019, 08:29


I was running a bot today (and yesterday) in an IC Markets demo account that has been trying to purchase AUDJPY through cTrader.

 

I keep receiving the error message:

10/04/2019 10:00:02.217 | → Order OID0 is REJECTED with error "Relative stop loss has invalid precision"

 

The order I tried placing is as follows according to the cTrader log tab with the output my bot writes:

10/04/2019 10:00:02.233 | Execute Market Order NOT successful! H1 AUDJPY; Short Buy; 1,002; TSL in Pips:26.23000; Approx Time:20190410 10:03:15

string commentString = _positionLabel + "; Short Buy; " + String.Format("{0:#,###}", PositionSize) + "; TSL in Pips:" + String.Format("{0:#,###.00000}", _stopLossInPips) + "; Approx Time:" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss");

TradeResult result = ExecuteMarketOrder(TradeType.Buy, Symbol, PositionSize, _positionLabel, _stopLossInPips, null, null, commentString, true);

 

It's trying to short 1002 units. The Trailing Stop loss (TSL) goes to 2 decimal places: 26.23.

 

Why is that stop loss being marked as "invalid precision" as the YEN goes to 2 decimal places when trading FOREX?

Thank you.

 


@firemyst
Replies

PanagiotisCharalampous
10 Apr 2019, 18:28

Hi FireMyst,

Try to round the TSL to one decimal place.

Best Regards,

Panagiotis


@PanagiotisCharalampous

firemyst
11 Apr 2019, 03:05

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Try to round the TSL to one decimal place.

Best Regards,

Panagiotis

Thank you. I will try it today and let you know.

I have a question though -- it works perfectly while backtesting. No orders rejected. Why would that be the case? 

That seems like a big flaw and major functional inconsistency if we can submit orders with stop losses in pips with 2-4 decimal places while backtesting in a demo account, but they're rejected by the same broker when not backtesting in the same demo account.


@firemyst

firemyst
12 Apr 2019, 13:26

RE:

Panagiotis Charalampous said:

Hi FireMyst,

Try to round the TSL to one decimal place.

Best Regards,

Panagiotis

Rounding the Stop Loss to 1 decimal point worked.

It still doesn't answer the question though -- why does it work in backtesting?

If such functionality isn't going to work in a "live" account, it shouldn't work while backtesting in a demo account.

Is this a cTrader bug or known issue?

 


@firemyst

PanagiotisCharalampous
14 Apr 2019, 13:12

Hi FireMyst,

Backtesting is a simulation of the trading on your machine. It does not communicate with the server and it does not account for all possible parameretes of a cBot's runtime. The specific error is sent by the server where the checks are a bit more strict. I would advise you to test your cBots on a demo account as well before moving to a live trading account.

Best Regards,

Panagiotis 


@PanagiotisCharalampous

thomas.abele
01 Jan 2020, 12:08

RE: precision if stopLoss or takeProfit is specified in pips

PanagiotisCharalampous said:

Hi FireMyst,

Backtesting is a simulation of the trading on your machine. It does not communicate with the server and it does not account for all possible parameretes of a cBot's runtime. The specific error is sent by the server where the checks are a bit more strict. I would advise you to test your cBots on a demo account as well before moving to a live trading account.

Best Regards,

Panagiotis 

Hi Panagiotis,

I saw for most Symbols the precision for stopLoss or takeProfit specified in pips is 1 digit. But for e.g. XAUUSD it is 0 digits.

Is there a way to find out programatically what the precision is?

Kind Regards,

Thomas


@thomas.abele

firemyst
02 Jan 2020, 05:22

RE: RE: precision if stopLoss or takeProfit is specified in pips

thomas.abele said:

PanagiotisCharalampous said:

Hi FireMyst,

Backtesting is a simulation of the trading on your machine. It does not communicate with the server and it does not account for all possible parameretes of a cBot's runtime. The specific error is sent by the server where the checks are a bit more strict. I would advise you to test your cBots on a demo account as well before moving to a live trading account.

Best Regards,

Panagiotis 

Hi Panagiotis,

I saw for most Symbols the precision for stopLoss or takeProfit specified in pips is 1 digit. But for e.g. XAUUSD it is 0 digits.

Is there a way to find out programatically what the precision is?

Kind Regards,

Thomas

 

@Thomas:

Is Symbol.Digits what you're looking for? https://ctrader.com/api/reference/internals/symbol


@firemyst

MegaCynic
02 Mar 2022, 14:15

RE: RE: RE: precision if stopLoss or takeProfit is specified in pips

firemyst said:

Is Symbol.Digits what you're looking for? https://ctrader.com/api/reference/internals/symbol

I'm running into the same problem right now and I don't see any value that would tell me at what precision to round the StopLoss/TakeProfit values.
 Symbol.TickSize is 1/ 10^Symbol.Digits for all symbols I've checked, which is at least one off for most, but sometimes even more. The UI seems to have the information somewhere, as for a manual trade you can't enter more precision than allowed. I'd love to know what it uses.

Thanks, Rolf.


@MegaCynic

amusleh
03 Mar 2022, 08:26

Hi,

Try this:

using System;
using cAlgo.API;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 10.5678)]
        public double Pips { get; set; }

        protected override void OnStart()
        {
            Print(NormalizePips(Pips));
        }

        private double NormalizePips(double pips)
        {
            var currentPrice = Convert.ToDecimal(Symbol.Bid);

            var pipSize = Convert.ToDecimal(Symbol.PipSize);

            var pipsDecimal = Convert.ToDecimal(pips);

            var pipsAddedToCurrentPrice = Math.Round((pipsDecimal * pipSize) + currentPrice, Symbol.Digits);

            var tickSize = Convert.ToDecimal(Symbol.TickSize);

            var result = (pipsAddedToCurrentPrice - currentPrice) * (tickSize / pipSize * Convert.ToDecimal(Math.Pow(10, Symbol.Digits)));

            return decimal.ToDouble(result);
        }
    }
}

It can normalize any Pips number to something that you can use as a stop loss or take profit.

It should work for all symbols.


@amusleh

MegaCynic
04 Mar 2022, 23:17

RE: Pip rounding

Thank you @amusleh for that code snippet. I've missed taking pipSize into account.

Do you know of any case where Symbol.TickSize is not 1/Math.Pow(10, Symbol.Digits)? The Remarks for the TickSize description makes me think it always is (which would allow us to simplify the result calculation).

 


@MegaCynic