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

Is reverse with limit orders possible?

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

    Is reverse with limit orders possible?

    Hello,

    1. When we use EnterLong, at that time if we have short position then strategy closing short position first and then going long or vise versa (something like reverse position except order's quantity may different).

    Can i do same thing with limit orders? I think when we use EnterLongLimit and if we have short position at that time, strategy don't touch current position and manage new order recording to it's order management properties.

    2. Related to my first question... I have a strategy using EnterLongLimit/EnterShortLimit orders for go long/short and using ExitLongStopMarket/ExitShortStopMarket for stop loss orders. My stop loss orders working like traling stop and when hit stop loss level, i want to reverse my position in the same bar. For test a strategy i'm using market replay, when i put my strategy on a chart and enable it. I see on historical bars working correctly. After start market replay i see after stop loss hit, my entry limit orders don't send to market.

    My strategy working OnBarClose, i try to change order handling properties all entries/unique entries etc. bar can not solve my problem. Any idea about it?

    UPDATE : I put some print lines to my code and these are from output window exactly same order and all of them printing at the same bar's close;

    * LONG => SHORT (This print from OnBarUpdate method and meaning that we have long position and short conditions met, after that line EnterShortLimit method calling)
    * An Enter() method to submit an entry order at '24.01.2017 11:20:16' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.
    * STOPLOSS EXECUTED (This from OnExecutionUpdate method and meaning executed my stopLossOrder for long position and so now we are flat. After that next OnBarUpdate will call this bar close but this time short conditions can not be met and so short position run away!)

    Thanks,
    Aytac
    Last edited by aytacasan; 02-24-2017, 08:45 PM.

    #2
    Hello,

    Thank you for the post.

    For the first item, yes you can reverse the position with limit orders as well, you would just call the opposite directions order method. Please see the following example:

    Code:
    if(Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Short)
    	EnterLongLimit(Close[0] - 1 * TickSize);
    if(Position.MarketPosition == MarketPosition.Long)
    	EnterShortLimit(Close[0] + 1 * TickSize);
    Regarding the second item, if you are trying to reverse the position it may be easier to use logic instead of using an Exit. For example, if you are already performing some logic to the trail, potentially you could add logic to check if the price crosses your calculated stop price and if so call the opposite Entry order instead of an exit. This would both close the position and enter in the opposite direction like the above example. You may need to review your entry logic also if you make this change.

    The error you are getting is helpful to know what is happening:
    An Enter() method to submit an entry order at '24.01.2017 11:20:16' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for a detailed explanation.

    You can locate the reasons this error is displayed on the following page: http://ninjatrader.com/support/helpG...d_approach.htm

    Depending on the logic of your script, this is likely the reason the logic is currently not working as expected.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse,

      Thanks for your response. So NT doing auto. close current position if we try to open opposite side position in any case, it does not matter what is the type of order. It's very good.

      About my other issue, i agree with you if i have a specific logic it will be more easy to develop and giving me more control about close and/or reverse position when develop my strategy. But the problem is i don't like a strategy that not using hard stop loss and when i use hard stop loss plus if i need to open opposite site order at the same bar NT always talk about "Internal Order Handling Rules" and don't process my orders.

      I'm looking that rules and yes rules make sense for me but only for historical (available only OHLCV data) tests but when we talk about market replay tests or real time data trading not make sense for me. I can open/close/reverse my position at the same bar without any problem.

      Could you please help me about that with a small sample, maybe i'm missing something, maybe i'm on wrong way. I can send a screenshot and detailed info about what i want to accomplish. I will be grateful for all your help.

      Regards,
      Aytac
      Last edited by aytacasan; 03-02-2017, 03:25 AM.

      Comment


        #4
        it's not possible to reverse positions with limit orders in NT under managed mode when you have protective orders. The only way is to go under unmanaged mode and code all the logic process which at the beginning might not so easy but with time you'll get it.

        Comment


          #5
          Hello,

          I'm not using unmanaged approach. But i'm using managed approach with "Advanced Order Handling". Even so, i have to use unmanaged approach for enough flexibility and solve my problems?

          Thanks,
          Aytac
          Last edited by aytacasan; 03-02-2017, 04:47 AM.

          Comment


            #6
            You have to ask support if NT8 advanced order handling allows you to tweak it and getting reverse positions with limit orders while there're protective orders. Still if NT team keep its principles, I'm sure that this is not possible, only under unmanaged approach. This is an old subject without change therefore I decided to code under unmanmaged, cause using limit orders often is vital.

            Comment


              #7
              Hello Jesse,

              Please consider all postings from the post you sent.
              After that could you please tell me what is your opinion about my issue?

              Thanks,
              Aytac

              Comment


                #8
                Hello,

                Thank you for the reply.

                Yes, while using the Managed approach, entering into the opposite direction will reverse the position but you would need to also account for the managed order handling rules to see in which cases orders can be ignored. Depending on the order methods used, this places certain stipulations on how logic can perform in the script. In your case, if you also want to use a stop loss you would run into the internal handling rules if it was still active when the condition to reverse happened. You would likely need to cancel the stoploss and then reverse the position once canceled.

                In my prior example, I had suggested one way to potentially accomplish the task using limit orders, in the case you also want to use a stoploss you would likely need to use the unmanaged approach to achieve that. You could potentially use logic with exit orders but In the case of exit orders, there would also need to be a gap between the calls to the entry and exit as the position would need to update.

                In this case, I would not have a specific sample I could provide that outlines these specific concepts, I could suggest to further review the managed order handling rules and the other documentation surrounding the managed approach to see if your total logic conflicts with any of the rules. If so, you would likely need to review the Unmanaged documentation further.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  I see, thanks for the clarification Jesse.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Skifree, Today, 03:41 AM
                  1 response
                  2 views
                  0 likes
                  Last Post Skifree
                  by Skifree
                   
                  Started by usazencort, Today, 01:16 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post usazencort  
                  Started by kaywai, 09-01-2023, 08:44 PM
                  5 responses
                  603 views
                  0 likes
                  Last Post NinjaTrader_Jason  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  6 responses
                  23 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Pattontje, Yesterday, 02:10 PM
                  2 responses
                  23 views
                  0 likes
                  Last Post Pattontje  
                  Working...
                  X