Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Submitted order price doesn't equal actual price in formula?

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

    Submitted order price doesn't equal actual price in formula?

    This is bizarre. I really hope this is a something seen before.

    I am working on a strategy (with a lot of help from this board, thank you again), where the entry is a market order, and the exit is thru either a SetStopLoss or SetProfitTarget order. I have a structure that now does basically exactly what I want, and has backtested great.

    The problem is while running on a Sim account with a live feed. Every once in awhile I will get an error where it will try to submit a sell stop order ABOVE the market, or a buy stop order BELOW the market, and it will terminate the script and close position. I never get any such error or problem in backtesting.

    Now, I have tons of print statements in my code. There is only ONE function which calls SetStopLoss. In it:

    stopPx = Math.Round((tradedPx + myVar),5);
    SetStopLoss(input, CalculationMode.Price, stopPx,
    false);
    Print(Time[0] + " Setting " + (longOrShort ? "Long stop loss = " : "Short stop loss = ")+ stopPx);

    So I compute the stopPx, call SetStopLoss, and print stopPx.
    Yet, in my last example, it submitted a EURUSD sell stop order @ 1.1627, which was above the market (had just bot 1.1614), while the print output was:
    1/15/2015 8:01:00 PM Setting Long stop loss = 1.16056
    1/15/2015 8:01:00 PM Setting Long takeProfit = 1.16351


    I'm completely confused here. I'm hoping it's a quirk with the Sim account since nothing like this shows up in backtesting.


    #2
    Hi Locke, do you reset your stop when flat for this strategy?



    'Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position'

    That's what I would ensure as first step, an example could be for example seen here - http://www.ninjatrader.com/support/f...ead.php?t=3222

    Comment


      #3
      Ok this must be it. Now I read the doc, but it doesn't explicitly say how to do that.

      I mean, I could create some fake stuff like
      SetStopLoss(input, CalculationMode.Percent, 0.10, false)

      It would take that order (as the reset, in a place where i'm flat), but then when I actually enter a position, it would submit THIS order to the broker, before sending the real one I want to (under OnExecution()).

      Is there a way to completely clear SetStopLoss() so it's not even active anymore? Or do we have to live with the "Submit incorrect order which shouldn't be executed before submitting the correct one" ? Maybe it's ok, but I'd hate to see this cause a problem somehow either in execution or with the broker.

      I hope I was clear here.

      Comment


        #4
        Locke, you could not unset a set order. The approach is reset to some default offset when flat like shown in our example. Just (re)setting this would not create any order though, the sets get directly attached when an incoming entry execution is seen. If you want more control including the option to cancel a specific order object, the Exit() methods would need to be used instead.
        Last edited by NinjaTrader_Bertrand; 01-16-2015, 08:04 AM.

        Comment


          #5
          I think I understand now. Thanks for the help sir.

          Comment


            #6
            Could you do something like this? Then there really is no order.



            private IOrder stopOrder = null;
            private IOrder takeProfitOrder = null;

            OnExecution()
            {
            stopOrder = SetStopLoss( correct stuff);
            }

            OnBarUpdate()
            {
            if (Position.MarketPosition == MarketPosition.Flat)
            stopOrder = null;
            }

            Comment


              #7
              Nevermind. I tried that and get "Cannot implicitly convert type void to NT IOrder". I guess it's a wrapper for fancy stuff. Oh well, was worth a shot.

              Comment


                #8
                Locke, the Set's would not have an IOrder return. If you want more control, consider taking the Exit() methods route please.

                Comment

                Latest Posts

                Collapse

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