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

Buy long, reverse to short, reverse again to long

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

    Buy long, reverse to short, reverse again to long

    It doesn't seem like this should be very difficult. So far i'm just trying to get it to work without adding in the indicators or anything. Just a simple framework to start with for backtesting the Eminis. It seems like I should just be able to, for example, buy long at the open of the day, set an ExitLongLimit(1, limit) and EnterShortStop(1, stop), then if the Limit hits, it's done, but if the stop hits it enters a new Limit and Stop following the same rules. I can do it if I just use EnterLong() and EnterShort() with the "if" rules determining what happens. But then I can only use (i think) the close of the bar, and I only have 1 minute data. I want it to exit the trade at exactly the stop price, and enter the next trade at that same price (I can figure slippage/spread separately if need be). When I program the above, it works some days and not others. There are some days were it doesn't even exit the first trade, just holds it until the end of the day. Can anyone provide a quick and simple example of doing this? I'm not on the right computer, but I can post the code I have and the results later if it's helpful.
    Thanks

    #2
    You cannot do it like that. If you want to reverse, simply call EnterShort without ExitLong calls. Calling Exit and an Enter runs the risk of double executions and thus is not allowed in NinjaTrader.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      But I can have a Stop order and Limit order both running right? I tried using EnterShortStopLimit but that only seemed work as a stop. Do I need to use SetProfitTarget and SetStopLoss? But then how do I determine if the exit was at the target or the stop?

      Comment


        #4
        nebeno,

        You can have ExitLongLimit and ExitLongStop running at the same time. You cannot have limit and stop working in opposite market directions though. Reason is because EnterShortLimit/Stop will reverse any long position it sees first. When you have ExitLongLimit with EnterShortStop it does not know if it should reverse or not depending on if that ExitLongLimit hits or not. Instead you should just program the logic to place in one order at a time. Whichever the price is closest to, use that order.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh

          I am trying to implement a stop and reverse strategy and am facing a similar problem. I am using a combination of EnterLongStop, ExitLongStop, EnterShortStop and ExitShortStop. From what I understand, EnterLongStop will first cancel any short position and then enter long because of which the NT Internal Order Handling Rules rejects other orders. This is all during backtesting.

          (1) Is there a lower level API available which provides more fine-grain control and bypasses NT's interpretation of the orders? My strategy is not a true Stop and Reverse, in the sense that the closing order and the reverse order may not happen at the same time in some cases.

          (2) Also is there a better way of dynamically updating stop levels instead of cancelling the existing order and then sending a new order?

          (3) It is also not clear to me how to construct OCO Orders via the Strategy Engine.
          ---------------------
          I also noticed that the sequence in which NT is processing the calls for order handling is not what I would expect.

          I have a EnterShortStop order active. I want to change that to EnterLongStop and first call the CancelOrder on the IOrder returned by EnterShortStop method. I then call the EnterLongStop function. All is happening in a function call made on the OnBarUpdate method (backtesting).
          Note that in Bar 9, I first cancel the short order entry before adding the EnterLongStop order. But NT rejects the LongStop because it has not yet processed the cancel request for the EnterShortStop. NT Trace is in italics.


          12/17/2009 10:41:16 AM Entered internal PlaceOrder() method at 12/17/2009 10:41:16 AM: Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.58 SignalName='' FromEntrySignal=''
          8: Short Entry Order Sell Stop at 73.58envHigh = 73.63; envLow = 73.58; slope = 0.0421428571428493
          9: Cancelling Short Entry Order
          12/17/2009 10:42:17 AM Entered internal PlaceOrder() method at 12/17/2009 10:42:17 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.62 SignalName='' FromEntrySignal=''
          12/17/2009 10:42:17 AM Ignored PlaceOrder() method at 12/17/2009
          10:42:17 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.62 SignalName=Buy' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'
          9: Long Entry Order Buy Stop at 73.62envHigh = 73.62; envLow = 73.57; slope = -0.0128571428571007
          12/17/2009 10:42:17 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Back101' Name='Sell short' State=Working Instrument='CL 02-10' Action=SellShort Limit price=0 Stop price=73.58 Quantity=1 Strategy='RegEnvRangeStopBased' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4f2bb380c8cd450487435f9d376a0a75' Gtd='12/1/2099 12:00:00 AM'
          Last edited by aviat72; 12-18-2009, 03:33 AM.

          Comment


            #6
            To clarify, sending in a Enter() does not cancel orders in the opposite direction. It only closes positions in the opposite direction first.

            1. NT7 will provide lower level control.

            2. Just call Exit() with the new stop price. It will amend your current order.

            3. This is done via your own code. When you receive a filled state in one, send a cancel in the other. For ExitLongLimit()/ExitLongStop(). Once the position is closed by either of them, the other will auto cancel when it can't find a position to close any more.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Thanks Josh.

              Could you get me access to NT7 Beta please... I am turning in circles right now since I need too many features from the new version to be productive. I pinged you at josh.peng at Nt.com also...

              Thanks

              Comment


                #8
                You are already on the list for the next round of betas. Thank you for your patience.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  I have been waiting patiently for a few weeks now .

                  I want to use the slow period to do a lot of new development and NT7 has a lot of architectural changes and features not available in NT6.5 which I do need.

                  So if you can let me download whatever the latest version of the Beta is, it will really help. I could have used this weekend to get things going.

                  I am still pushing my comfort zone with the features which NT has and really do not care about bugs in the system. The features which I can target are important for me.

                  Comment


                    #10
                    Hello,

                    Since you are asking about NT7, I will have someone reply to you on Monday. Thank you for your patience.
                    DenNinjaTrader Customer Service

                    Comment


                      #11
                      Ben:

                      After doing some more research, it is clear that there is very little value for me to develop my stuff based on NT6.5 with NT7 right around the corner. Stuff like bypassing internal order handling, multi-instrument indicators etc. are almost a must have for me. So please do try and get me in the Beta.

                      Comment


                        #12
                        aviat72,

                        You are already in the next beta. There is no point in testing the current beta as the next version is about to roll out shortly. As such I am closing this thread.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by FAQtrader, 04-25-2024, 12:00 PM
                        9 responses
                        148 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by ETFVoyageur, Yesterday, 02:10 AM
                        5 responses
                        51 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by ETFVoyageur, 05-07-2024, 07:05 PM
                        20 responses
                        161 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by Ludwik, Today, 03:52 AM
                        4 responses
                        28 views
                        0 likes
                        Last Post Ludwik
                        by Ludwik
                         
                        Started by DawnTreader, 05-08-2024, 05:58 PM
                        18 responses
                        66 views
                        0 likes
                        Last Post DawnTreader  
                        Working...
                        X