Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

sample script CustomPlotSample

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

    sample script CustomPlotSample

    Technical support tells me that the script in this file is not supported by them, so I am wondering if anyone here can give me some pointers.

    This script contains a void function called Plot

    Code:
    public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
    {
    . . .
    }
    Within this function there is a statement that places text on the chart at a fixed location

    Code:
    graphics.DrawString("Upper left corner", textFont, textBrush, bounds.X+10, bounds.Y+10, stringFormat);
    I want to be able to add text to my strategy that stays in a fixed Y location relative to the chart bounds and a fixed X location relative to a specific data bar. IOW, I want the text to scroll horizontally with the data but ignore any automatic price scaling activity so that it is always, for example, 5 pixels below the top of the chart. If I scroll the designated data bar off of the screen, the text should scroll off with it. If I scroll the designated data bar back onto the screen, the text should also scroll back. And still be 5 pixels below the top of the chart.

    I have added this function to my custom strategy script but it will not compile. It flags the function name Plot and says something like " ... not in this context ..."

    I have compared the using declarations at the top of my script (all the same as in CustomPlotSample).

    I have added the commented lines that appear in the summary block just before the function call and reference the parameters called by the Plot function.

    I do not see anything else that might be missing. But there must be something.

    v6.5.1000.14, WXP/SP3, new to C and NinjaScript but not to programming

    ???,
    LB

    #2
    Did you try it in a custom indicator of yours as well?

    Strategies do not plot, so the context in which you attempt to call this method is off...

    For a fixed text location, try using DrawTextFixed -

    http://www.ninjatrader-support.com/H...TextFixed.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Did you try it in a custom indicator of yours as well? http://www.ninjatrader-support.com/H...TextFixed.html
      Yes, I've tried two different approaches, and I get compile errors there as well. But before I get into them I have run into another problem.

      If I have a script with errors, any attempt to compile a second (known good) script aborts and the compiler flags the first script (with the error). The second script is still in the editor.

      Is there a way to get around this without commenting out code in the first script (with the error)?

      Comment


        #4
        Yes, expected as all scripts compile into one assembly for maximum performance at runtime, but therefore they all have to be in a compilable state.

        You could just comment out the complete script if you don't want to fix it now but later...more tips found here -

        http://www.ninjatrader-support2.com/...ead.php?t=4678
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Sounds like an OK work around. But ...

          If I Select All and then Coment Selected Text, then try to either save the script or compile it, NT crashes.

          ???

          Comment


            #6
            However, I have found another work around (made a sub folder and moved the broken script to it).

            So lets move on.

            I found what I was doing wrong in my indicator when I added the Plot function - left out one of the parameters. (Perhaps one day your maintenance guys can make the error message a little more informative?)

            So lets move on.

            You also said that "Strategies do not plot". Since I can look at a live NT chart right now, with the MACrossover sample strategy running on it, and I can see two MA indicators plotted on it, I presume that you mean something other than "a strategy CANNOT BE MADE to plot things".

            In fact, the strategy wizard has a switch for each indicator you invoke, to control whether or not it is plotted on the chart.

            Comment


              #7
              gamemaster, great you got it working - a strategy can call indicators to add them to the chart for visualization purposes, but you can't custom plot from the NinjaScript Plot method from it.

              http://www.ninjatrader-support2.com/...ead.php?t=3228
              BertrandNinjaTrader Customer Service

              Comment


                #8
                One more question on this topic. (I understand that NT does not support the Plot function, so you might want to just sit back and see if any of the non-company members can help me here.)

                Invoking the Plot function suppresses any indicators that you are plotting from the OnBarUpdate function. In the last week or so I have been rummaging around in the forum and have seen some discussion of this, but I don't remember exactly where.

                The fix, if if remember correctly, involves placing certain code statements in the correct order. It is a defacto Z-order control scheme. (True Z-order control is said to be comming in v7.)

                Can anyone point me to an existing discussion of this, or explain it to me here?

                LB
                Last edited by gamemaster; 03-12-2010, 10:29 AM.

                Comment


                  #9
                  LB, we do support the standard Plot method, but unfortunately not overriding it to achieve custom plotting features.

                  Correct the ZOrder is determined in the sequence the plots / indicators are added to the chart.

                  In NT7 the ZOrder of applied indicators and draw objects can be directly adjusted on the chart with holding Shift pressed and your mouse scroll wheel while having selected the data points.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks.

                    I finally found the discussion I was thinking about and this was the answer discussed. But this kind of misses the point.

                    How do I add some text to the main chart using the graphics objects (so I can independently control X and Y placement as described in my opening post), and still have my indicators visible? Neither DrawText nor DrawTextFixed do what I need done.

                    MUST I override the Plot function in order to use the graphics objects? I've tried to invoke them from within OnBarUpdate without success (because of no parameters I guess). Is there a way to get around this?

                    (Again, since this is a question about VERY USEFUL but unsupported toys, you might want to sit back and see if anyone else can help.)

                    Comment


                      #11
                      LB, correct you would need to override the Plot method for this - another example would be the 'Status Box' custom indicator posted to our sharing section here - http://www.ninjatrader-support2.com/...&pp=15&page=13
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        OK, so NT is not able to do things like this. Not even with the full power of C# behind it. Bummer.

                        Let me try a different approach - maybe I'm going about this the hard way.

                        Is there a way to cause the day of the week (Mon, Tue, etc) to appear in the time axis several times a day (such as 8 AM, 12PM, 3PM)?

                        Comment


                          #13
                          gamemaster, both are definitely doable by custom coding in C# / NinjaScript, but as previously noted you would need to override the default Plot() method which involves C# coding at an advanced level that we unfortunately can't support here. But you should have a good start with the samples I provided...
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Blairski, Yesterday, 09:19 AM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by tonynt, Today, 09:33 AM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by minotti1, Today, 08:31 AM
                          1 response
                          13 views
                          0 likes
                          Last Post NinjaTrader_Jim  
                          Started by SmartArtsStudio, 05-15-2021, 10:46 AM
                          1 response
                          15 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by Airwave, Today, 06:02 AM
                          2 responses
                          22 views
                          0 likes
                          Last Post NinjaTrader_BrandonH  
                          Working...
                          X