Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 giulyko00, Yesterday, 12:03 PM
        2 responses
        10 views
        0 likes
        Last Post giulyko00  
        Started by r68cervera, Today, 05:29 AM
        0 responses
        3 views
        0 likes
        Last Post r68cervera  
        Started by geddyisodin, Today, 05:20 AM
        0 responses
        6 views
        0 likes
        Last Post geddyisodin  
        Started by JonesJoker, 04-22-2024, 12:23 PM
        6 responses
        36 views
        0 likes
        Last Post JonesJoker  
        Started by GussJ, 03-04-2020, 03:11 PM
        12 responses
        3,241 views
        0 likes
        Last Post Leafcutter  
        Working...
        X