Announcement

Collapse
No announcement yet.

Backtesting - Adding to positions, closing the entire position on a stop

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

  • Backtesting - Adding to positions, closing the entire position on a stop

    Hi!

    I'm running eSignal 8.0

    I'm successfullt adding to positions in backtesting (with Strategy.doLong/Strategy.doShort, I'm successfully exiting partial positions on a profit target (Strategy.doSell/Strategy.doCover, but when my stop is eventually hit, I hit a snag. Even though the Strategy.isLong is reset, and parts of my remaining position is closed out at the correct date/price, my entire remaining position is not closed out for some reason.

    I've tried both:

    var nLot = Strategy.getPositionSize();
    Strategy.doSell("Long Stop2", Strategy.STOP, Strategy.THISBAR, nLot, nStop);
    (where nStop is the stop price)

    and
    Strategy.doSell("Long Stop2", Strategy.STOP, Strategy.THISBAR, 8300, nStop);
    (where I know 8300 is the number of shares that should be in the position at this time (also according to the trades tab on running the backtest))

    But it just refuses to stop me out of my entire position, carrying the long position over to the next signal, and even signals after that before eventually stopping out at a later stop. This happens even if a short signal is correctly processed inbetween.

    On top of this:
    If, for some reason, I've added to a position enough so that I exit more shares than the initial entry-position on a profit target, the subsequent stop is not recorded at all in Trades, but Strategy.isLong is still reset.

    (that is in all of the above:
    if(Strategy.isLong()) {
    setBarBgColor(nReturnBgColor); }
    shows the "right" trade, but it is not correctly recorded under Trades in backtesting)

    So, obviously my adding to a position messes "something" up, as partialing out of a position works correctly without adding to the position, but I don't understand how and why this would affect anything at all....

    Help appreciated...

    Regards,
    Bugg
    Attached Files
    Last edited by Bugg; 02-19-2008, 03:00 AM.

  • #2
    Bugg
    Without seeing the code I am not sure if this applies to your case but if I remember correctly there is an issue in the Strategy Analyzer when strategies scale in and out of a position (strategies that either scale in and exit or enter and scale out do not appear to be affected). In these cases the code itself is working as it should but the Strategy Analyzer is not organizing the report correctly.
    I believe eSignal is aware of the issue but as far as I know a fix has not yet been released.
    Alex


    Originally posted by Bugg
    Hi!

    I'm running eSignal 8.0

    I'm successfullt adding to positions in backtesting (with Strategy.doLong/Strategy.doShort, I'm successfully exiting partial positions on a profit target (Strategy.doSell/Strategy.doCover, but when my stop is eventually hit, I hit a snag. Even though the Strategy.isLong is reset, and parts of my remaining position is closed out at the correct date/price, my entire remaining position is not closed out for some reason.

    I've tried both:

    var nLot = Strategy.getPositionSize();
    Strategy.doSell("Long Stop2", Strategy.STOP, Strategy.THISBAR, nLot, nStop);
    (where nStop is the stop price)

    and
    Strategy.doSell("Long Stop2", Strategy.STOP, Strategy.THISBAR, 8300, nStop);
    (where I know 8300 is the number of shares that should be in the position at this time (also according to the trades tab on running the backtest))

    But it just refuses to stop me out of my entire position, carrying the long position over to the next signal, and even signals after that before eventually stopping out at a later stop. This happens even if a short signal is correctly processed inbetween.

    On top of this:
    If, for some reason, I've added to a position enough so that I exit more shares than the initial entry-position on a profit target, the subsequent stop is not recorded at all in Trades, but Strategy.isLong is still reset.

    (that is in all of the above:
    if(Strategy.isLong()) {
    setBarBgColor(nReturnBgColor); }
    shows the "right" trade, but it is not correctly recorded under Trades in backtesting)

    So, obviously my adding to a position messes "something" up, as partialing out of a position works correctly without adding to the position, but I don't understand how and why this would affect anything at all....

    Help appreciated...

    Regards,
    Bugg

    Comment


    • #3
      Hi Alex,

      I'm pretty sure my code works as intended, but I can't really say 100% sure (since the Analyzer messes up the output), but what you're describing seems to apply. It works if I skip the scaling out, and it works if I skip the scaling in, but it does not work scaling in and out.

      If it's an eSignal issue (that's not related to v8.0) I guess it'll just "have" to be fixed.
      Would be nice to get an official (We're working on it type of message, tho' )


      Thanks,
      Bugg

      Originally posted by Alexis C. Montenegro
      Bugg
      Without seeing the code I am not sure if this applies to your case but if I remember correctly there is an issue in the Strategy Analyzer when strategies scale in and out of a position (strategies that either scale in and exit or enter and scale out do not appear to be affected). In these cases the code itself is working as it should but the Strategy Analyzer is not organizing the report correctly.
      I believe eSignal is aware of the issue but as far as I know a fix has not yet been released.
      Alex

      Comment

      Working...
      X