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

Point and Figure - OnPriceChange - often will not enter until bar close

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

    Point and Figure - OnPriceChange - often will not enter until bar close

    I have a strategy set to calculate OnPriceChange, and using GetCurrentBid(0) to enter when passing Close[2] plus 2.5 points. Sometimes it will enter before the current bar closes, but often it will wait until the close of the bar before making the entry. The price isn't jumping at the last moment before close. In one example, I can watch the price moving in the range 2 to 3 points above the passing point for entry and then higher, and only entering after bar close. In this example, the entry was made 9 points above where I intended to enter.

    Is there a better way to make accurate entries on this bar type?

    #2
    Hello ronaldgreene828,

    Thank you for your post.

    So I may best try to reproduce on my end, what are the settings for your Point and Figure chart? What instrument did this occur on?

    If you could provide a code snippet of your entry logic, that would be helpful as well.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      In another test, I set the entry for GetCurrentBid when passing Close(2) plus no additional points. It makes more entries this way before bar close. For one entry, the price rose above Close[2] moving around above for about a minute after passing. While the price is moving around above, the bar doesn't follow the price. Then after a minute, the bar extended 8 points above Close[2] and made the entry. After another minute the bar then closed 4 points higher.

      Comment


        #4
        Here is the set for entry. The set is duplicated for different slope values. I attached a screenshot for point and figure settings.

        if ((State == State.Realtime)
        && (LongEntry == false)
        && (ShortEntry == false)
        && (TurnOffStrategy == false)
        && (SMA1[1] > SMA1[2])
        && (SMA1[1] <= SMA1[2] + 0.5)
        && (Open[1] - Close[1] >= 0.75)
        && (Close[2] - Open[2] >= 1)
        && (Close[1] > Open[2])
        && (GetCurrentBid(0) > Close[2] + PassingDistanceForEntry)
        && (Close[2] < SMA1[1] + Slope0p5distanceFromSMA1)
        && (Close[2] > SMA1[2])
        && (LongExitPrevBarClosingPrice != Close[1]))
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), @"Long 1");
        LongEntry = true;
        ShortEntry = false;
        LongEntryPrice = GetCurrentBid(0);
        HighSinceEntry = GetCurrentBid(0);
        Draw.TextFixed(this, @"SMA20and8 Fixed text_103", @" L103", TextPosition.TopLeft);
        }

        Click image for larger version

Name:	Screenshot (148).png
Views:	213
Size:	205.4 KB
ID:	1119666
        Attached Files

        Comment


          #5
          It seems like the bar updates once a minute and no entries can be made between bar updates.

          Comment


            #6
            I apologize, my brain is kicking in. I'm checking the default settings and it looks like I can set it for ticks instead of minutes so I'll see if that will work.

            Comment


              #7
              Hello ronaldgreene828,

              Thank you for your note.

              From what I can see of your code, it should enter as soon as those conditions are true. You're using a market order to enter so we'd expect to see some slippage from the price that it's submitted at if the market is moving quickly, but what I'd recommend would be to use trace orders and prints so you can a) see exactly when the order is submitted and b) check the values of your entry conditions so you can tell if an order should have been entered at a certain point.

              The first thing I would recommend would be to turn on the Order Trace function:

              Strategy Builder > Default Properties > More Properties > Trace Orders, or:

              if (State == State.SetDefaults)
              {
              TraceOrders = true;
              }

              Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

              Here is a link to our help guide that goes into more detail on tracing orders:

              https://ninjatrader.com/support/help...aceorders2.htm

              Trace orders alone may not give you the full picture of whether or not a trade should have been entered at a given point on a given bar, so adding prints to your strategy that will show in the NinjaScript Output window, with information on what the variables you're using for your conditions are on a particular bar, can be helpful.

              This forum post goes into great detail on how to use prints to help figure out where issues may stem from — this should get you going in the correct direction. You can even add these using the Strategy Builder.

              https://ninjatrader.com/support/foru...ns-not-working

              If you run into issues like we saw here, the above information will allow you to print out all values used in the condition in question that may be evaluating differently. With the printout information you can assess when the strategy is actually calculating it should enter. If you're confused as to what you're seeing, please feel free to post what you're seeing from the prints.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Thanks for the details, I'll be able to clearly see what's happening.

                Comment


                  #9
                  Hello ronaldgreene828,

                  Thank you for your reply.

                  Would you be able to supply a reduced version of the script so I may test on my end? Any code unnecessary to reproduce (plots, drawing objects, etc) should be omitted. Please export the script from Tools > Export > NinjaScript Add-On. Do not check the box to export as a compiled assembly or I will not be able to review the code. Please attach the resulting .zip file to your reply.

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    I'm using historical data for testing. I read something that states only barclose is calculated in this case. Would this be why the bar does not update per tick?

                    Comment


                      #11
                      Hello ronaldgreene828,

                      Thank you for your reply.

                      That would be accurate.

                      You should expect that a strategy running real-time (live brokerage account, live market simulation, Market Replay etc...) will produce different results than the performance results generated during a backtest using historical data. This difference may be more easily seen on certain Bars types (e.g. Point and Figure) than others due to their inherent nature in bar formation.

                      During a backtest you can select conservative or liberal fill algorithms which will produce different results. Fills are determined based on 4 data points, OHLC of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

                      Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

                      Also, here is a link to the differences on real-time vs backtest (historical).
                      http://ninjatrader.com/support/helpG...ime_vs_bac.htm

                      Adding intra-bar granularity can help with this.

                      Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades by supplying the correct price at the correct time for the order to fill with.

                      In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add this secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (TickReplay).

                      Here is a link to our forums that goes into depth on using Order Fill Resolution and Tick Replay to ensure your backtests are as close to real time results as possible:

                      https://ninjatrader.com/support/foru...mance?t=102504

                      High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically.

                      Please let us know if we may be of further assistance to you.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks very much for the information. I was using the playback connection because I can see what's happening during testing. Now I see the value of using real time data on a simulated account.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by frankthearm, Today, 09:08 AM
                        7 responses
                        27 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by NRITV, Today, 01:15 PM
                        1 response
                        5 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by maybeimnotrader, Yesterday, 05:46 PM
                        5 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by quantismo, Yesterday, 05:13 PM
                        2 responses
                        16 views
                        0 likes
                        Last Post quantismo  
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        33 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X