Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

should an exit order test for 'in position'

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

    should an exit order test for 'in position'

    Best practices question.

    My code currently does not test for the existance of a position
    It just tests the exit condition and fires the appropriate exitlong/short.

    I notice with traceorders on, that this generates a minor err msg saying order ignored.

    So would you recommend testing for the existance of a postion first?

    For example

    This
    Code:
    // LSMA exit
       if (Position.MarketPosition == MarketPosition.Long && Low[0] < (LinReg(25)[1] - 2*TickSize))
       {
        ExitLong("LSMA","");
    
     }
    
    
    
    vs 
    
    This 
    
    // LSMA exit
       if (Low[0] < (LinReg(25)[1] - 2*TickSize))
       {
        ExitLong("LSMA","");
    
     }

    #2
    imported post

    Zoltran,

    Good question.

    Testing for a market position will be more efficient since the Exit() methods are not entered. On a simple strategy, the performance savings I suspect will truly be irrelevant. If you have a complex strategy with a lot more code, it may be come more relevant. Performance gain in my mind is irrelevant in real-time running, its the backtesting where performance can be noticed. Does a typical backtest take 10 seconds? Or does it take 10 minutes? Are you running optimization runs? These are the questions I would ask yourself to determine which approach to take.

    For clarification, there is no harm in entering an exit method when flat since the method will return anyways.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Related question.

      I have a strat that dynamically updates a stop loss based on a Moving avg.

      This can generate an update with every tick.... which could be a lot of updates.
      Especially with something like the qqqq and a real tic/tic feed.

      To mitigate this a bit, my logic uses the prior bars MA value,
      So the stop price only changes once a bar


      But what's the recommended best practice?

      I could only update it once a bar on 'first tick' or once a minute etc?


      Comment


        #4
        imported post

        For sure I would avoid updating the stop price on each incoming tick. Internally, NT will round the double value you pass in to a valid tick size and then ignore if the stop price == the new value. However, consistent redudant price changes within a bar can cost you money depending on how your brokerhandles price changes. Most only allow so many before they charge you.

        From a performance standpoint, NT can handle ultra-high frequency order changes and cancellation on a tick by tick basis. This has been thoroughly tested. If changing on a per bar basis is all your strategy needs and you are running with CalculateOnBarClose = false, I would do something like:

        if (FirstTickOfBar)
        // Change stop loss here, remember to acces SMA(Period)[1] which is the value of the bar that just closed.

        Ray
        RayNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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