Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade Reversal Issue

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

    Trade Reversal Issue

    Hello Support,

    I have the following trade reversal issue on Currency Pairs
    1. Strategy Enter Longs ("Long5Q1" & "Long5Q2")
    2. Strategy EnterShort ("Short4Q1" & Short4Q2")
    3. Price Trend Up no target shown at the DOM.
    4. Short trade closed manually.

    The trade lists:
    1. Long trade: Entry name Long5Q1 & Long5Q2 with Exit name Short4Q1 & Short4Q2
    2. Short trade: Entry as Close Position, with Exit name blank.

    Attached is the Execution & Trades.
    Because short entry is Close Position, there is no target and there is no stop seen in the DOM. This is a major issue.
    Why is short entry name become exits for Long, and Close Position becomes Entry name? What is happening?
    How can I solve this issue?

    Thanks.

    Regards.

    EdwardK.
    Attached Files

    #2
    Hello Edward,

    Thank you for your post.

    Can you please share the strategy file that was used to generate these orders as well as the trace and log files for the day that this occurred.

    You can find the strategy file at:
    My Documents\NinjaTrader\bin\custom\strategy

    Trace and logs are stored:
    My Documents\NinjaTrader\trace
    My Documents\NinjaTrader\log

    Send files for 20100812

    If you don't want to post here, can send a note to [email protected] Include reference to this thread:
    Support for the development of custom automated trading strategies using NinjaScript.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hello RyanM,
      Attached is the log and trace zip file.
      My strategy do a straight EnterLong and EnterShort.
      Relevant code snippets.
      Long5:
      case5: if (en5byAtm == false && Lg5Callable) {
      if (en5Q1 > 0) EnterLong(en5Q1,"Long5Q1");
      if (en5Q2 > 0) EnterLong(en5Q2,"Long5Q2");
      }


      For Short4
      case4: if (en4byAtm == false && Sh4Callable) {
      if (en4Q1 > 0) EnterShort(en4Q1,"Short4Q1");
      if (en4Q2 > 0) EnterShort(en4Q2,"Short4Q2");
      }


      Thanks.

      Regards.

      EdwardK






      Thanks.

      Regards.
      Edwardk.
      Attached Files

      Comment


        #4
        Hello EdwardK,

        Entries will reverse a position, so the short entry name is used for the exit long signal.

        The short entry exited the long position and then entered short.

        The short position is then closed at 9:24.

        If you don't want reversal behaviour, you should add market position checks to your entry conditions.

        Example:
        if (entershortConditions && Position.MarketPosition != MarketPosition.Long)
        EnterShort();
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hello RyanM,

          That is NOT what the Help Guide says. My understanding is that NT will handle closing existing position before entering short. That is why we do not need to check the current position. The OrderID seems to suggest that, the Close Position ID is smaller than the EnterShort. This is not correct behaviour of NT. How can it take Entry name as Exit? This particular NT behaviour is incorrect.

          The Log also show NT is cancelling all the profit and stops of the Shorts after that.

          If I check first, knowing position is 2 Longs, I Exit 2 long first and issue EnterShort 2, I could end up with 4 shorts! I posts this issue in the forum last time. Because NT will see it is still has two Longs (the exit could have been filled and delayed, NT does not know yet), and still issue Close Position, then Enter Short.

          Please let me know.

          Thanks.

          Regards,
          EdwardK

          Comment


            #6
            Your conditions for ShortEntry evaluate to true. This statement will close your long position and then enter short.

            Is this what you feel is incorrect?

            Entry Methods
            Entry methods are used to submit orders that create a market position if none exists or to reverse an existing position.

            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hello RyanM,

              I capture the highlight of the Log on NT issuing Close then Short orders, which is correct. Please see picture attached or the actual Log file sent earlier.

              Although Close is issued first, the two short orders are filled first by IB. But NT know which Order is which, you can see it in the log. So it should not take first Filled to be the Exit.

              Thanks.

              Regards.
              EdwardK
              Attached Files

              Comment


                #8
                Sorry, I'm not following here. ShortEntry issues two orders at the same time. One order closes your position and the other enters short. Are you seeing something else here?
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hello RyanM,

                  Please see the Log, time at 8/12/2010 9:24:10 to 9:24:13

                  I issue two EnterShort of 0.1M each. NT processed them to become, first Close order of 0.2M, and then two Shorts of 0.1M each. (Ie.three orders to broker) This is as described by the Help Guide. We do not have to worry about positions, NT handles them for us.

                  The log then shows orders are accepted then working.

                  Then comes orders are filled, but the Two Short orders are filled first then the Close order (as shown in the Log). NT knows the Order ID, so it know what is what. So it should pair the Close as exit of previous Long Trade. And the Short is an Entry rather than as Exit.
                  But NT incorrectly use the first Filled order (two Shorts) as the Exit! (This is the incorrect that I mention)

                  Then NT cancels the Targets and the Stops of my two EnterShorts. This is probably the side effect of being incorrect on the pairing. Hence these cancellation are also incorrect. And this is a major issue.

                  Please let me know.

                  Thanks.
                  Regards,
                  EdwardK.

                  Comment


                    #10
                    Hi Edward,

                    I see what you're saying now but this is not likely causing the issue with your targets and stops cancelling. The log message indicates:

                    8/12/2010 8:47:53 PM|1|32|Order='339963537/DU60927' Name='Profit target' New State=Cancelled Instrument='$GBPUSD' Action=BuyToCover Limit price=1.55735 Stop price=0 Quantity=0.1M Type=Limit Filled=0 Fill price=0 Error=NoError Native error='Order Canceled - reason: (202)'

                    You will have to pursue the exact reason for canceling with your broker. It indicates Native Error 202.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello RyanM,

                      The instrument on discussion is $USDJPY.

                      8/12/2010 9:24:12 PM|1|32|Order='339963549/DU60927' Name='Profit target' New State=PendingCancel Instrument='$USDJPY' Action=Sell Limit price=85.545 Stop price=0 Quantity=0.1M Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
                      8/12/2010 9:24:12 PM|1|32|Order='339963548/DU60927' Name='Trail stop' New State=PendingCancel Instrument='$USDJPY' Action=Sell Limit price=0 Stop price=85.395 Quantity=0.1M Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''
                      8/12/2010 9:24:12 PM|1|32|Order='339963551/DU60927' Name='Profit target' New State=PendingCancel Instrument='$USDJPY' Action=Sell Limit price=85.595 Stop price=0 Quantity=0.1M Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
                      8/12/2010 9:24:12 PM|1|32|Order='339963550/DU60927' Name='Trail stop' New State=PendingCancel Instrument='$USDJPY' Action=Sell Limit price=0 Stop price=85.375 Quantity=0.1M Type=Stop Filled=0 Fill price=0 Error=NoError Native error=''

                      There are no errors till now.
                      Then the cancellations with the following errors:
                      Error=NoError Native error='Order Canceled - reason: (202)'

                      Why there is PendingCancel ? There is no errors till then, who triggers this ? Are you saying broker does this Not NT ??

                      Thanks.

                      Regards,
                      EdwardK

                      Comment


                        #12
                        Yes, it indicates Native Error, which is not generated by NinjaTrader. You will have to discuss with your broker what error code 202 means.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello RyanM,

                          I have resolved the issue by moving reversal trade onto OnOrderUpdate. New entries are pending until existing positions are confirmed close via OnOrderUpdate.

                          I have another problem, regarding NT Trail Stop. I use a static NT Trail Stop setup at Initialize. I also have Exit Strategies. The issues are:
                          1. Trail stops may be hit at the time as my strategy exit, occasionally, ending in new reverse position, with no target and stop.
                          2. Trails stops may be hit at the same time as a reverse trade entry is given, also ending is too many reverse positions. Additional reverse position has no stop and target.

                          To resolve this issue, we need to know where the trail stops are for the positions.
                          How can I know where is the trail stop for the existing positions?

                          Thanks.

                          Regards.
                          EdwardK.

                          Comment


                            #14
                            Hi Edward,

                            Glad to hear you were able to solve this. Thanks for sharing your solution.

                            You can see this reference sample for monitoring trail stop orders:


                            The sample creates array lists for targets and stop losses, but you can use the same principle for your TrailStop orders, and identify through name property.

                            #region Variables
                            private ArrayList trailStopTokens = new ArrayList();


                            if (order.Name == "Trail stop")
                            trailStopTokenTokens.Add(order.Token);
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks RyanM.

                              Regards.

                              Edwardk

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              633 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              566 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X