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

SumbitOrderUnmanaged Price Error

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

    SumbitOrderUnmanaged Price Error

    IsUnmanaged = true;

    In protected override void OnBarUpdate()

    I have the following code which generates the error:

    if ((entryOrder1 == null) && (entryOrder2 != null) && (entryOrder3 == null) && (SFlag == true) && (tradeflag == true) && (stopflag == false))
    { // Enter Short Order Filled and assigned to entryOrder2: SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, Quantity, aPrice, 0, "", "Enter Short");

    askincr = TickDistanceAsk * TickSize;
    bidincr = TickDistanceBid * TickSize;
    askPrice = GetCurrentAsk(0);
    bidPrice = GetCurrentBid(0);
    aPrice = askPrice + askincr;
    bPrice = bidPrice - bidincr;
    ssPrice = aPrice + (TickDistanceStop * TickSize);
    SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, Quantity, 0, ssPrice, "", "Enter SStop");
    stopflag = true;
    Print("Detection of Short Order Filled: entryOrder3 is:" + entryOrder3);
    Print("Detection of Short Order Filled: entryOrder2 is: " + entryOrder2);

    }

    Since ssPrice is greater than bidPrice, and the same error is generated by Strategy when OrderType is set to StopLimit, I don't know what I'm doing syntactically for this error to happen when my other limit order is filled. Please guide me. Thank you very much.

    #2
    Hi hirezsqwave, thanks for posting. I made a new topic because the other topic was 5 years old.

    What is the value of aPrice = askPrice + askincr compared to the Ask price at the time of order submission? I don't see ssPrice being used in the sell limit order, aPrice is being used for the limit price and the value of that variable is causing the error.

    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      The object of the initial two orders: a sell order which gets filled, and a buy order that sets a profit target is to have the buy order be filled at the bid price minus a range value that the trader can set, for example 2 ticks.Such generates a profitable trade if the market price goes down to the target price, which is calculated as bidPrice minus bidincr and stored in variable bPrice. When the market goes in the opposite direction, then an unrealized loss starts mounting. So, I'm inputting a new limit order at a stop distance that the trader specifies called TickDistanceStop. When I attempt to submit the stop order, it puts out the error that the Stop price can't be less than the bid price, but the calculation of ssPrice is aPrice + TickDistanceStop, a value much higher than the bid price, thus taking a losing trade if the current market matches the value of ssPrice. So, again, I'm not sure what I did incorrectly when placing this order to generate the error, the order rejection, and thus the termination of the strategy. In submitting the order, I've tried StopLimit for Order type and still get the same error. So, recently, I tried making it a Limit Order but the error is the same outcome. SFlag must be true for this code to execute. There is no error with the original trade except that the strategy leaves the target order in place, even though I've submitted a CancelOrder request.

      if (order.Name == "Enter Long" && orderState == OrderState.Filled)
      {
      entryOrder1 = order;
      longfillflag = true;
      Print("OnOrderUpdate Long Filled: " + order.Name);
      }

      plus if the above is true,

      if (Order.IsTerminalState(entryOrder1.OrderState))
      entryOrder1 = null;

      If the order wasn't filled, because a Stop Order was filled instead, then

      if ((order.Name == "Enter Long") && ((orderState == OrderState.Accepted) || (orderState == OrderState.Working)))
      {
      entryOrder1 = order;
      // order3flag = 2;
      Print("OnOrderUpdate Enter Long order is Active, but not filled: " + order.Name);
      if (shortfillflag == true && ((buystopfillflag ==true) || (sellstopfillflag == true)))
      {
      CancelOrder(entryOrder1);
      if (entryOrder1.OrderState == OrderState.Cancelled)
      entryOrder1 = null;
      }
      }

      Thank you for your guidance.

      Comment


        #4
        Hi hirezsqwave, the order in your first post that is not commented is:
        SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, Quantity, 0, ssPrice, "", "Enter SStop");

        and ssPrice is ssPrice = aPrice + (TickDistanceStop * TickSize);

        All buy limit orders need to be placed below the bid price. Your strategy is submitting orders on illegal sides of the market. You can confirm this by printing the price being used in the order vs GetCurrentAsk/GetCurrentBid before submitting the order. We have a collection of unmanaged strategy examples implementing trailing stops and brackets here for reference:




        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          Hi hirezsqwave, the order in your first post that is not commented is:
          SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, Quantity, 0, ssPrice, "", "Enter SStop");

          and ssPrice is ssPrice = aPrice + (TickDistanceStop * TickSize);

          All buy limit orders need to be placed below the bid price. Your strategy is submitting orders on illegal sides of the market.
          Not only that, but if ssPrice is supposed to be the LimitPrice, then it's highly
          probable OP is using the API incorrectly.

          SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, Quantity, ssPrice, 0, "", "Enter SStop");

          How so?
          The LimitPrice argument is always before the StopPrice.

          Wait, what's that sound?
          A thousand hands just slapped a thousand foreheads.

          Or some such proverb ... but I'm probably using it incorrectly.



          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,404 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          95 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          159 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Yesterday, 09:29 PM
          0 responses
          8 views
          0 likes
          Last Post Belfortbucks  
          Working...
          X