Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades exiting at wrong prices - bug?

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

    Trades exiting at wrong prices - bug?

    Please see the screenshot below:
    http://prntscr.com/gt00u1

    I have been adding MTF handling and changed my update to OnEachTick. Other than that, I'm not sure what could be causing trades to be closed at impossible prices (based on the time that it says the trade was exited).

    This doesn't happen every time, but it happens quite often in backtesting now.
    Does anyone know what might be causing this exactly?


    Also, a small MTF-related issue: If I am backtesting on the 5 minute chart, and in my code I add 15 minute and 60 minute Data Series, would I be able to reference the 5 minute with index 0, and 15m with index 1? The reason I ask is that I'm getting an out of bounds error on my last index, so I'm not sure if the time frame selected in the strategy analyzer defaults to index 0. Thanks!
    Last edited by gredenko; 10-04-2017, 12:05 AM.

    #2
    Hello gredenko,

    Thank you for your post.

    On the first item concerning the historical fill, is the time of the fill matching the secondary (60 minute) time frame's close?
    I suspect as we are looking at historical fills, the order is filling on one of the additional time frames and in turn is filling at a price that was achieved within that additional time frame's bar. As the bar would plot it's close at that time, it would plot it's Open, High, Low, and Close at that time as well thus resulting in the fill well outside the bounds of the primary time frame's bar.

    On the second item concerning the index reference, where are you seeing this error? Can you detail the full error? If you understand where you are accessing the index that violates a rule and thus generates the error can you provide that detail?

    I look forward to your response.

    Comment


      #3
      Hey Patrick, yes that does sound like what might be happening.

      Here is another screenshot, where it also seems like the stop loss is being hit before the trade is even opened. http://prntscr.com/gt8rxg

      Is this fixable while using the OnEachTick setting and multiple time frames? If so, what should I do?

      As for the index issue, here is what I had in code, though I can't seem to get the error again..

      //added 4 data series
      AddDataSeries(BarsPeriodType.Minute, 15);
      AddDataSeries(BarsPeriodType.Minute, 30);
      AddDataSeries(BarsPeriodType.Minute, 60);
      AddDataSeries(BarsPeriodType.Minute, 240);

      //getMACD is my own function used to simplify the MACD call since I make it often
      double macd_15 = getMACD(1)[0];
      double macd_30 = getMACD(2)[0];
      double macd_60 = getMACD(3)[0];
      double macd_240 = getMACD(4)[0];

      Earlier I had included a 10 minute dataseries above 15, and was calling 15, 30, 60, 240 with indeces 2, 3, 4, 5, which seemed to give an error, but again I can't seem to replicate it so perhaps I was wrong.

      But my question now is, if I am using the 5-minute period in the settings, and not adding the 5 minute data in my code, will accessing the 5-minute period be done with index 0, 15 with 1, and so on? Or do I have to add the 5-minute period in my code to access it with index 0?

      Comment


        #4
        Hello gredenko,

        Thank you for your response.

        For the screenshot it would appear the Trade Performance is missing the initial entry but is seeing the initial exit. If you increase the DaysToLoad when your right click in the chart and select Data Series, do you continue to see the same behavior?

        For are correct on how to access the indexes:
        • Index 0 is the primary series (the series of the chart for example).
        • Index 1 is the secondary series (the first 'AddDataSeries' call in your code)
        • Index 2 is the next series added via 'AddDataSeries'.
        • etc.

        I look forward to your response.

        Comment


          #5
          I'm not seeing Data Series when I right click my chart. Are you talking about within Strategy Analyzer? I am not using any other charts at this time to display data.

          Also, it can happen midway or late in my selected time frame, meaning there are correct trades being taken prior to it. I'm not sure if that necessarily means enough data is loaded prior to the erroneous trades, but I am just putting that out there.

          Also, not sure if it's relevant, but the time frame I'm looking at right now is Dec 23 2015 to Jan 20 2016. I use up to 50 previous bars on 240 minute/4 hour time frame at the most when I look back in my code. So there are several days where trades are not taken (in Dec) due to not having enough bars to look back at, but from Jan 6 my trades start getting taken. Jan 8 is the first time I see this bug.

          I hope that helps.

          Comment


            #6
            Hello gredenko,

            Thank you for your response.

            So you are testing in the Strategy Analyzer.

            Please test a new database with the instructions below.
            • Shutdown NinjaTrader and Go to the Start Menu
            • Select My Documents--> NinjaTrader 8--> DB
            • Please delete the 'cache' folder
            • Right click on NinjaTrader.SDF and select "Rename." *Name it "OLDNinjaTrader.SDF."
            • Then restart the software and NinjaTrader will create a fresh database file to use

            You can return to your prior database by renaming the new one and naming your database back to "NinjaTrader.SDF".

            Please let me know if the Strategy Analyzer is still showing these irregularities after testing a new database.

            Comment


              #7
              Yeah I am using Strategy Analyzer and the ScriptEditor only.

              I have followed those instructions, but I still have some of these trades happening:
              http://prntscr.com/gtcxp1

              I did not restore my original .sdf file yet.

              --------------------------------------------------------------------------------
              As for the time frame and 0-based index question, I'm still having an issue. As I mentioned before, I am backtesting with the 5 minute period, while adding 15 minute and higher time frames within my code. I noticed a discrepancy and I logged some price values in my code.

              When calling Time[0] and Time[1], I get time in 15 minute intervals even while backtesting with the 5 min. period. (2:00:00 AM, 2:15:00 AM). The prices of open/close that I call with Open[0] and Close[0] are also wrong in terms of the chart for the 5m candles at those times (they correctly match the 15m candles instead).

              In my code, I add the 15 minute bars with AddDataSeries as below, and so those should be index 1 (and other time frames 2, 3, 4), correct? I have not added 5min anywhere.

              } else if (State == State.Configure) {
              AddDataSeries(BarsPeriodType.Minute, 15);
              AddDataSeries(BarsPeriodType.Minute, 30);
              AddDataSeries(BarsPeriodType.Minute, 60);
              AddDataSeries(BarsPeriodType.Minute, 240);
              }

              Why is my log printing the 15m values, if the 5m time frame is selected, and shouldn't that be index 0? I'm really confused, about whether or not I need to add the 5m data series in my code and then reference it with [0], and whether calling High[0] instead of High[0][0] is allowed with MTF.

              I hope that makes sense, let me know if you need more information.
              Last edited by gredenko; 10-04-2017, 10:57 PM.

              Comment


                #8
                Hello gredenko,

                Thank you for your response.

                May we test the strategy that you are backtesting and the multi-timeframe strategy you use as well?

                You can export your strategy by going to Tools > Export > NinjaScript Add On > Add > select your strategy > OK > Export > name the file 'NTsupport' > Save.

                The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

                If you prefer you can send the file over to platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and a reference to this thread in the body of the email.

                I look forward to assisting you further.

                Comment


                  #9
                  I am not entirely sure what fixed it but I did end up fixing this issue. Thank you for the help!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by caacapital, Today, 10:10 AM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_ShawnB  
                  Started by DiverG20, Today, 10:23 AM
                  0 responses
                  17 views
                  0 likes
                  Last Post DiverG20  
                  Started by SuneSorgenfrei, Today, 09:29 AM
                  0 responses
                  15 views
                  0 likes
                  Last Post SuneSorgenfrei  
                  Started by dodoei, Today, 07:24 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post dodoei
                  by dodoei
                   
                  Started by thecashguys, Today, 06:13 AM
                  0 responses
                  12 views
                  0 likes
                  Last Post thecashguys  
                  Working...
                  X