Announcement

Collapse
No announcement yet.

Backtester Duplicating Trades

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

  • Backtester Duplicating Trades

    Hi,

    I'm encountering an issue with the backtester where it's duplicating trades. With my example below, I enter a long trade at 2017-09-27 with 1 contract and exits at 2018-01-22 with 1 contract. I logged the script and it only enters the trade once on 2017-09-27 with the Strategy.doLong returning true and only exits once on 2018-01-22 with Strategy.doSell returning true. Even using Strategy.isInTrade() between 2018-01-22 and 2018-02-05 returns false. For some reason the backtester is keeping the first long trade open until a new entry signal, which then it continues to provide incorrect dates and duplicate trades.


    Click image for larger version  Name:	Dup Trade.png Views:	0 Size:	11.9 KB ID:	268383


    Update:

    So, what is happening is about 125 bars directly after my first trade the script randomly resets and goes back to the first bar (bar 0) and reruns but keeps all the variable values. So instead of continuing from 9-27-0:0 to 9-27-0:15 it jumps back to the time template start 9-25-14:45 and reruns, however the second time through it continues from 9-27-0:0 to 9-27-0:15 just fine

    Update #2:

    The restart seems to be related to a getSeries call, maybe the sym()

    For example,
    PHP Code:
    mySeries getSeriesclose(sym(getSymbol() + "," myInterval))); 
    Will change where the script reloads based on the value of myInterval.
    In my case, myInterval = 15 resets after the first candle, myInterval = 60 resets after the first trade.

    I was looking at the documentation for sym, and noticed this:

    Formulas using sym() may be reloaded by the application if a separate chart using a Dynamic time template or a time template set to load more bars makes a secondary request for history on the same symbol's interval used by sym(). This is the default behavior of the application. If this negatively impacts the processing of a custom formulas running in other charts, the solution is to use custom time templates that load the same specific number of bars to avoid the secondary history requests made by other charts. When using multiple interval formulas it is recommended to avoid using Dynamic time templates or time templates that load different number of bars for the same interval in any of the charts present in the layout or page.
    I do not have a separate chart open, only have my main chart open, for my time template I am using the hard-coded Start Date/Time option
    Last edited by ewdeg98; 09-26-2019, 01:26 PM.
Working...
X