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

Managing the order of trades

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

    Managing the order of trades

    I am still learning but managed to put a system together that is showing potential.

    If certain conditions are met I enter long with EnterLongStop and short with EnterShortstop

    If the system was long and the condition to go short was met - the long trade would be closed and a short trade entered automatically

    After reading what I could find in the help file I then added SetTrailStop(CalculationMode.Ticks, 80); to the initialize method.

    Now all trades are exited only with trailstops.

    What do I need to do so that a trade may be exited by a trailstop OR a trade in the opposite direction?

    #2
    Using that line should not prevent you from reversing with an opposite directioned order. You most likely are hitting the stops before you reach the reversal condition. You can verify this for yourself by setting a ridiculously large stop that should theoretically never be triggered. When you do this you should see that your orders are still reversing as expected.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      unfortunately does not work

      Originally posted by Josh View Post
      Using that line should not prevent you from reversing with an opposite directioned order. You most likely are hitting the stops before you reach the reversal condition. You can verify this for yourself by setting a ridiculously large stop that should theoretically never be triggered. When you do this you should see that your orders are still reversing as expected.
      Josh

      Thanks for the reply

      I have done what you suggested. Made it 800 ticks wide. Number of trades reduced from 171 to 4 - all was only exited by trailstop - none by reversal in direction.

      To make sure I commented the trailstop line out - system then generated 171 trades again.

      Regards

      Comment


        #4
        Okay verge. Thanks for the information. Would you mind posting a simple as possible strategy that demonstrates the issue you are experiencing so I can play around with it?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          It works in a simple strategy

          Originally posted by Josh View Post
          Okay verge. Thanks for the information. Would you mind posting a simple as possible strategy that demonstrates the issue you are experiencing so I can play around with it?
          Josh

          I thought about what I could do with the least effort to do what you ask - so I inserted the following line in to a copied version of the SimplaMAcrossOver strategy that comes with NT. The line was SetTrailStop(CalculationMode.Ticks, 500);

          I then ran the strategy - and it work the way it should - when a trade was entered in the opposite direction the system executed - and did not wait for a trailingstop.

          So now I still don't know what I am doing wrong in my own strategy. (could it have something to do with the curly braces - when comparing the two strategies that is about the only thing I can see that differ (except for the conditions themselves of course) . My own strategy has more curly braces.

          The simple one is below:

          protected override void Initialize()
          {
          SMA(Fast).Plots[0].Pen.Color = Color.Orange;
          SMA(Slow).Plots[0].Pen.Color = Color.Green;

          Add(SMA(Fast));
          Add(SMA(Slow));

          CalculateOnBarClose = true;
          SetTrailStop(CalculationMode.Ticks, 500);
          }

          /// <summary>
          /// Called on each bar update event (incoming tick).
          /// </summary>
          protected override void OnBarUpdate()
          {
          if (CrossAbove(SMA(Fast), SMA(Slow), 1))
          EnterLong();
          else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
          EnterShort();
          }

          Comment


            #6
            Since it worked in the simple case we know the architecture is fine. That means some debugging on your strategy will need to be done to locate what is messing your strategy up. Please try debugging as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              It seems to happen because I used EnterLongStop

              Originally posted by Josh View Post
              Since it worked in the simple case we know the architecture is fine. That means some debugging on your strategy will need to be done to locate what is messing your strategy up. Please try debugging as per these tips: http://www.ninjatrader-support.com/v...ead.php?t=3418
              http://www.ninjatrader-support.com/v...ead.php?t=3627
              There is another difference between my strategy and the simple one I realised now is that the simple one use EnterLong while mine used EnterLongStop (and same for short)

              I could not find any documentation describing the interaction between SetTrailStop and using a stop order. Can you point me to a section that describes how they work together please?

              When I changed the order type from EnterLong Stop to EnterLong the SetTrailStop did not prevent a trade in the opposite direction anymore. The problem is that I want to use stop orders and trailstops - and have trade reversals

              Comment


                #8
                Please see this article on order rules: http://www.ninjatrader-support.com/H...verview36.html
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Josh,

                  I have to say I seemed to be confused about something similar to Verge. And I've studied all the relevant sections I can find on your on-line guide.

                  My strategy is working fine... I enter named positions using EnterLong() or EnterShort(). I place stops dynamically using ExitLongStop() or ExitShortStop() - obviously tied to the entries by name. All working.

                  However, I am looking to add another form of exit... which is effectively a reversal into a position in the opposite direction.

                  If I am currently long 1 contract and my position is named "MyLong"... and I have a working stop attached to that named long position called "MyLongStop"... If I now get a signal to go short, how do I exit my long and short one contract and get all the names right...? i.e. exiting the long called "MyLong" and entering a 1 contract short called "MyShort"...??


                  Do I have to use ExitLong() first and then on the next line call EnterShort() - named "MyShort"...???

                  Many Thanks
                  Last edited by Sidhartha; 04-14-2008, 01:24 PM.

                  Comment


                    #10
                    Guys... not sure if you've seen this post since I didn't post a new thread. Any thoughts...?

                    Comment


                      #11
                      Since you have been working with Josh, he will respond later on this evening.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Ray.

                        Comment


                          #13
                          Hi Sidhartha,

                          You could try just submitting the EnterShort() order directly. You may need to cancel your ExitLongLimit() order first depending on how you have it setup (see the Internal Order Handling Rules article in my previous post). Bear in mind if you are using market orders (EnterShort and EnterLong) you don't need to worry about the IOHRs.

                          Alternatively you can go with the approach you outlined. Just ExitLong() and then do an EnterShort and name it however you want.

                          If you can outline the exact methodology of orders you wish to place I can advise you on that case scenario. It is difficult to talk in generalities due to the order handling rules.
                          Last edited by NinjaTrader_JoshP; 04-15-2008, 02:06 AM.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by AaronKoRn, Yesterday, 09:49 PM
                          0 responses
                          11 views
                          0 likes
                          Last Post AaronKoRn  
                          Started by carnitron, Yesterday, 08:42 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post carnitron  
                          Started by strategist007, Yesterday, 07:51 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post strategist007  
                          Started by StockTrader88, 03-06-2021, 08:58 AM
                          44 responses
                          3,982 views
                          3 likes
                          Last Post jhudas88  
                          Started by rbeckmann05, Yesterday, 06:48 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post rbeckmann05  
                          Working...
                          X