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

Order rejected because of "insufficient buying power"

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

    Order rejected because of "insufficient buying power"

    My strategy's SELL order to close a short positon in a live cash account at MBT was rejected because of "insufficient buying power." According to the MBT Navigator log this normal Sell order was interpreted as a SELL SHORT order, apparently because it arrived before my pending Stoploss order was cancelled and, if accepted, would have resulted in a net short position instead of being flat.

    The log file shows ALL the details of ALL 6 strategies I had running in Cash and Sim accounts, which is pretty confusing to look at, so I'm just attaching an image of the Order file for this particular strategy, which seems to have enough information for a diagnosis.



    Questions:
    1. Is my interpretation correct and does it mean that I need to include a bit of code to cancel the Stop order before submitting the Exit order? If so, any examples, pointers?
    2. MBT's specific reason for rejecting my order was "insufficient buying power." Does this mean that this order would NOT be rejected if my account did have sufficient buying power? That would be disastrous if it resulted in an unintended short position while I was asleep.
    3. Ninja's fail safe mechanism (shutting down the strategy and then trying to close any open position) worked well in this case, but apparently I can't always count on that. So what's the best way to ensure that such a thing will never happpen again in future?
    I'll be grateful for any and all the help I can get on this issue!
    Attached Files

    #2
    Hello,

    Quick question, was this on stocks this occured on?

    I look forward to assisting you further.

    Comment


      #3
      Hi Brett,

      No it was forex at MBTrading.

      Comment


        #4
        Hello,

        I know of an issue with this on equities but no forex.

        Can you please send me your trace and log files that this occured on and please let me know the time and date this occured.

        Please send them vie ControL Center->Help->Mail To support and put ATTN: Brett and reference this forum post.

        I look forward to assisting you further.

        Comment


          #5
          Hello,

          Ok thanks for sending that in.

          This is not related to a sell short order it was simply a sell order:

          New state=Rejected Instrument='$EURUSD' Action=Sell Limit

          The reason this occured is you did not have enough margin in your account to cover 2 sell orders.

          1 for your stop loss and the other your profit target.

          Even though only one was going to be filled the system interprets it as dtwo different orders to go short/exit the position.

          Since you did not have enough equity in th account for a 2 short position the second order was rejected by their risk management system.

          To get around this you needed to first cancell your stop loss before you submit your exit order.

          If you need help with this let me know, how are you submitting your stop loss? What method are you using?

          Let me know if I can be of further assistance.

          Comment


            #6
            Thank you Brett. That's what I thought. YES, I'm not sure how to code a cancelation of my stoploss before submitting my exit order. Could you please tell me how to do that?

            I'm using SetStopLoss under Intialize() to set my stoploss.

            Comment


              #7
              Hello,

              Ok, you would need to no longer use SetStopLoss().

              Insteaad you would use this method:

              The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


              Then you will be able to cancel the orderID via this sample, this will show you how to cancel orders:

              Following are links to all available NinjaScript reference samples within this forum section: Strategy Reference Samples (NinjaTrader 8) - also applicable to NT7 Using a time filter to limit trading hours (http://www.ninjatrader.com/support/forum/showthread.php?t=3226) Using multiple entry/exit signals simultaneously


              Then finally you can submit and order to exit the position.

              Comment


                #8
                Thanks for your help, Brett. That should do it.

                Comment


                  #9
                  One more question (at least!)

                  Whoops, I guess I'm not quite finished. I'm using the OnExecution() method as demonstrated in SampleOnOrderUpdate to submit my stoploss so that I can later cancel it before submitting my Exit order. I think I'm getting it, but this is my first time to work with these methods so I have a question:

                  I can see that I will need separate stoploss statements for the long and the short side because in the former case the stoploss amount is subtracted from the AvgPositionSize and in the latter case it is added. Naturally, the sample only shows the long side, so I'm not sure WHERE to put the statement for the short side.

                  Can I nest both statements inside the same OnExecution() block as I have done in the attached image, or do I need to structure it in some other way?
                  Attached Files

                  Comment


                    #10
                    Hello,

                    Great glad to see.

                    Actually you would not want to use Position.MarketPosition at all down in OnExecution().

                    What you would want to do instead is below:



                    if (execution.MarketPosition == MarketPosition.Long)

                    and vice versa for your short stop loss.

                    Let me know if I can be of further assistance.

                    Comment


                      #11
                      Ah yes, that makes sense. Thanks.

                      And thanks for persevering with this (I can't promise I'm finished yet!). Studying the IOrder methods makes me appreciate just how much NT's does for us intermediate programmers inside the robust "invisible code convenience wrapper" of the simpler managed orders. And yet I'm grateful for the new willingness to provide support for these methods. Since I've seen what a barrage of related support questions this has unleased, and I feel I must commend you all for your heroism! Lol.

                      Comment


                        #12
                        Hello,

                        It is no problem Glad to be of assistance.

                        Comment


                          #13
                          Wait, we're not done yet!

                          I think I've got the front end of this figured out, i.e. how to submit entryOrder and stopOrder so that they will have an IOrder ID that I can later (back end) use to cancel the stopOrder, but I'm still having problems with the back end.

                          The link http://www.ninjatrader.com/support/f...php?t=3220 you gave me in post #7 above that was supposed to show me how to cancel orders took me not to a single Strategy Reference Sample but to a menu of 24 Samples.

                          I've searched that menu very hard but I could find no Sample that deals with both the front and back ends of my situation, but from studying many other threads and Help resources it seems the best the advice is to cancel my stop and wait for confirmation that it has been cancelled from within OnOrderUpdate. Right?

                          Now here's the problem: I have to cancel my stopOrder before my ExitLong() order is submitted but I don't want do that until my Exit conditions exist. Since that depends on technical analysis of what's happening with the BARS, it needs to be detected from within OnBarUpdate. Am I right?

                          So how and where do I merge or link the OnBarUpdate events that detect my exit conditions with the OnExecution and OnOrderUpdate events that cancel and then confirm cancellation of my stopOrder, so that I can THEN send my Exit order?

                          What am I missing? There's no Sample that I can find that demonstrates how to do both ends of this thing. I noticed while searching the forum for hints that there are a lot of other threads dealing with this or very similar Stoploss/Exit issues under IOrder methods. I'm not the only one that needs this solution. Maybe its time for Josh to write a Reference Sample that deals specifically with this Stoploss/Exit issue.

                          Would you please pass this request to him?

                          Meanwhile, can anyone else out there shed light on this? Doesn't anyone with an MBTrading cash account use stoplosses together with technical exits? If so, how do you avoid having your technical exits canceled? Inputs would be much appreciated!

                          Comment


                            #14
                            Hello,

                            Think your just missing the sample on how to cancel it. Thought I had linked it, sorry.

                            Please check this sample out. This will show how to cancel the order.

                            When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until


                            You'll simply once your ready to reverse your position, then cancel the stop loss first, then on confirmation of the cancellation then you wil want to have previously set a variable on OnBarUpdate that you can use in OnOrderUpdate() that once the stop order is cancelled to then immediately reverse your position. Then reset this variable once it is done. You would only set this variable when you detect that a reverse is ready to occur.


                            If you hae any further questions please let me know.

                            Comment


                              #15
                              I think I see what you're saying, Brett, but it seems overly complicated. Why not just cancel the stop under OnBarUpdate (which is one of the possibilities shown in SampleCancleOrder) and then Exit the position directly under OnOrderUpdate as soon as the stop cancellation is confirmed? And then reset the exitOrder. Something like this:

                              Code:
                               
                              [U]Variables[/U]
                              private IOrder stopOrder = null;
                              private IOrder exitOrder = null;
                               
                              [U]OnBarUpdate() [/U]
                              if (exit conditions)
                              {
                                CancelOrder(stopOrder);
                              }
                              [U]OnOrderUpdate[/U]
                              if (stopOrder != null)
                              {
                                 if (order.OrderState == OrderState.Cancelled)
                                 {
                                    stopOrder = null;
                                    exitOrder = ExitLong(myExitLong", "myEnterLong")
                                  }
                              }
                              if (exitOrder != null)
                              {
                                  if (order.OrderState == OrderState.Filled
                                  {
                                     exitOrder = null
                                  }
                              }
                              Would that work? If not, please suggest alternative code. (This is hard for me to test experimentally because the problem occurs only in my live cash account and I can't simulate it.)

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by nicthe, Today, 02:58 PM
                              1 response
                              7 views
                              0 likes
                              Last Post nicthe
                              by nicthe
                               
                              Started by percy3687, Yesterday, 12:28 AM
                              3 responses
                              30 views
                              0 likes
                              Last Post percy3687  
                              Started by SilverSurfer1, Today, 01:33 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post SilverSurfer1  
                              Started by ETFVoyageur, Today, 10:27 AM
                              2 responses
                              18 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by CommonWhale, Today, 01:12 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post CommonWhale  
                              Working...
                              X