Announcement

Collapse
No announcement yet.

Rounding Limit Price results in No Fill in Backtest?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rounding Limit Price results in No Fill in Backtest?

    Hi All,

    Currently, I am backtesting a strategy, and making sure I get realistic fills for further research. But I ran into a problem that I am not sure how to fix.

    Here is a working snippet:
    PHP Code:
    nPosPrice nLowerEnvelopeLast;
    Strategy.doLong("Long",Strategy.LIMIT,Strategy.THISBAR,100,nPosPrice
    When I try to round the fill price, because it is long, like 34.4635454, here is that code that does NOT work
    PHP Code:
    nPosPrice nLowerEnvelopeLast.toFixed(2);
    Strategy.doLong("Long",Strategy.LIMIT,Strategy.THISBAR,100,nPosPrice
    Debug prints in the nonworking version indicate the price is being rounded correctly. But the backtester isn't recognizing them as fills! Strange stuff, please help! XD

    - Roger

  • #2
    Haha, sorry all for wasting time, I found the answer.

    Using .toFixed results in the variable created as a string. So you multiply it by 1 to get a number.

    Corrected (working) code is now:
    PHP Code:
    nPosPrice nLowerEnvelopeLast.toFixed(2) * 1;
    Strategy.doLong("Long",Strategy.LIMIT,Strategy.THISBAR,100,nPosPrice
    - Roger

    Comment


    • #3
      Hi Roger,

      Thanks for posting the solution. I'm sure it will help others in the future.

      Thx

      Comment


      • #4
        Guys,

        I’ve recently been looking for a solution to the same problem. This is a good one.

        I’ve also found this solution by Alex and Brad. As usual with both of these chaps an excellent and elegant solution.

        here


        Hope that helps.

        Kind regards,

        Dan

        Comment

        Working...
        X