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

onBarUpdate or onExecution

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

    onBarUpdate or onExecution

    I have a strategy that starts out without a target and as price moves in my favor I only want to exit if there is a particular pullback from the previous candle's advance. Not to get bogged down in the exact details of this - what I'm pondering is whether it would be better to trigger an Exit order in the onBarUpdate method (where I evaluate whether it's time to exit) or in onExecution. I'm also wondering it it may be better to just reassign my stop to Close[0].

    I am currently using the advanced ordering flow (per the recommended NT examples) which means triggering entries in onBarUpdate() but setting both my Target and Stop in the onExecution() method after assuring that my Entry has been properly filled. If you're experienced with NT order flow then I'm sure you are familiar with all that and that I don't need to elaborate.

    Now let's assume I have seen a price pullback that justifies an exit - I now have various options of how to get out:

    1) I have already a stop in place, which was set as an initial stop loss (ISL) in my onExecution method and which was later propagated along (manually - I don't use NT TrailingStops). So I could theoretically just set that stop to the current Close[0]. I would prefer doing that in my onExecution method but it's not going to be called unless there is an execution scheduled, right? So I would have to do this call in the onBarUpdate() method I suppose.

    2) Upon triggering an exit point I could set an Exit order to the current Close[0] - again in my onBarUpdate method. This would automatically close out my open Entry and Stop orders.

    3) I could do a variation of 2) in that I set a very distant Exit in my onExecution method right after my Entry - let's say I would set it to Double.MaxValue (for a long) or 0 for a short. So now I have a faux stop in place that will never get hit. Then, when I am ready to exit I reassign the Exit order in onBarUpdate. Not sure if there's an advantage of doing that...

    Which of those three approaches would you choose? I'm trying to keep my order flow as clean as possible and any suggestions would be appreciated. If anything is unclear please ask away.
    Last edited by molecool; 03-16-2013, 12:04 PM.

    #2
    Originally posted by molecool View Post
    ... 1) I have already a stop in place, which was set as an initial stop loss (ISL) in my onExecution method and which was later propagated along (manually - I don't use NT TrailingStops). So I could theoretically just set that stop to the current Close[0]. I would prefer doing that in my onExecution method but it's not going to be called unless there is an execution scheduled, right? So I would have to do this call in the onBarUpdate() method I suppose.
    Looks like the cleanest option (not the least reason being that it is what I use myself). You cannot do it from OnExecution() because there is no event that has caused an execution: you do it from OnBarUpdate() using COBC = false, or else do it from OnMarketData(), where the COBC setting is completely irrelevant. (As an aside, because all my entries are made with a "COBC = true" setting, I do all instant actions from OnMarketData(). Unfortunately, we cannot backtest or optimize using OnMarketData() events, so it means that I develop using a secondary 1-tick or 1-range barSeries, then disable the secondary series in real trading, so that the OnMarketData() event handles the instant exits. It is bad enough loading a 1-tick barSeries in backtest; I am not about to do it live: speedy response is too important to me for me to bog down my processor with a 1-tick series being processed on every tick).

    Comment


      #3
      Originally posted by koganam View Post
      Looks like the cleanest option (not the least reason being that it is what I use myself). You cannot do it from OnExecution() because there is no event that has caused an execution: you do it from OnBarUpdate() using COBC = false, or else do it from OnMarketData(), where the COBC setting is completely irrelevant. (As an aside, because all my entries are made with a "COBC = true" setting, I do all instant actions from OnMarketData(). Unfortunately, we cannot backtest or optimize using OnMarketData() events, so it means that I develop using a secondary 1-tick or 1-range barSeries, then disable the secondary series in real trading, so that the OnMarketData() event handles the instant exits. It is bad enough loading a 1-tick barSeries in backtest; I am not about to do it live: speedy response is too important to me for me to bog down my processor with a 1-tick series being processed on every tick).
      Hey koganam - thanks so much for your input - very much appreciated! Anyway, as you may recall COBC is set to false for this strategy. I have never used OnMarketData() - is that part of the managed or unmanaged call flow? (I assume it's the former) So based on the docs I take it this one is being called on every market event. I don't see a particular advantage of using that as COBC is set to false already.

      Backtesting isn't going to work for this strategy anyway because I decided to only use my minute series and omit adding a tick series (for reasons you have already outlined).

      Last question - why would you use a Stop order and not an Exit order from the onBarUpdate() method?
      Last edited by molecool; 03-16-2013, 05:39 PM.

      Comment


        #4
        Originally posted by molecool View Post
        Hey koganam - thanks so much for your input - very much appreciated! Anyway, as you may recall COBC is set to false for this strategy. I have never used OnMarketData() - is that part of the managed or unmanaged call flow? (I assume it's the former) So based on the docs I take it this one is being called on every market event. I don't see a particular advantage of using that as COBC is set to false already.
        Absolutely correct to what I have emphasized in red. I said as much.
        ... Last question - why would you use a Stop order and not an Exit order from the onBarUpdate() method?
        Greed? Hopium? If I use a Stop at the price that I am going to get out anyway, then if the market suddenly takes off in my direction after all (maybe I am long, and The Bernank announces a new round of instant POMO), the market has kept me in. I generally prefer the market to take me out, rather than me get out, so I arrange for the market to take me out, but only if it is no longer going in my favor.

        Comment


          #5
          Originally posted by koganam View Post
          Absolutely correct to what I have emphasized in red. I said as much.

          Greed? Hopium? If I use a Stop at the price that I am going to get out anyway, then if the market suddenly takes off in my direction after all (maybe I am long, and The Bernank announces a new round of instant POMO), the market has kept me in. I generally prefer the market to take me out, rather than me get out, so I arrange for the market to take me out, but only if it is no longer going in my favor.
          Hey thanks again for taking time to respond over the weekend - you've been very helpful in the past and I very much appreciate that.

          Anyway, I'm not sure I follow your logic regarding the use of a stop vs. an exit order. Both orders would turn into a market order immediately at the market price. So even if the Bernank pulls another scheme and the market runs up the exchange would receive the same market order to buy back or sell my position at market. Not sure what difference it makes - except maybe technically within NinjaTrader. That is what I was alluding to in fact - in the end it's esoteric, correct? Same difference so to say.

          Comment


            #6
            Originally posted by molecool View Post
            Hey thanks again for taking time to respond over the weekend - you've been very helpful in the past and I very much appreciate that.

            Anyway, I'm not sure I follow your logic regarding the use of a stop vs. an exit order. Both orders would turn into a market order immediately at the market price. So even if the Bernank pulls another scheme and the market runs up the exchange would receive the same market order to buy back or sell my position at market. Not sure what difference it makes - except maybe technically within NinjaTrader. That is what I was alluding to in fact - in the end it's esoteric, correct? Same difference so to say.
            Not quite. Once again, the devil is in the details. A Stop order only becomes active after the stop is hit; an exit order is immediately active. Let us use some example prices to demonstrate.

            The /ES is at 2025.50, and we are long. You put in an exit order to sell at 2025.00. The current market price is higher than your exit price, so you are immediately filled. I, on the other hand, place a Stop order at the same 2025.00. Unless and until the market retreats to my Stop Price, I do not have an active order to sell my position. If the market now takes off, I can fall to my knees and give all thanks and praise to The Bernank Gift Machine, because I am still in the market. No need to tell you that I will be furiously adjusting that Stop upwards behind the market.

            Of course, the question arises: "What about if the orders are placed by both of us, at the current price of 2025.50? Again, the devil is in the details. While very unlikely, there is still a minute chance that if the market were to take off just as I placed my order, the delay in transmission might have my Stop Order behind the market when the order actually arrives at the exchange after my 'puter processes and sends the order, and I will be in clover. No matter how small the chance, I would rather have the opportunity if it comes along. To each his own, I guess.

            Comment


              #7
              Originally posted by koganam View Post
              Not quite. Once again, the devil is in the details. A Stop order only becomes active after the stop is hit; an exit order is immediately active. Let us use some example prices to demonstrate.

              The /ES is at 2025.50, and we are long. You put in an exit order to sell at 2025.00. The current market price is higher than your exit price, so you are immediately filled. I, on the other hand, place a Stop order at the same 2025.00. Unless and until the market retreats to my Stop Price, I do not have an active order to sell my position. If the market now takes off, I can fall to my knees and give all thanks and praise to The Bernank Gift Machine, because I am still in the market. No need to tell you that I will be furiously adjusting that Stop upwards behind the market.

              Of course, the question arises: "What about if the orders are placed by both of us, at the current price of 2025.50? Again, the devil is in the details. While very unlikely, there is still a minute chance that if the market were to take off just as I placed my order, the delay in transmission might have my Stop Order behind the market when the order actually arrives at the exchange after my 'puter processes and sends the order, and I will be in clover. No matter how small the chance, I would rather have the opportunity if it comes along. To each his own, I guess.
              Yes, makes sense - problem is that in an automated scenario it would leave my position open, which isn't really what I want. I get your reasoning though and thanks for taking the time to elaborate. Much obliged as usual.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ZeroKuhl, Yesterday, 04:31 PM
              4 responses
              28 views
              0 likes
              Last Post ZeroKuhl  
              Started by cupir2, Yesterday, 07:44 PM
              3 responses
              21 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by reynoldsn, Yesterday, 07:26 PM
              2 responses
              14 views
              0 likes
              Last Post reynoldsn  
              Started by MartinT, 05-17-2023, 06:00 AM
              18 responses
              173 views
              0 likes
              Last Post flybuzz
              by flybuzz
               
              Started by sgordet, Today, 05:24 AM
              2 responses
              21 views
              0 likes
              Last Post sgordet
              by sgordet
               
              Working...
              X