Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Commissions - Enter once, exit twice

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

    #16
    Hello fosh,

    You'll have to print all values you're working with and use TraceOrders output to track order submission.

    Print(Order.Filled);

    Ryan M.NinjaTrader Customer Service

    Comment


      #17
      Ryan,
      Where should I put the Print statement? OnExecution()?

      Comment


        #18
        There isn't really one place to put it. You need to track its value at various points so placing in multiple places won't hurt. OnExecution() is a good place to start since it will update with each execution event.
        Ryan M.NinjaTrader Customer Service

        Comment


          #19
          Ryan,

          Thanks for the info on info on TraceOrders. I've used it along with the Print() statements that I already had scattered among my code.

          A few things that I have notcied:
          - The share quantity is always incorrect by 100 shares
          - The Print(Order.Filled) statement shows a 100 in the Output window when this happens

          I have scoured my code and no where do I set an order for 100 shares. It's so odd that it it always 100 shares. I was having a similar problem with the ATM strategies that I configued giving me incorrect share sizes. Could there be a tie? I do not have an ATM strategy selected in the drop down box either. Could it have something to do with the Shadow SIM trade feature?

          Ryan, in your expeiences, generally speaking, what has revealed itself to be the issue when an "extra" order seems to be sent, albeit randomly? Any past experiences that may point me in a possible direction and make this a little less painful. At present, it just seems very random.

          Thanks
          fosch
          Last edited by fosch; 12-07-2010, 01:20 PM. Reason: typo

          Comment


            #20
            It's hard to guess at what may be happening since there are so many potential interactions. It also depends on how your code is structured - the scope where you're accessing and printing values.

            What may work best is starting from a simplified strategy to verify the mechanics and then add complexity only once you've verified behavior. Attached is a simple strategy that submits a real time market order for 100 and prints Order.Filled. From there you can try adding complexity like target orders or scaling in. Check and recheck everything before adding another layer.
            Attached Files
            Ryan M.NinjaTrader Customer Service

            Comment


              #21
              Thank you Ryan. This evening I will start over and begin recreate my strategy piece by piece as you have recommended. Thanks for your help.

              One last question to help me this evening, if I define a variable in a strategy's Initialize() method, and then I assign that variable a value in the OnBarUpdate() method, can I access that value from another method without explicitly passing the variable in as an argument? Like the OnExecution() or a button_click for instance?

              Many thanks.
              fosch

              Comment


                #22
                Sure, sounds good.

                Sorry, I didn't follow the 2nd question. Variables should be declared in variables region.
                private int movingAveragePeriod;

                If you want to assign this variable in code later on:
                movingAveragePeriod = 10;

                You can access this variable anywhere in the strategy code. Just type movingAveragePeriod
                Ryan M.NinjaTrader Customer Service

                Comment


                  #23
                  7.0 range bar predictor

                  Does anyone know of a range bar predictor (price panel) for version 7.0?

                  Comment


                    #24
                    Originally posted by NinjaTrader_RyanM View Post
                    Sure, sounds good.

                    Sorry, I didn't follow the 2nd question. Variables should be declared in variables region.
                    private int movingAveragePeriod;

                    If you want to assign this variable in code later on:
                    movingAveragePeriod = 10;

                    You can access this variable anywhere in the strategy code. Just type movingAveragePeriod
                    Morning Ryan,
                    Well it was a late evening last night, but I figured out what the problem was with my strategy. I do have a follow-up question as to how to fix it though.

                    But first, here is a brief summary so you don't have to run through the thread again to recall.

                    ISSUE: I have an Unmanaged Strategy that submits an order in the OnBarUpdate(), then in the OnExecution(), I place my stop order. The issue was that "sometimes" the correct quantity for my stop order was being submitted and "sometimes" the incorrect (some random quantity) was being submitted. For instance, if I placed an order for 1000 shares, then sometimes the stop would be for 1000 and other times it would be for some higher quantity like 1400?

                    Here's the OnExecution() code:

                    if (entryOrder != null && entryOrder == execution.Order)
                    {
                    if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
                    stopOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, execution.Order.Filled, 0, StopLossPrice, "OCOL1"+entryOrder.Instrument, "Long Stop");
                    }

                    PROBLEM DISCOVERED: It turns out that when an order was PART FILLED, my stop order was being submitted twice. For instance, in above example, if I wanted a stop for 1000 and I got a partial fill of 400, then I would end up with the first pass of OnExecution() submitting a stop for 400 shares, then a second pass submitting one for 1000 shares... and thus arriving at the erroneous 1400 shares.

                    SOLUTION: I still need help here.... I added the following code just before I submit the stopOrder in the code above:


                    if (stopOrder != null)
                    {
                    CancelOrder(stopOrder);
                    stopOrder = null;
                    }

                    With this code, when I get a Partial Fill, I cancel the original stopOrder, set it to null, and then re-submit a stopOrder with the new Filled amount. The problem is that NinjaScript does not like me Cancelling the stopOrder and then re-submitting a new stopOrder. It shows me this by immediately canceling the new stopOrder that was submitted.


                    How can I modify my stopOrder without adding shares to it?

                    Thanks.
                    Joe

                    Comment


                      #25
                      Hi Joe,

                      Glad to hear you identified what was happening with the order.filled property. One additional item you should look into is exposing the Quantity value from IExecution:


                      For changing orders, you don't want to cancel and resubmit. You can use ChangeOrder for this.
                      Ryan M.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

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