Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ERROR WITH EnterOcoStop

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

    ERROR WITH EnterOcoStop

    Hi everyone, I have programmed a robot that each candle is necessary to put a EnterOcoStop order if necessary and if the conditions are met, Backtesting or optimization or WalkForward also gives some great results and do not jump any error.

    When I put on the Market Replay or operate in RealTime but in Demo connection jump these two errors . Click image for larger version

Name:	ninjaforum.jpg
Views:	1
Size:	40.4 KB
ID:	903340 Anyone ever happened ?

    Thanks in advance

    #2
    Hello fisagol,

    Thank you for your post.

    When running historically, if you use an invalid price for a stop order, this will not stop your script and will instead be ignored.

    The message in the output window when TraceOrders = true; will be similiar to the following:
    7/28/2015 4:01:00 PM Ignored PlaceOrder() method at 7/28/2015 4:01:00 PM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=2072.50 SignalName=Buy' FromEntrySignal='' Reason='Invalid order price, please see log tab'

    In real-time (including Market Replay), if you submit a stop with an invalid price, this will stop your script completely as this is a rejected order.

    You need to verify that the order you are about to place is a valid price.

    The BuyToCover stop is an order to exit a short position (for example a stop loss). You need to make sure that this order is above the current ask price for this order to not be rejected.

    What code are you currently using to submit this order?
    Are you doing a check that the exit order is above the current ask price?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      When I want to go with an order Stop what I do is this

      if (Position.MarketPosition == MarketPosition.Flat)
      {
      if (High[0] > topRange)
      {
      EnterOcoStop(longEntryPrice, bottomRange);
      }
      else if (Low[0] < bottomRange)
      {
      EnterOcoStop(topRange, shortEntryPrice);
      }
      }
      else if (Position.MarketPosition == Cbi.MarketPosition.Long)
      ExitLongStop(longExit);
      else if (Position.MarketPosition == Cbi.MarketPosition.Short)
      ExitShortStop(shortExit);
      My question now is: how should it do to check the price is right?

      ThankYou for answer!
      Last edited by fisagol; 09-17-2015, 11:54 AM.

      Comment


        #4
        Hello fisagol,

        This doesn't really show the code that calculates the price for the exit.

        What is shortExit?

        Is this a double?
        Is this a calculated price?
        How is this calculated?
        Where does this come from?
        How are you trying to use this?
        Are you making sure that this value is greater than the current ask price?


        To check that the price you are going to use is greater than the current ask you can use:
        if (myPriceVariable >= GetCurrentAsk())

        Where myPriceVariable is the price you are checking. Likely this will be shortExit if you are trying to use the shortExit variable as a calculated price.
        Last edited by NinjaTrader_ChelseaB; 09-17-2015, 12:00 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          My code to calculate this short exit an other variables is:
          double shortExit = Low[LowestBar(Low, TradeLength)] + (Range * 50);
          double longExit = Low[LowestBar(Low, TradeLength)] + (Range * 50);
          and to enter and buy or sell is:

          double longEntryPrice = Low[LowestBar(Low, TradeLength)] + (tradeRange * 80);
          double shortEntryPrice = Low[LowestBar(Low, TradeLength)] + (tradeRange * 20);
          Which it would have to indicate whether the value of the variable is greater than the ask or bid ?

          Thanks for ask!

          Comment


            #6
            Hello fisagol,

            You are using the low of a bar for an order than must be above the ask. I forsee some orders getting rejected for this. You cannot place a buy stop limit or buy stop below the ask price.

            I am also not seeing any code to ensure that the shortExit price is above the current ask.
            You will need to add this to ensure the order is not rejected.

            Also, I am not able to tell when this code is being triggered. If this code is triggered once in OnStartUp(), the price is going to change as data comes in and this price may be valid when the strategy starts but won't be valid after any time has passed.
            (I'm not saying that this is what you are doing, but I am saying when you set this does matter. You need to check that the price of the order is valid just before the order is placed without allowing any time to pass. This means that it needs to be in the same method during the same trigger)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Okei perfect time for me to stay clear when I put this:

              if (Position.MarketPosition == MarketPosition.Flat)
              {
              if (High[0] > topRange)
              {
              EnterOcoStop(longEntryPrice, bottomRange);
              }
              else if (Low[0] < bottomRange)
              {
              EnterOcoStop(topRange, shortEntryPrice);
              }
              }
              else if (Position.MarketPosition == Cbi.MarketPosition.Long)
              ExitLongStop(longExit);
              else if (Position.MarketPosition == Cbi.MarketPosition.Short)
              ExitShortStop(shortExit);

              would have to put something like this ?

              if (Position.MarketPosition == MarketPosition.Flat)
              {
              if (High[0] > topRange and (longEntryPrice >= GetCurrentAsk())
              {
              EnterOcoStop(longEntryPrice, bottomRange);
              }
              else if (Low[0] < bottomRange and shortEntryPrice <= GetCurrentAsk())
              {
              EnterOcoStop(topRange, shortEntryPrice);
              }
              }
              else if (Position.MarketPosition == Cbi.MarketPosition.Long)
              if(longExit > Bid) ExitLongStop(longExit);
              else if (Position.MarketPosition == Cbi.MarketPosition.Short)
              if (shortExit < Ask) ExitShortStop(shortExit);

              It would be nice this kind of conditional orders ?

              Or should it change?

              Or would you put them anywhere else?

              Comment


                #8
                Hi fisagol,

                When it comes to:
                if (High[0] > topRange and (longEntryPrice >= GetCurrentAsk())
                {
                EnterOcoStop(longEntryPrice, bottomRange);
                }

                I cannot say. EnterOcoStop() is not a NinjaTrader method, this is a method that was written custom for this script and I do not know how this works because you have not included this code.

                However, as long as you are calculating the stop price in the same method and same update as where the stop is being submitted, then you would want this check in the code that is calculating the price that the order is going to be submitted to.

                Lets say that your variable is below the ask price when it is calculated, if that is true, then set the variable to the ask price (plus one tick to make sure its isn't rejected).
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Okay then if I want to change the order OCO a limit order or stop order checking that is above or below the ask or bid as you would ?

                  Comment


                    #10
                    Hello fisagol,

                    I'm not certain what you are asking.

                    However, a buy limit or sell stop must be placed below market.
                    A sell limit or sell stop must be placed above market.

                    Yes, you should check that your order has a valid price before you place it so that it does not get rejected.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by habeebft, Today, 07:27 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_ChristopherS  
                    Started by AveryFlynn, Today, 04:57 AM
                    1 response
                    12 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by Max238, Today, 01:28 AM
                    4 responses
                    38 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by r68cervera, Today, 05:29 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by geddyisodin, Today, 05:20 AM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X