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

Historic to real time trade transitioning

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

    #16
    I still have Wait Until Flat as my start behavior.

    Yes, I'm under the impression that in order to prevent the error and have my strategy shut down from under me that I have to transition the historical order to a real time order. So I'm still doing that for the entries only and not for the targets and stops. And it's fine until one of the profit targets are hit - the framework doesn't put the stops and targets. Just when one of the profit targets are hit does it put the targets and stops, when it should not for historical orders.

    You forgot to either confirm or refute that placing those targets and stop on the trade after the first target is hit is a problem or not.

    Comment


      #17
      Originally posted by traderpards View Post
      You forgot to either confirm or refute that placing those targets and stop on the trade after the first target is hit is a problem or not.
      Thank you for your response, traderpards,

      This should not be something that occurs without your own logic performing such a function.

      I would recommend debugging your script further to determine how these orders are generating their own protective orders.

      Please let me know if you have any questions.

      Comment


        #18
        No Patrick, my script is not to blame. Think about it for a second. Look at the screen shot I sent. The last historical entry is an entry (3). When I first refreshed the chart with the strategy, we got that historical trade and there were no trade flags - the framework knew about them but they were in the background. Then when the first target was hit, the framework "uncovered" them; that is, the framework placed those on the chart from its historical record and turned the historical trades stops into live trade stops. In other words, before the historical trade target was hit, they were in the background and considered historical targets. After that first target was hit, the remaining two targets (and the stop) became live targets. You can see in the screenshot that it's a quantity of 2 on the stop loss associated with two profit targets.

        If it were my strategy, there would be three there. It's that simple. The reason there is only two left is because the framework detected that one of the profit targets were hit and the framework uncovered the others, or exposed them, or did whatever it did to make them live stops and targets that would turn into a live, unwanted trade when hit. There is only one place in my strategy where protective orders are put, and that's in OnBarUpdate() where the trade is triggered and it's always a quantity of two, not three. I do not put a profit target or a stop loss anywhere in my code except in a call made in OnBarUpdate. Besides, that trade is historical - even if I wanted to put a stop loss and a profit target on a historical trade, I'm not sure how you do that, not that I'd want to and I wouldn't think you even can. This is happening within your framework.

        This is a problem in the framework and by now I was hoping you'd admit it instead of trying to dodge it. You say it "should not" happen, but it is - just see the screen shot where I showed you that it's happening. I would recommend you try to reproduce it and see if it can't be fixed.

        I can't help but wonder if the requirement to "transition historical trades into live trades," which I'm doing on the entries and not the targets and stop, wasn't some kludge to try to fix something else. (I wonder that because you already know it's a historical trade in your data structures so why does the user have to do something special? Why don't you guys just do whatever transitioning is necessary?)

        Comment


          #19
          Hello traderpards,

          Thank you for your response.

          I can go through the code and test it out to provide a possible solution. Do you have an updated version you could send me?

          Comment


            #20
            Yeah... You're not going to find a possible solution - I think it needs fixing - but if you want to look anyway...

            I'd send you my base class that's kind of a trade manager I use to easily make strategies but it's pretty big and I know you guys don't like working with something that large. I'll make something similar to what I'm using, test it to make sure it does what I'm claiming, which it will and then I'll send it to you. I may need a couple of days though.
            Last edited by traderpards; 02-09-2017, 10:00 PM.

            Comment


              #21
              Reproduced

              ...and you don't even have to wade through 10,000 lines of code. (It turned out to be not as much of a pain as I thought it would.)

              Steps to reproduce:

              1. Download GC 02-17 data - however much you need for last week.
              2. Unzip the strategy
              3. Connect to Market Replay and go to Jan 23rd, 10:00 pm.
              4. Load the strategy and turn on Chart Trader
              5. At 4:54 am, the morning of Jan 24th, a short trade triggers
              6. Hang tight until 12:02 pm when the first profit target is hit.
              7. Stop the Market Replay as soon after the first profit target is hit and before the 2nd profit target is hit. You don't have much of a gap in there - the 2nd one gets hit quickly. (your screen should look like Screen Shot #1.)
              8. In the control center, Positions tab, Flatten everything or Close.
              9. Reload the strategy - this loads that trade you stopped at as a historical trade. So far, so good - this is what you'd expect for a historical trade.
              10. Run the strategy until the 2nd target is hit.
              11. Observe the trade flags on the screen. (Screen shot #2)
              12. So, what I did since I don't think the third target will get hit naturally is I dragged the third target up halfway up that current bar and let the price action take it out. When the price action does take out that target you'll notice that a live trade is triggered long with no protective orders. (Screen shot #3)

              That to me is a problem... Right?

              Note: So this reproduced it this way. But I'll bet you don't need to wait until the first profit target is hit. It will probably reproduce if you stop the strategy, close the trade after the entry, restart the strategy and then you'll see it put the two flags on the chart for the two orders that are left after the first target is hit.

              The ideal solution would be to make it so transitioning stops and targets works, I would think. (I tried it but I forgot what doing that led to.)
              Attached Files
              Last edited by traderpards; 02-09-2017, 10:01 PM.

              Comment


                #22
                Hello traderpards,

                Thank you for your response.

                I cannot reproduce that behavior, I do see similar entries and exits. However, I do not have the No Gap bars. Can you replicate this without using custom bar types?

                I look forward to your response.

                Comment


                  #23
                  You can reproduce this on any time frame, I would think. I just did it on plain ole stock Range bars (18). The thing to look for historically is it hitting all three targets. Then you run it until it hits the first target, restart the strategy and watch it put the flags on the third target when it hits the second target and then watch it enter a live trade once it hits the third target.

                  The key is step #8, where you must flatten everything or close the current trade on the chart. You need to do that because in a real scenario, you won't have that trade in the background. Somehow that affects how you get the trading flags on the chart which tells you that you are about to launch a trade in the opposite direction, I think. I think that because it didn't reproduce for me when I tried it but then I realized that I didn't delete the active trade when I restarted the strategy after the first target was hit. Once I did that, then presto, it reproduced just like it did with those other bars.

                  The screenshots are for GC 02-17 on Jan 20th. Range 18 bars.
                  Screenshot 1 - Stop the strategy here after the first target is hit and restart and this is about what you get
                  Screenshot 2 - After the second target is hit, you get the flags on the third target.
                  Screenshot 3 - After the third target is hit, it gives you a trade in the opposite direction, which is what you don't want.
                  Attached Files

                  Comment


                    #24
                    Hello traderpards,

                    Thank you for your patience.

                    I wanted to let you know I can in fact reproduce this in multiple testing scenarios. We are investigating further to find the cause of this and I will update you here when I have details.

                    Comment


                      #25
                      I think this is fixed. I didn't see anything in the release notes that would indicate that it is fixed because I didn't get an issue number from you and none of the issues listed there sound like this one. But I forgot to turn CL over to the newest contract on Friday and since I'm done for today, I turned it over and there is a trade in progress on my strategy when I refreshed the chart. The first target got filled live and I don't see any stop and target flags generated after the first target was hit, which is what causes the unwanted trade in the opposite direction. So... thanks!!

                      Comment


                        #26
                        Hello traderpards,

                        Thank you for your update on this matter.

                        Please let me know if we may be of further assistance.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Started by stafe, 04-15-2024, 08:34 PM
                        7 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by merzo, 06-25-2023, 02:19 AM
                        10 responses
                        823 views
                        1 like
                        Last Post NinjaTrader_ChristopherJ  
                        Started by frankthearm, Today, 09:08 AM
                        5 responses
                        21 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by jeronymite, 04-12-2024, 04:26 PM
                        3 responses
                        43 views
                        0 likes
                        Last Post jeronymite  
                        Working...
                        X