Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop & Multi-Time-Frame (MTF)

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

    SetTrailStop & Multi-Time-Frame (MTF)

    Dear Support,

    i have the following problem in the backtesting:

    When i use a SetTrailStop without MTF, the trailing stop works fine.
    When i add a second timeframe in the strategy, the trailing stop no longer works correct on the primary time frame.

    What make i wrong? I note this NT information:
    Should you call this method to dynamically change the trail stop price in the strategy OnBarUpdate() method, you should always reset the trail stop price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your trail stop order on your next open position

    How can i reset the trail stop price/offset value?


    Example trail stop without MTF: - working fine
    ----------------------------------------------------------------------------------------------------------
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    }
    protected override void OnBarUpdate()
    {
    if(CCI(20)[0] > 200 && Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLong(DefaultQuantity, "OpenLong");
    SetTrailStop("OpenLong", CalculationMode.Ticks, 20, true);
    }
    }

    Example trail stop with MTF: - not work
    ----------------------------------------------------------------------------------------------------------
    protected override void Initialize()
    {
    CalculateOnBarClose = true;
    Add(PeriodeType.Minute, 3);
    }
    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 1)
    return;

    if(CCI(BarsArray[0], 20)[0] > 200 && Positions[0].MarketPosition == MarketPosition.Flat)
    {
    EnterLong(0, DefaultQuantity, "OpenLong");
    SetTrailStop("OpenLong", CalculationMode.Ticks, 20, true);
    }
    }


    Many thanks in advance.
    Last edited by tulx2305; 02-12-2013, 10:56 AM.

    #2
    Hello tulx2305,

    Thank you for your note.

    I was able to test your code and verify that the stop loss gets set correctly and does exit the position after 20 ticks of down movement.

    Please send me some examples of values the the price hit and the values the stop loss should have exited your position.

    If you can, let me know of a reproducible scenario I can test with. Such as a specific date and time in historical data or with the Market Replay.

    I look forward to assisting you further.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello tulx2305,

      Thank you for sending the screenshots.

      When back testing over historical data, bars will only have Open, High, Low, and Close data. This means some bar types such as renko, a tick based bar type, are not going to have the same fill results.

      The solution for this is to use the Market Replay which uses live data or use Intrabar Granularity to add a second data series to your strategy.

      Below is a link to another forum thread that discusses Intrabar Granularity. In post #12, Brett goes over Renko bars on Multi-Time Frame in back testing.
      http://www.ninjatrader.com/support/f...ad.php?t=49420

      Also, here is a link to a working reference sample that demostrates intrabar fill.
      http://www.ninjatrader.com/support/f...ead.php?t=6652

      How can i reset the trail stop price/offset value?
      Calling SetTrailStop will allow you to modify the price or tick offset of the trail. The current distance the trail is at will be reset once the position is flat.

      Please let me know if I can be of further assistance.
      Last edited by NinjaTrader_ChelseaB; 02-13-2013, 10:04 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      649 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 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
      576 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X