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

Strategy Analyzer places orders at beginning of candle?

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

    Strategy Analyzer places orders at beginning of candle?

    Regardless of what I have programmed, the strategy analyzer places both BUY and SELL orders at the beginning of the Candle that I am referencing. This is devastating to a strategy test. It's as if knowing the future, the strategy then makes better trades into the past to win more often. Clearly, we cannot do this in real life...

    Please explain why this is, and how I can make it stop!

    Screenshot attached. This is by far one of the worst bugs I've seen in the Strategy Tester.

    Here is my order code, which shows the Print statements that you see in the screenshot. If my code is wrong, please correct me. If not, please tell me how to get around this issue so I can have a real Strategy Analyzer test. I paid $1k for this software, and this is a huge huge issue. The last trade in the screenshot should have been a 6 point loss, but instead it was a 13 point win!


    ** I have downloaded as much historical data as I can. Tick, Minute, Day, etc, covering more than the entire period for the test window, so it definitely is not for a lack of data to process.

    ** Edit: I changed the of name of my function to myPlaceOrder after looking into the Trace options for orders and seeing that you all use that as an internal function. It did not change the order placement, and also setting TraceOrders to true does nothing. I'm guessing I need to restart all of NT for that option to take effect? Although the documentation does not note this to be the case...


    Code:
    		private void myPlaceOrder(string orderType, string orderName) {
    			if (orderType == "short" || orderType == "shortStop" ) {
    				if ( setSLfromLVMA ) { 
    					stopLossInTicks = Math.Abs(Close[0]-l_vma.Value[0]); // Math.Abs(stopLoss-Close[0]);
    				} else {
    					stopLossInTicks = SL; // Math.Abs(stopLoss-Close[0]);
    				}
    				stopLoss = Close[0]+stopLossInTicks;//High[HighestBar(High, 10)]+3;
    				myStopLoss1.StartAnchor.Price = stopLoss;
    				entryPrice = Close[0];
    
    				EnterShort(orderName);
    
    				Print(Time[0] + " - [ " + Name + " ] - " + "SELL: Entering market -- Close[0]: " + Close[0] + " StopLoss: " + stopLoss + " StopLossInTicks: " + stopLossInTicks + " TakeProfit1: " + takeProfit1);
    			} else if (orderType == "long" || orderType == "longStop" ) {
    				if ( setSLfromLVMA ) { 
    					stopLossInTicks = Math.Abs(Close[0]-l_vma.Value[0]); // Math.Abs(stopLoss-Close[0]);
    				} else {
    					stopLossInTicks = SL; // Math.Abs(stopLoss-Close[0]);
    				}
    				stopLoss = Close[0]-stopLossInTicks;
    				myStopLoss1.StartAnchor.Price = stopLoss;
    				entryPrice = Close[0];
    
    				EnterLong(orderName);
    
    				Print(Time[0] + " - [ " + Name + " ] - " + "BUY: Entering market -- Close[0]: " + Close[0] + " StopLoss: " + stopLoss + " StopLossInTicks: " + stopLossInTicks + " TakeProfit1: " + takeProfit1);
    			}
    			breakEven = false;
    		}
    Attached Files
    Last edited by timwelch; 01-30-2018, 08:59 AM. Reason: adding info

    #2
    Hello timwelch,

    Thanks for your post and welcome to the NinjaTrader forums!

    Strategies run on historical data will operate on the basis of Calculate.OnBarClose. The strategy is executed at the end of each bar and if extry/exit conditions exist the orders are placed and executed on the next bar.

    Please review the helpguide link for further information: https://ninjatrader.com/support/help...ime_vs_bac.htm

    Can you provide further information concerning your strategy in terms of the methods used for your actual stop and take profit?

    What calculate mode are you using for your strategy?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Did you look at the screenshot I posted? Not trying to sound rude at all, but the very last two trades show the issue very clearly without me having to reveal to you the inner workings of my strategy. IF what you are saying is true, then the orders for both open and exiting the trade would not have happened at the beginning of the bar, but at the END of it. But that is not what is happening here. Price moved up in the last trade, which triggered my strategy to make a Long, and instead of placing the order where it triggered, it ended up placing it at the beginning of that Bar. And the same happened for closing the trade.


      EDIT: To answer your question, I have always had Calculate.OnEachTick set in all of my strategies. I actually recall reading this before, and that is acceptable in a back test, if the trades were actually placed at the end of a bar. What is not acceptable is placing trades at the beginning of the bar that was the trigger point. :-) I can add more logging to show / prove that the bar number was the same as the one that was triggered, so you can see it's actually going back in time to the beginning of the bar to make the trade.
      Last edited by timwelch; 01-30-2018, 09:59 AM.

      Comment


        #4
        Further disclosure:

        My strategy does not wait for the beginning of a bar to either place a trade or to exit a trade. I also do not use a stopLoss order when I place a trade. I check the price as it moves, (which is why the Calculate.OnEveryTick setting is there) to see when to get in and when to get out of a trade.

        Comment


          #5
          Here's another screenshot with CurrentBar integer printed along with the trade information. Reading this backward, from the last new bar on the screen, this clearly shows to me that the SA is going backwards in time to place the trade at the beginning of the "current" bar, rather than waiting to the end of it as you suggest.
          Attached Files

          Comment


            #6
            It appears as though this behavior only exhibits itself when you do not specifically call IsFirstTickOfBar as a requirement to placing a trade. IF I call that, ensuring that I only begin the trade at the beginning of a new bar, then the trade works fine, or at least as expected. It will put me into the trade exactly there, at the beginning of the bar. And it will adhere, as well as it can, to taking me out where i ask it to as well.

            But, when I try to get into a trade, without using IsFirstTickOfBar as a requirement, the pattern exhibited is that of 1) It will always place the trade at the beginning of the bar, even if I call EnterLong/Short anywhere inside of the bar, and 2) it will always take me out at the beginning of the bar where I called ExitLong/Short (which is 99% of the time, back in time before the trade was actually bad or rather before I would have exited giving the false impression that there are more profits than in reality). This is definitely not desirable and needs to be looked into further.

            **This only affects the Strategy Analyzer. In real-time, the trades are handled properly and as expected. The issue is that because of this oddity in placing orders, as you can see in the screenshots, it gives a false sense of security that the strategy you're working on is actually successful, when in reality, there would be much devastation of loss.

            For now, I'm going to move to using IsFirstTickOfBar and adjust my strategy to deal with that, since I can at least guarantee that I will be placed into the trade where I ask, and not somewhere in the past (which also wreaks havoc on StopLoss placement, BTW. See the output of the screenshot, where the stopLoss ends up being ABOVE the actual order. This is insanity!)

            Please fix ASAP!

            Comment


              #7
              Hello timwelch,

              Thank you for your patience.

              I recommend you review the following items on Historical Fills.

              First refer to the "Discrepancies: Real-Time vs Backtest" information at the following link: https://ninjatrader.com/support/help...ime_vs_bac.htm

              Once you understand the discrepancies I recommend you look into the Historical Fill Logic at the following link: https://ninjatrader.com/support/help...fill_logic.htm

              You can then take advantage of the Historical Fill Processing options detailed at the following link: https://ninjatrader.com/support/help...ical_fill_.htm

              With these items in mind please then provide the following information:
              • What Fill Processing options are you using?
              • Do the fills coincide with the Fill Processing you are using?
              • Do you have any question on Historical Fill Logic?
              • Do you understand the difference between historical and real-time processing for strategies? If not, what questions do you have?


              I look forward to your response.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by poplagelu, Today, 05:00 AM
              0 responses
              3 views
              0 likes
              Last Post poplagelu  
              Started by fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,407 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              98 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              8 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              160 views
              0 likes
              Last Post loganjarosz123  
              Working...
              X