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

multi exit strategies

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

    multi exit strategies

    i am attempting to run a strategy that not only uses trailing stop and profittarget exits (which run from Initialize() ), but have two additional exit routines that run from OnBarUpdate() from within the same strategy.


    Is there a way to make sure that a stop that gets triggered on the same bar as an additional strategy does not run both simultaneous, ending up with a net short position (on a long only strategy)?

    I think this happened to me today when live testing.

    I am wondering if the following if-then logic in the OnBarUpdate() exits would work in front of the alternative exit strategies to prevent double exitting (ending up with a net reverse position w/ no exits).


    if (condition 1 &&
    Position.MarketPosition != MarketPosition.Flat)
    { ExitLong...

    Last edited by scriabinop23; 05-17-2007, 08:32 PM.

    #2
    There is no way to 100% guarantee that you will not get double fills if you elect to have exits via the SetStopLoss() and SetProfitTarget() methods and also call an exit method via the OnBarUpdate() method.

    If you need to have conditinal exits, I recommend going that approach 100%.
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      There is no way to 100% guarantee that you will not get double fills if you elect to have exits via the SetStopLoss() and SetProfitTarget() methods and also call an exit method via the OnBarUpdate() method.

      If you need to have conditinal exits, I recommend going that approach 100%.

      Will using the CalculateOnBarClose = false have any impact here? Might the use of this condition make OnBarUpdate() more easily catch the status?

      Comment


        #4
        That will not remove the risk of a double fill. It will allow you to submit your exit orders from OnBarUpdate() within a bar instead of at the end of the bar.

        Coding a strategy tick by tick is more trick than bar by bar. Its better to start with bar by bar strategy, understand and learn NinjaTrader's concept, then move to tick by tick if you feel the need.

        Also keep in mind that during backtest, its only ever bar by bar.
        RayNinjaTrader Customer Service

        Comment


          #5
          OK. I upgraded to the newest NT release 2.

          I tried this as my alternative exit, and the exit order doesn't get stimulated when the position.marketposition == marketposition.long is met.

          if (BarsSinceEntry("LongHammer") > timeStopBars
          && Position.MarketPosition == MarketPosition.Long
          && Position.GetProfitLoss(Close[
          0], PerformanceUnit.Currency) < 0
          )
          ExitLongLimit((Bars.CurrentBid),
          "TimeStop","LongHammer");


          The 'if Position.Marketposition = MarketPosition.Long' routine is not working. I am debugging with print routines and get this:
          SinceExit: 0 105100 SinceEntry:3 PL Current Position: -150.000000000006 Long

          Basically in this bar, timestopbars = 2 (passed from strategy spec), the P&L is negative, and the position is Long. That should satisfy all three contigencies.

          I isolated each contigency and this is confirmed. Position.Getprofitloss was fixed and works fine in the newest beta (thanks guys). And my bars since entry timestop works with the position... routine excluded as well.


          Comment


            #6
            For clarification, do you mean that the ExitLongLimit() is not triggered? If yes, then I would add a debug print statement after this method called to ensure its called then enable TraceOrders = true in Initalize(). By having this enabled, it will trace out data each time your code enters this method. It will provide you with an idea why this method is ignored.

            Additional info - http://www.ninjatrader-support.com/H...aceOrders.html
            RayNinjaTrader Customer Service

            Comment


              #7
              yes, now enabled. but yes, i think the boolean condition isn't even met to trigger the order.
              hmmm.

              by the way i just backtested this with the trace and it works fine.
              For some reasons the orders weren't triggering real time when running the strategy live.

              we'll see.
              Last edited by scriabinop23; 05-18-2007, 12:52 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by giulyko00, Today, 12:03 PM
              0 responses
              4 views
              0 likes
              Last Post giulyko00  
              Started by AttiM, 02-14-2024, 05:20 PM
              12 responses
              213 views
              0 likes
              Last Post DrakeiJosh  
              Started by cre8able, 02-11-2023, 05:43 PM
              3 responses
              238 views
              0 likes
              Last Post rhubear
              by rhubear
               
              Started by frslvr, 04-11-2024, 07:26 AM
              8 responses
              117 views
              1 like
              Last Post NinjaTrader_BrandonH  
              Started by stafe, 04-15-2024, 08:34 PM
              10 responses
              47 views
              0 likes
              Last Post stafe
              by stafe
               
              Working...
              X