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

Close[1] acts on wrong range bar

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

    Close[1] acts on wrong range bar

    I am having problems with commands such as Close[1], Low[1] etc acting on the wrong range bar.

    This is the simple strategy that I am using to test the automated trading:

    Code:
    protected override void OnBarUpdate()
            {
                
                if (Position.MarketPosition == MarketPosition.Flat )
                    {
                    if (Close[1] > Open[1] )
                    {
                        EnterLongLimit(100, GetCurrentAsk(),"");
                        SetProfitTarget(CalculationMode.Ticks, 30);
                        SetStopLoss(CalculationMode.Ticks,30);
    
                    }
    }
    }
    CalculateOnBarClose is set to false

    The instrument is QID, an ETF. I am using range bars and testing using the simulated data feed.

    The problem is that Close[1] and Open[1] is being calculated for the bar two bars away rather than the bar directly before the current bar, which is being formed.

    This is placing the orders one bar late.

    For example:

    Bar 1 has Close > Open
    Bar 2 has Close > Open

    The limit order is placed in bar 3 and not bar 2

    I would expect the limit order to be placed in bar 2.

    I think this is also happening on live data from IB, however I would have to confirm this on Monday when the markets re-open.

    Any help/advice appreciated.

    Thanks
    Chris

    #2
    You will have to add some print statements and debug your strategy to see why the condition is NOT true on the bar for which you expect. If you are running calculate on bar close set to true, then for sure this is expected behaviour.
    RayNinjaTrader Customer Service

    Comment


      #3
      Hi Ray

      Thanks for the quick reply.

      There is nothing to debug as I published all the code in the strategy in the post above.

      I have set Calculate on bar close to false, as indicated in the post. If set to true, then yes tis wpould indeed be expected behaviour.

      Why is Close[1] being interpreted wrongly?

      Comment


        #4
        You should add Print(Time[0]) in various locations in your code to see when your condition is triggering. I guarantee you that Close[1] is not being interpreted incorrectly. Make sure that when you run your strategy, the Calculate on bar close parameter is set to false in the strategy dialog window and not just having it set programatically in your code, if you did do that.
        RayNinjaTrader Customer Service

        Comment


          #5
          Hi Ray

          Using that Print statement resolved the problem.

          The limit order is being placed at the top, or bottom of bar 2 (which is the correct bar), however the Buy text is being displayed on the next bar (bar 3) on the chart so it seems that the order is being placed on the wrong bar, when in fact its not.

          Thanks for your help

          Comment


            #6
            Executions generally will have a time stamp that falls on the bar after the order is placed. In any case, executions are plotted accurately based on time.
            RayNinjaTrader Customer Service

            Comment


              #7
              Order Display Bug with Range Charts

              Hi, further on this "incorrect bar" issue, take a look at the two attached images. One is from realtime, which shows a fill and a subsequent close in the middle of nowhere on the chart... completely wrong.
              After hitting the F5 button to reload the strategy, and thus to use historical data, the fill displays at the correct time. ( It is the one on the right of the chart filling at 9367. ) Note that is the same price as the erroneous fill in the first pic.
              I have watched this happen in front of me, and I can tell you that the fill happens at the time and price it is supposed to. HOWEVER, the time recorded for the fill is incorrect, and so it displays on the wrong Range bar.
              There is no way anything in my Strategy can be making this happen, as the code at question is the internal Ninja order display logic.
              My CalculateOnClose is set to true.
              I am using the latest build.
              Cheers,
              saltminer
              Attached Files

              Comment


                #8
                Hello,


                Realtime behavior is always completely different than historical behavior. Looking at a screenshot will not suffice. You will need to check TraceOrder logs in real-time, execution and orders tabs. You will need to match the timestamp of the trade with the bar.
                DenNinjaTrader Customer Service

                Comment


                  #9
                  Looking at the logs it seems that times recorded for trades in realtime Range bars are wrong. Upon triggering an order and filling, the times recorded for them are EARLIER than "right now".
                  The logs are wrong, and the chart display is thus wrong too.

                  To be clear;
                  1) conditions for my strategy come into alignment and an Entry is made. This is at a bar close while ComputeOnClose=true;
                  2) I draw something on the chart at bar[0] to highlight this fact.
                  3) Order fills at correct price
                  4) Time of the order in the logs and display on Chart is too early... sometimes a few bars sometimes many bars prior - impossibly early for the strategy to have triggered, and displaying where a fill at that price would also have been impossible.

                  Comment


                    #10
                    saltminer,

                    We have never heard any other report like this. I suggest you do a complete uninstall and reinstall of both NinjaTrader and .NET 2.0.

                    1. Backup your important files like Indicators and Strategies
                    2. Uninstall NinjaTrader
                    3. Delete \My Documents\NinjaTrader 6.5 BEWARE YOU WILL LOSE ALL DATA, ALL WORKSPACES, ALL NINJASCRIPT etc.
                    4. Uninstall .NET 2.0
                    5. Clear browser cache
                    6. Reinstall .NET 2.0
                    7. Reinstall NinjaTrader
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Realtime fills displaying incorrectly.... further info

                      Regarding post #7 below, I have additional information.
                      Everything displays as it should when using market orders within the strategy, e.g. EnterLong(...)
                      However when using a limit order, EnterLongLimit(...) without changing anything else about the strategy or the Ninja installation, then suddenly back again came the displaced orders display.
                      Orders are being displayed on the chart at the correct price but on the wrong bar. (too early)

                      saltminer

                      Comment


                        #12
                        saltminer,

                        You need to check the timestamps of those bars. If all of those range bars have the exact same time stamp then this is expected to happen. It will plot on the first bar of the given timestamp. Otherwise please proceed as in post #10 and also please try resyncing your PC clock.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by ZeroKuhl, Today, 04:31 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post ZeroKuhl  
                        Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
                        54 responses
                        5,336 views
                        0 likes
                        Last Post Gaterz
                        by Gaterz
                         
                        Started by ETFVoyageur, 05-07-2024, 07:05 PM
                        11 responses
                        74 views
                        0 likes
                        Last Post -=Edge=-  
                        Started by _Zero_, 04-10-2020, 03:21 PM
                        145 responses
                        7,900 views
                        6 likes
                        Last Post johng2
                        by johng2
                         
                        Started by TheTradingMantis, 01-19-2023, 02:05 AM
                        43 responses
                        921 views
                        0 likes
                        Last Post jmagaia
                        by jmagaia
                         
                        Working...
                        X