Reply

Ninjatrader Stop Order Rounding Problem

8 replies

xlhuang1995

Subscriber, bbp_participant, community, 11 replies.

Visit profile

8 years ago #114993

I was running SQ and found some nice candidates for EURUSD. So I exported those strategies to ninjatrader but when I backtested them in ninjatrader, they made no trades with only a few cancelled stop orders at 1.0000 for entry (see attached screenshot). Those strategies were all using stop entry order. 

 

In the code I found that SQ was using price = roundprice() for entry price. So I added Print(price) on the next line and it printed lines of 1 when I ran the backtest again.

 

Then I deleted roundprice() and left the price unrounded. Surprisingly, the prices were rounded correctly according to my ticksize (even without roundprice()).

 

Then I calculated roundprice() using my brain, according to SQMangedStrategy, which also went through  round() and  _round (), and I got the correct price. However, the strategy kept giving me 1.00000 when I ran backtest.

 

This totally makes no sence. I cannot figure out why it keeps giving me 1.00000 when the correct price should be something like 1.42365.

 

BTW, my ticksize was 0.00005. I was running on Interactive Brokers.

 

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

8 years ago #136454

Tried to duplicate your problem using 6E futures data (tick size 0.00005) and randomly generated strategy using Limit order only and the problems also occurs to me. No trades executed only orders having limit price of 1.0000. Mark will look at this what can be done.

0

xlhuang1995

Subscriber, bbp_participant, community, 11 replies.

Visit profile

8 years ago #136613

Yeah I think I got to the point. It is a bug in the SQManagedStrategy, a strategy imported to NT by SQ.

 

When NT is calculating how many decimals there are in the tick size, it is DESIGNED to splits the tick size at the decimal point. From my example, 0.00005 becomes 0 and 00005. It than takes the latter and count how many digits there are.

 

However, the tick size NT gets, and then splits, is in SCIENTIFIC NOTATION. So it can’t really split it at the decimal point because there is no decimal point in 5E10-5. And this causes the problem.

 

I have played with the code in SQManagedStrategy, and fixed this problem by myself. It was an easy fix, but I cannot understand how engineers from SQ could make such a stupid mistake. And how can people use SQ to generate forex strategies with small tick size to be used in NT? Or there is actually no one using SQ with NT?

0

mabi

Customer, bbp_participant, community, 261 replies.

Visit profile

7 years ago #136706

“StrategyQuant now fully supports NinjaTraderâ„¢ trading platform!”  ??

0

kazex

Customer, bbp_participant, community, 6 replies.

Visit profile

6 years ago #143048

I have exactly the same issue, what is the modification needed in SQManagedStrategy to fix it?

 

Thanks.

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

6 years ago #143051

Hello,

 

this might help to solve the issue

 

In NT open Tools -> Edit NinjaScript -> Edit Strategy, find SQManagedStrategy and find Initialize() method.
There is a line:

string str = Instrument.MasterInstrument.TickSize.ToString(System.Globalization.CultureInfo.InvariantCulture).TrimEnd('0');           

replace it with line:

string str = Instrument.MasterInstrument.TickSize.ToString("##.#").TrimEnd('0');

and it should start working correctly.

0

mabi

Customer, bbp_participant, community, 261 replies.

Visit profile

6 years ago #143078

Thank you Tomas. What i do not understand is why the template on which SQ generate code for is not updated with this.

0

kazex

Customer, bbp_participant, community, 6 replies.

Visit profile

6 years ago #143087

Hello,

this might help to solve the issue

In NT open Tools -> Edit NinjaScript -> Edit Strategy, find SQManagedStrategy and find Initialize() method.
There is a line:

string str = Instrument.MasterInstrument.TickSize.ToString(System.Globalization.CultureInfo.InvariantCulture).TrimEnd('0');

replace it with line:

string str = Instrument.MasterInstrument.TickSize.ToString("##.#").TrimEnd('0');

and it should start working correctly.

I did the change but the problem still occurs, I printed the price and the values seem to make sense but the some trades between SQ and NT are different, this does not happen with market orders, justo stop orders (entry order or stop trailing).

Enviado desde mi iPhone utilizando Tapatalk

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

6 years ago #143275

Please send me the STR strategy file to [email protected]. I need to check why it happens with your strategy, thanks

0

Viewing 8 replies - 1 through 8 (of 8 total)