Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

no short orders generated

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

    no short orders generated

    Hi,
    I need help understanding why this logic will only take long orders and won't generate any short orders. It looks for a breakout to either side of the current day's High or Low:

    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Times[0][0].TimeOfDay == TimeGo.TimeOfDay)
    && (Close[0] < CurrentDayOHL1.CurrentHigh[0]))
    {
    EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), CurrentDayOHL1.CurrentHigh[0], "");
    }

    // Set 2
    else if ((Times[0][0].TimeOfDay == TimeGo.TimeOfDay)
    && (Close[0] > CurrentDayOHL1.CurrentLow[0]))
    {
    EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), CurrentDayOHL1.CurrentLow[0], "");
    }

    // Set 3
    if (BarsSinceEntryExecution(0, "", 0) >= BarsHold)
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    }​

    thank-you;
    David

    #2
    Hello trader3000a,

    You will likely need to use a print to find out what the values are when you think the short condition should be true. That would be how to know if its a problem with your condition or something else. The only other item you could try would be to enable TraceOrders.


    One note about your exits is that you should not submit both a long and short exit at the same time, you should make two sets for the exits and check if you are in a position before calling the appropriate exit for the position.

    Comment


      #3
      Hi Jesse,
      Thanks for the tip re: the Exits.

      When I turn off the Long condition entry the strat takes short trades. It seems like the short entry, because it's second in line, isn't allowed to be processed. Is this a part of the managed approach safety net? Is there a simple way to get around it if that's the case?

      thanks,
      David

      Comment


        #4
        Hello trader3000a,

        It may be that your signal names are not unique, you are using a blank string for both entries. Part of the order handling rules will block that:

        Methods that generate orders to enter a position will be ignored if:

        •The entry signal name is not unique

        Comment


          #5
          Hi Jesse,
          I named the entries and exits, but the issue persists. I don't get any errors except 1 on the first trade attempt in the series

          ( Strategy 'DFgoTime/-1': An Enter() method to submit an entry order at '01/03/2022 10:00:00' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.

          Any other ideas?

          if (BarsInProgress != 0)
          return;

          if (CurrentBars[0] < 1)
          return;

          // Set 1
          if ((Times[0][0].TimeOfDay == Timego.TimeOfDay)
          && (Position.MarketPosition == MarketPosition.Flat)
          && (Close[0] < CurrentDayOHL1.CurrentHigh[0]))
          {
          EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), (CurrentDayOHL1.CurrentHigh[0] + (1 * TickSize)) , @"longEntry");
          }

          // Set 2
          if ((Times[0][0].TimeOfDay == Timego.TimeOfDay)
          && (Position.MarketPosition == MarketPosition.Flat)
          && (Close[0] > CurrentDayOHL1.CurrentLow[0]))
          {
          EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), (CurrentDayOHL1.CurrentLow[0] + (-1 * TickSize)) , @"shortEntry");
          }

          // Set 3
          if ((Position.MarketPosition == MarketPosition.Long)
          && (BarsSinceEntryExecution(0, "", 0) >= BarsHold))
          {
          ExitLong(Convert.ToInt32(DefaultQuantity), @"longExit", @"longEntry");
          }

          // Set 4
          if ((Position.MarketPosition == MarketPosition.Short)
          && (BarsSinceEntryExecution(0, "", 0) >= BarsHold))
          {
          ExitShort(Convert.ToInt32(DefaultQuantity), @"shortExit", @"shortEntry");
          }​

          Comment


            #6
            Hello David,

            The managed approach does not allow a stop order to be submitted in the opposite direction if there is already a working order.

            "Methods that generate orders to enter a position will be ignored if:

            •A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction

            •A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction

            •The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction"


            If you are planning for a breakout and want both orders to be working, you will need to use the unmanaged approach and send the orders with OCO.

            Below is a link to an example.
            https://ninjatrader.com/support/foru...579#post770579
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello trader3000a,

              In that specific case one of the orders was ignored based on the internal order handling rules. That may have happened if both entry conditions happened at the same time. The conditions you have are fairly simple and as long as the close was greater than the low and less than the high both conditions could become true.

              Regarding the short side, do you have any targets being submitted in OnStateChange?

              One other note is that now that you are using signal names you need to update BarsSinceEntryExecution to also include the correct signal names so that will work as expected.

              I would suggest adding a print into each entry condition so you can physically see when each condition is becoming true, that may help to identify what is happening.

              Comment


                #8
                Hi,
                Re: Chelsea's reply:
                It seems like this OCO example can't be backtested. Is there an example that can?
                thanks,
                David

                Comment


                  #9
                  Hello David,

                  Noted in the post:
                  "These examples are designed to place orders in real-time so that you can see the orders appear and try and cancel one to see the behavior.
                  Unmanaged orders can also be submitted in historical data and be backtested by removing the check for real-time.​"

                  Remove the check for State.Realtime and move the code to OnBarUpdate() if you want to backtest the example.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Chelsea,
                    Apologies, but "move the code to OnBarUpdate" is too broad for me. I just get errors. Perhaps you could be more explicit, like cut lines 50 to 60 and place within the OBU brackets, then delete lines x, y, z to allow historical....
                    thanks,
                    David

                    Comment


                      #11
                      or just "move the second bracket from on bar update to the end of line x. delete lines x-z

                      Comment


                        #12
                        Hello David,

                        Below I am providing a link to a forum post with helpful resources on getting started with C# and NinjaScript.


                        I would encourage you to follow through code and understand how the code works so that you may make modifications.

                        That said, move the closing curly brace on line 64 to line 66 and then cut lines 138 to 146 and paste this on line 65.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,
                          Thanks, and I appreciate the advice. I've been programming for a couple of decades, and I have to say, 163 lines of code for one of the most basic types of trades going is unexpected for a trading software package.
                          It would be great if you and your team could abstract a bracket trade into a simple method. I understand you're creating flexibility with the unmanaged approach, but perhaps there could be an intermediate approach between managed and unmanaged for some fundamental trades such as a bracket. I find that most entries that work well can be written in a handful of lines, truly.
                          Again, thanks for your help, and no offense intended. I know you're busy.
                          David

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Today, 05:17 AM
                          0 responses
                          39 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          124 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          64 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          41 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          46 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X