Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop Cancelling OCO Stop and PT immediately

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

    SetTrailStop Cancelling OCO Stop and PT immediately

    Hi,

    I'm having a bit of a problem which I can't work out despite numerous searches and testing. I get the feeling I'm simply missing something obvious, so I thought I'd ask the collected wisdom in the forums.

    My current strategy is based on a 6 Range Chart. For backtesting granularity I've Added a 1 Tick series within the Strategy. All Orders are placed on the 1 Tick Series with a 12 tick PT and a 4 tick trailing Stop set using SetTrailStop().

    e.g.
    SetTrailStop("FuriousCaterpillar", CalculationMode.Ticks, FuriousStop, false);

    This seems to work fine when Backtesting.

    I'm currently wanting to Forward test this strategy to work out a few bugs so I can watch it actually entering and exiting. (Still with a 1 Tick series in the script to enable the Trailing Stop to move every tick if required)

    Whenever I Enable the Strategy with Market Replay, the historical trades seem to be fine, but any Trades taken once Market Reply begins running have a very odd error occur.

    From the Log:
    The Order is submitted correctly.
    The Order executes correctly.
    The PT and Trailing Stop are submitted correctly.
    The Trailing Stop moves 1 Tick (in response to price)
    The Trailing Stop is cancelled.
    This cancels the PT due to being an OCO
    The original entry is left naked in the Market with no PT or Stop.

    If I remove the 1 Tick Series from the Code, and submit the orders and PT/Stop to the Primary series (6 Range) then it's all fine... But I'm back to the Stop only updating when the next 6 Range Bar Closes which is not enough granularity for this Strategy.

    Can you tell me why this occurs?
    What are my options for using the Strategy within Market Replay and ensuring the Trailing Stop updates every tick?
    Will I require markedly different code for Back testing vs Market Replay testing?
    Last edited by Welovethelibrary; 12-22-2013, 12:42 AM. Reason: Spelling, Context

    #2
    Hi Welovethelibrary,

    Thank you for your post and welcome to the forums!

    To investigate this further,

    Please send me your log and trace files to support[at]ninjatrader[dot]com by going to Help -> Mail to Support from the Control Center.

    Put ATTN Cal in the subject line and a reference to this forum post in the body.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Welovethelibrary View Post
      Hi,

      I'm having a bit of a problem which I can't work out despite numerous searches and testing. I get the feeling I'm simply missing something obvious, so I thought I'd ask the collected wisdom in the forums.

      My current strategy is based on a 6 Range Chart. For backtesting granularity I've Added a 1 Tick series within the Strategy. All Orders are placed on the 1 Tick Series with a 12 tick PT and a 4 tick trailing Stop set using SetTrailStop().

      e.g.
      SetTrailStop("FuriousCaterpillar", CalculationMode.Ticks, FuriousStop, false);

      This seems to work fine when Backtesting.

      I'm currently wanting to Forward test this strategy to work out a few bugs so I can watch it actually entering and exiting. (Still with a 1 Tick series in the script to enable the Trailing Stop to move every tick if required)

      Whenever I Enable the Strategy with Market Replay, the historical trades seem to be fine, but any Trades taken once Market Reply begins running have a very odd error occur.

      From the Log:
      The Order is submitted correctly.
      The Order executes correctly.
      The PT and Trailing Stop are submitted correctly.
      The Trailing Stop moves 1 Tick (in response to price)
      The Trailing Stop is cancelled.
      This cancels the PT due to being an OCO
      The original entry is left naked in the Market with no PT or Stop.

      If I remove the 1 Tick Series from the Code, and submit the orders and PT/Stop to the Primary series (6 Range) then it's all fine... But I'm back to the Stop only updating when the next 6 Range Bar Closes which is not enough granularity for this Strategy.

      Can you tell me why this occurs?
      What are my options for using the Strategy within Market Replay and ensuring the Trailing Stop updates every tick?
      Will I require markedly different code for Back testing vs Market Replay testing?
      That seems to be what the NT Help says must happen: Set() statements must be applied against the primary barSeries.

      ref: http://www.ninjatrader.com/support/h...nstruments.htm

      See the last folded section, that has this in the "Notes":
      Notes:
      1. Should you have multiple Bars objects of the same instrument and are using Set() methods in your strategy, you should only submit orders for this instrument to the first Bars context of that instrument. This is to ensure your order logic is processed correctly and any necessary order amendments are done properly.

      Comment


        #4
        Thanks Cal
        I'll run a fresh Forward Test when I get home and mail the logs through to you.

        Thanks Koganam
        I had missed that little section. Thank you for highlighting it.

        Hmmm...
        It does seem to say that its 'not a good idea'. But that doesn't tell me what specifically is the order management problem in doing this, why it works in backtesting and Strategy Analyser, but not Forward, or what the best option is to get around it.
        I think my two main options to avoid Set() methods on the 1 Tick series would be:

        1) Remove the 1 Tick Series, and use CalculateOnBarClose = false.
        However this would require a rewrite of key parts of the strategy, and potentially cause higher overheads and performance issues in backtesting. (I'm also still not sure even then whether the TrailingStop would then update every tick, or it would require Advanced Order Management and setting the stop on each tick)

        2) Use a named ATM instead.
        However, I expect this will remove the ability to use Stop and PT as variables in the Strategy Optimiser... since you're handing off to the ATM.

        Does this also mean that backtesting this way is a bad idea?

        I'd love to hear if anyone has encountered this problem before and has found a way to keep CalculateOnBarClose() = False but still managed a trailing stop on a per tick basis... and how they did it? (Or whether it just doesn't matter and I should go to tick-by-tick management).

        I'll send the logs and trace through shortly, Cal.
        Last edited by Welovethelibrary; 12-23-2013, 02:35 PM. Reason: Grammar!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X