Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Point and Figure and NinjaScript

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

    Point and Figure and NinjaScript

    Instead of adding to another PnF thread I start a new one for scripting with PnF chart styles. I would like to build a strategy based on the PnF chart style. The question I have is how can I address the boxes (bars) of the PnF? What extra methods and parameters are there for us?

    I found:
    AddPointAndFigure() with their parameters but no other methods.

    I would like to know things like:
    Close[0].isUpBox() // return if current box is a 'X'
    Close[1].hasBox() // return if there is a box above the current box
    Close[-1].hasbox() // return if there is a box beneath the current box
    Close[0].Column[1].hasBox() // return if the previous column of boxes has a box on the same row (value height) as the current box

    Why, because I would like to feel around the current box to know if a pattern is in place.

    The question is how to know what kind of box there is and how to navigate through the previous boxes? Am a professional programmer so no need for a detailed explanation.

    Thanks,
    Johan

    #2
    Johan,

    It works in the exact same session as say a minute bar. A column is considered a bar. Close[0] for the currently building bar. You cannot go [-1]. If you want previous columns, use [1] etc.

    Relevant information is the highest point and lowest point of the column. You can do the math inbetween based on your box size setting to know how many X's or O's.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your quick response Josh!

      It sounds all very logical!

      Still one question, is there another way to know if it is an up bar or a down bar ("0" or "X") then checking the high and the low? Because what if you have a 1 box reversal and the new column is one box high, checking the high and low won't give you the answer. Just give you this example to know if there is an easier way to check, my own strategy will only use a 3 box reversal so that isn't the problem.

      Thanks,

      Johan

      Comment


        #4
        Not sure I follow. You will have to check the prices themself to know if its an X or an O there is no way around that.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Okey, thanks!

          Comment


            #6
            BTW I have seen that the volume indicated in the small databox for PnF charts is not correct in some cases.

            I have 1 Min PnF charts 24/7 for ES and TF using Closing price. The TF charts show volume in single or double digits for bars with box size 2 and reversal of 3 boxes. For ES it is showing more reasonable volume though I am not sure if it is correct.

            Comment


              #7
              Problem 1:
              On Friday I had finished a basic strategy but it is not working right. The problem is that the buy and sell stops aren't triggered by Ninjatrader on the right way....
              It seems that when a stop is placed, e.g. buy stop and the high of the current PnF bar is higher than the buy stop, it get immediately filled at the high of the bar, while such high quotes haven't passed yet through the OnBarUpdate() event. The same happens with the sell stop. I have to test it some better, but it seems there are some problems with it. At this moment I am testing it by back testing through the strategy analyzer.

              Problem 2:
              But an other point I found out is that the CurrentBar spits a lot of rubbish information! Seems to be a bug?

              protectedoverridevoid OnBarUpdate()
              {
              Print(CurrentBar.ToString() +
              "_____" +Close[0].ToString()+ "_____"+ Time[0].ToString());
              }

              This gave the following outcome (do you see that Currentbar has multiple different values):

              20_____1177,5_____6-4-2010 14:33:00
              513_____1177,75_____6-4-2010 14:33:00
              514_____1177,75_____6-4-2010 14:34:00
              515_____1178_____6-4-2010 14:35:00
              516_____1178_____6-4-2010 14:36:00
              517_____1177,75_____6-4-2010 14:37:00
              518_____1178,25_____6-4-2010 14:38:00
              519_____1178,25_____6-4-2010 14:39:00
              520_____1178,25_____6-4-2010 14:40:00
              521_____1178_____6-4-2010 14:41:00
              522_____1178_____6-4-2010 14:42:00
              523_____1178_____6-4-2010 14:43:00
              524_____1178,25_____6-4-2010 14:44:00
              21_____1178,75_____6-4-2010 14:45:00
              525_____1178,5_____6-4-2010 14:45:00
              526_____1178,75_____6-4-2010 14:46:00
              527_____1178,75_____6-4-2010 14:47:00
              528_____1178,5_____6-4-2010 14:48:00
              529_____1178,5_____6-4-2010 14:49:00
              530_____1178,5_____6-4-2010 14:50:00
              531_____1178,5_____6-4-2010 14:51:00
              532_____1178_____6-4-2010 14:52:00
              533_____1178_____6-4-2010 14:53:00
              534_____1178_____6-4-2010 14:54:00
              535_____1178_____6-4-2010 14:55:00
              536_____1178_____6-4-2010 14:56:00
              537_____1178_____6-4-2010 14:57:00
              538_____1178_____6-4-2010 14:58:00
              539_____1178,25_____6-4-2010 14:59:00
              540_____1178_____6-4-2010 15:00:00
              22_____1177,5_____6-4-2010 15:01:00
              541_____1177,75_____6-4-2010 15:01:00
              542_____1177,5_____6-4-2010 15:02:00
              543_____1177,5_____6-4-2010 15:03:00
              544_____1177,5_____6-4-2010 15:04:00
              545_____1177,75_____6-4-2010 15:05:00
              546_____1177,75_____6-4-2010 15:06:00
              547_____1177,75_____6-4-2010 15:07:00
              548_____1178_____6-4-2010 15:08:00
              549_____1178_____6-4-2010 15:09:00
              550_____1178_____6-4-2010 15:10:00
              551_____1178,25_____6-4-2010 15:11:00
              552_____1178,5_____6-4-2010 15:12:00
              553_____1178,75_____6-4-2010 15:13:00
              554_____1178,75_____6-4-2010 15:14:00
              555_____1178,75_____6-4-2010 15:15:00
              556_____1179_____6-4-2010 15:16:00
              557_____1179_____6-4-2010 15:17:00
              558_____1179_____6-4-2010 15:18:00
              559_____1179_____6-4-2010 15:19:00
              560_____1179_____6-4-2010 15:20:00
              561_____1179_____6-4-2010 15:21:00
              562_____1179,25_____6-4-2010 15:22:00
              563_____1179,25_____6-4-2010 15:23:00
              564_____1179_____6-4-2010 15:24:00
              565_____1179_____6-4-2010 15:25:00
              566_____1179_____6-4-2010 15:26:00
              567_____1178,75_____6-4-2010 15:27:00
              568_____1178,75_____6-4-2010 15:28:00
              569_____1178,75_____6-4-2010 15:29:00
              23_____1179,75_____6-4-2010 15:30:00
              570_____1179,25_____6-4-2010 15:30:00
              24_____1179_____6-4-2010 15:31:00
              571_____1179,5_____6-4-2010 15:31:00
              572_____1179_____6-4-2010 15:32:00
              573_____1179_____6-4-2010 15:33:00
              574_____1178,75_____6-4-2010 15:34:00
              575_____1179_____6-4-2010 15:35:00
              576_____1179,5_____6-4-2010 15:36:00
              577_____1179,5_____6-4-2010 15:37:00
              25_____1180,5_____6-4-2010 15:38:00

              Comment


                #8
                Done some more research en tests.

                With the following code I got the results below:
                Print(CurrentBar.ToString() + "_____" + BarsInProgress.ToString() + "_____" + Close[0].ToString()+ "_____"+ Low[0].ToString()+ "_____"+ High[0].ToString()+ "_____"+ Open[0].ToString()+ "_____"+ Time[0].ToString());


                20_____0_____1177,5_____1177,5_____1180_____1180__ ___6-4-2010 14:33:00
                513_____1_____1177,75_____1177,5_____1178_____1177 ,75_____6-4-2010 14:33:00
                514_____1_____1177,75_____1177,5_____1178,25_____1 177,75_____6-4-2010 14:34:00
                515_____1_____1178_____1177,75_____1178,25_____117 7,75_____6-4-2010 14:35:00
                516_____1_____1178_____1177,75_____1178_____1177,7 5_____6-4-2010 14:36:00
                517_____1_____1177,75_____1177,75_____1178_____117 8_____6-4-2010 14:37:00
                518_____1_____1178,25_____1178_____1178,25_____117 8_____6-4-2010 14:38:00
                519_____1_____1178,25_____1178_____1178,25_____117 8_____6-4-2010 14:39:00
                520_____1_____1178,25_____1177,75_____1178,5_____1 178_____6-4-2010 14:40:00
                521_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:41:00
                522_____1_____1178_____1178_____1178,25_____1178__ ___6-4-2010 14:42:00
                523_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:43:00
                524_____1_____1178,25_____1178_____1178,5_____1178 _____6-4-2010 14:44:00
                21_____0_____1178,75_____1177,75_____1178,75_____1 177,75_____6-4-2010 14:45:00
                525_____1_____1178,5_____1178_____1178,75_____1178 _____6-4-2010 14:45:00
                526_____1_____1178,75_____1178,25_____1178,75_____ 1178,25_____6-4-2010 14:46:00
                527_____1_____1178,75_____1178,5_____1178,75_____1 178,5_____6-4-2010 14:47:00
                528_____1_____1178,5_____1178,5_____1178,75_____11 78,5_____6-4-2010 14:48:00
                529_____1_____1178,5_____1178,25_____1178,75_____1 178,5_____6-4-2010 14:49:00
                530_____1_____1178,5_____1178,5_____1178,75_____11 78,5_____6-4-2010 14:50:00
                531_____1_____1178,5_____1178_____1178,75_____1178 ,5_____6-4-2010 14:51:00
                532_____1_____1178_____1178_____1178,5_____1178,5_ ____6-4-2010 14:52:00
                533_____1_____1178_____1177,75_____1178,25_____117 8,25_____6-4-2010 14:53:00
                534_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:54:00
                535_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:55:00
                536_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:56:00
                537_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 14:57:00
                538_____1_____1178_____1178_____1178,25_____1178__ ___6-4-2010 14:58:00
                539_____1_____1178,25_____1178_____1178,25_____117 8_____6-4-2010 14:59:00
                540_____1_____1178_____1177,75_____1178,25_____117 8_____6-4-2010 15:00:00
                22_____0_____1177,5_____1177,5_____1178,5_____1178 ,5_____6-4-2010 15:01:00
                541_____1_____1177,75_____1177,5_____1178_____1178 _____6-4-2010 15:01:00
                542_____1_____1177,5_____1177,25_____1177,75_____1 177,75_____6-4-2010 15:02:00
                543_____1_____1177,5_____1177,25_____1177,75_____1 177,75_____6-4-2010 15:03:00
                544_____1_____1177,5_____1177,25_____1177,75_____1 177,5_____6-4-2010 15:04:00
                545_____1_____1177,75_____1177,5_____1178_____1177 ,5_____6-4-2010 15:05:00
                546_____1_____1177,75_____1177,5_____1178_____1177 ,75_____6-4-2010 15:06:00
                547_____1_____1177,75_____1177,5_____1178_____1177 ,75_____6-4-2010 15:07:00
                548_____1_____1178_____1177,75_____1178_____1177,7 5_____6-4-2010 15:08:00
                549_____1_____1178_____1177,75_____1178,25_____117 7,75_____6-4-2010 15:09:00
                550_____1_____1178_____1178_____1178,25_____1178__ ___6-4-2010 15:10:00
                551_____1_____1178,25_____1178_____1178,5_____1178 _____6-4-2010 15:11:00
                552_____1_____1178,5_____1178,25_____1178,5_____11 78,25_____6-4-2010 15:12:00
                553_____1_____1178,75_____1178,25_____1179_____117 8,25_____6-4-2010 15:13:00
                554_____1_____1178,75_____1178,5_____1179_____1178 ,5_____6-4-2010 15:14:00
                555_____1_____1178,75_____1178,5_____1179_____1178 ,5_____6-4-2010 15:15:00
                556_____1_____1179_____1178,75_____1179_____1178,7 5_____6-4-2010 15:16:00
                557_____1_____1179_____1178,75_____1179_____1178,7 5_____6-4-2010 15:17:00
                558_____1_____1179_____1178,75_____1179_____1179__ ___6-4-2010 15:18:00
                559_____1_____1179_____1178,75_____1179,25_____117 9_____6-4-2010 15:19:00
                560_____1_____1179_____1178,75_____1179,25_____117 9_____6-4-2010 15:20:00
                561_____1_____1179_____1179_____1179,25_____1179__ ___6-4-2010 15:21:00
                562_____1_____1179,25_____1179_____1179,5_____1179 _____6-4-2010 15:22:00
                563_____1_____1179,25_____1179_____1179,5_____1179 _____6-4-2010 15:23:00
                564_____1_____1179_____1179_____1179,25_____1179,2 5_____6-4-2010 15:24:00
                565_____1_____1179_____1179_____1179,25_____1179__ ___6-4-2010 15:25:00
                566_____1_____1179_____1178,75_____1179,25_____117 9_____6-4-2010 15:26:00
                567_____1_____1178,75_____1178,75_____1179_____117 9_____6-4-2010 15:27:00
                568_____1_____1178,75_____1178,75_____1179_____117 9_____6-4-2010 15:28:00
                569_____1_____1178,75_____1178,5_____1179_____1179 _____6-4-2010 15:29:00
                23_____0_____1179,75_____1177,75_____1179,75_____1 177,75_____6-4-2010 15:30:00

                Comment


                  #9
                  How is my setup, on the strategy analyser I set in the backtest properties the same chart as I did in the code:

                  AddPointAndFigure("ES 06-10", PeriodType.Minute, 1, 1, 3, PointAndFigurePriceType.Close, MarketDataType.Last);

                  Only the OnBarupdate() seems to be triggerd less often on the chart setup (Barsinprogress == 0) then on the code (Barsinprogress ==1) while they both had the same values???

                  When I only use the Barsinprogress == 0 things seem to go smooth...

                  Point 1:
                  Strange thing is that OnBarUpdate() is triggered only for a bar and NOT for each minute! You would suspect multiple OnBarUpdate events with the SAME currentBar value, with the same Open,High,Low but with different Close values! In this way I can only have influence on my strategy after one whole bar is formed what could be within a minute but also within a day depending on the volatility!

                  Point 2:
                  And how does the back test address the update process on point 1, does the back test walk through each minute data and accordingly execute the orders? Or are they also executed after an bar update (it seems that the back test executes each minute data...but is that true)?

                  Point 3:
                  I pointed it out a little bit in point 1. A PnF bar (a column of 'x' or '0') has in this NT implementation always a close that equals the low or the high, but that is incorrect because before the bar closes the close value has risen or climbed already before it goes to the nextbar. The open is the one that will say if it is an up or down bar because it will never change and will be at the high or low point of the bar. That is also the check that I perform in my strategy. But to be honest, I have no idea if matters that the close of the bar/column has the value of the high or low...for my strategy it doesn't matter...and I can over see if someone will be bordered with it that it doesn't...just a point to think about...

                  Comment


                    #10
                    Originally posted by johannes View Post
                    Only the OnBarupdate() seems to be triggerd less often on the chart setup (Barsinprogress == 0) then on the code (Barsinprogress ==1) while they both had the same values???
                    This is because your BarsInProgress 0 has many less bars than BIP 1. Since you are running a multi-instrument strategy, this is expected behavior.
                    Point 1:
                    Strange thing is that OnBarUpdate() is triggered only for a bar and NOT for each minute! You would suspect multiple OnBarUpdate events with the SAME currentBar value, with the same Open,High,Low but with different Close values! In this way I can only have influence on my strategy after one whole bar is formed what could be within a minute but also within a day depending on the volatility!
                    That is correct. OnBarUpdate() is only called after each bar update, unless you set CalculateOnBarClose = false and then it would be called upon each tick during a real-time test. During a backtest, CalculateOnBarClose has no meaning.
                    Point 2:
                    And how does the back test address the update process on point 1, does the back test walk through each minute data and accordingly execute the orders? Or are they also executed after an bar update (it seems that the back test executes each minute data...but is that true)?
                    The backtester only runs OnBarUpdate after each bar is completed. You can add intrabar granularity to your backtests though.

                    Point 3:
                    I pointed it out a little bit in point 1. A PnF bar (a column of 'x' or '0') has in this NT implementation always a close that equals the low or the high, but that is incorrect because before the bar closes the close value has risen or climbed already before it goes to the nextbar. The open is the one that will say if it is an up or down bar because it will never change and will be at the high or low point of the bar. That is also the check that I perform in my strategy. But to be honest, I have no idea if matters that the close of the bar/column has the value of the high or low...for my strategy it doesn't matter...and I can over see if someone will be bordered with it that it doesn't...just a point to think about...
                    Thank you for pointing this out. We will look over it and make sure the implementation is correct.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Point 3. I am not exactly sure what you mean. A bar closes when the next bar begins. For PnF, the next bar begins off of the prior bar and as such the close of the prior bar is at the high/low of that bar as that is the "jumping off" point for the new bar. Or am I missing something here? Thanks for the clarification.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Josh, I have thought about it, and the NT implementation is correct. Because you guys implemented it as normal bars doesn't mean that the close should be different. So forget point 3.

                        But I found some other strange behavior during the development, I have already described it, but I will try it to do a little bit more clear. Probably I am doing something wrong...

                        I have the following strategy:

                        protectedoverridevoid Initialize()
                        {
                        CalculateOnBarClose =
                        false;
                        Unmanaged =
                        true;

                        AddPointAndFigure(productToTrade, PeriodType.Minute, 1, 1, 3, PointAndFigurePriceType.Close, MarketDataType.Last);

                        }


                        protectedoverridevoid OnBarUpdate()
                        {
                        Print(CurrentBar.ToString() + "_____" + BarsInProgress.ToString() + "_____" + Close[0].ToString()+ "_____"+ Low[0].ToString()+ "_____"+ High[0].ToString()+ "_____"+ Open[0].ToString()+ "_____"+ Time[0].ToString());

                        }

                        I run this strategy on a PnF chart with the same settings (see attached picture) as strategy is using. When I run this strategy on a realtime stream from Interactive Brokers with the instrument ES-06 I get the following output (see below). How could it be that the chart data at CurrentBar==0 has different data then the strategy data at CurrentBar == 1???? What is going wrong here? And why do I sometimes see data as 1191,74998077049, that isn't even a tick value? And why do the times differ? What am I overlooking, or what is going wrong?

                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,75_____1191,5_____1191,75_____ 1191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,5_____1191,5_____1191,75_____1 191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,75_____1191,5_____1191,75_____ 1191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,75_____1191,5_____1191,75_____ 1191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,75_____1191,5_____1191,75_____ 1191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,75_____1191,5_____1191,75_____ 1191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,5_____1191,5_____1191,75_____1 191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6125_____1_____1191,5_____1191,5_____1191,75_____1 191,74998077049_____13-4-2010 15:21:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6126_____1_____1191,75_____1191,62499038524_____11 91,75_____1191,62499038524_____13-4-2010 15:22:00
                        296_____0_____1191,5_____1191,5_____1192,25_____11 92,25_____13-4-2010 15:12:00
                        6126_____1_____1191,75_____1191,62499038524_____11 91,75_____1191,62499038524_____13-4-2010 15:22:00
                        Attached Files

                        Comment


                          #13
                          johannes,

                          All of the times differ so for sure all of the data will differ because you are looking at different bars. Remember that from a strategy, it does not start processing till you have a minimum of 20 bars. This is the default bars required setting. An indicator is not restricted by this and is likely why you are starting earlier.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks for your quick response Josh,

                            All of the times differ so for sure all of the data will differ because you are looking at different bars.

                            I thought something like that, but how do I look at the right bars? How can I get the data on the chart (CurrentBar ==0 <= or am I not correct with this??) and the data added by

                            Code:
                            AddPointAndFigure(productToTrade, PeriodType.Minute, 1, 1, 3, PointAndFigurePriceType.Close, MarketDataType.Last);
                            (CurrentBar == 1 <= or am I not correct with this??) in sync with each other?

                            In the attachment strange2 I set the "Min. Bars required" to 0 to get it in sync, but that didn't work...

                            A)
                            It seems that the chart (CurrentBar == 0) is walking behind, but when I look at the chart it constantly displays the correct tick value. So why is the strategy handling an other tick then the chart?

                            B)
                            In the attachment strange behavior you can see that the tickdata on the chart was constantly 1186,75 then the value of the future E-MiniS&P500 changed to 1186.50 (saw it changing in TWS from Interactive Brokers to). You see on that tick first a new BarUpdate event been triggered with CurrentBar ==0 with out of sync data and then you see BarUpdate event triggered again with CurrentBar ==1
                            At this event you can see that it has a close value that is in sync with the latest tick the future has been trading on. But The time is 1 minute in the futere, computer time displays 16:41

                            C)
                            The Low[0] and the Open[0] display very strange values on the BarUpdate event with a CurrentBar ==1! It can even occur that it is only the Open[0] who throws this kind of values. As you could have seen in my previous post. This is future data with .25 ticksize so this kind of values shouldn't happen.

                            I hope you won't find me to annoying...

                            Thanks in advance,

                            Johan
                            Attached Files

                            Comment


                              #15
                              I did not fully understand your screenshots, but please consider this. You need to actually start the PnF chart at exactly the same time or else you end up with different bars since PnF depends on the starting point.

                              What I suggest is you to set BarsRequired to 0 on the strategy and get it printing immediately just like the indicator. Make sure your days to load and session template are exactly the same.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              607 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              353 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X