Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator Develpoment or Strategy Builder?

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

    #16
    Hello trdninstyle,

    Thank you for your note.

    In order to explore the different adjustments for rectangles, I suggest opening up a test script in the Strategy Builder (Control Center > New > Strategy Builder). This is similar to the advice I provided in post #2 of this thread. Next, you can go to the conditions and actions screen and set an action to draw a rectangle. The interface will allow you to adjust things like color and opacity, and then the start/end barsAgo and Y values will determine where the different corners of the rectangle will be placed. Once you have set up the action, you can click the "View Code" button to see how the action is coded inside of the NinjaScript Editor. This code may be copied and pasted directly into the indicator you are developing.

    It can also be helpful to keep the help guide page for Draw.Rectangle open and compare the code from View Code with the help guide page, as well as take note of which options you select in the Strategy Builder change which parts of the actual code. Here is the help guide section for Draw.Rectangle:

    Note: using an overload with areaOpacity will allow you to set the opacity for the area of the rectangle

    For more tips when getting started/getting more familiar with coding in NinjaScript, please see the link below:


    Our scripting support team does not provide hands-on development or debugging assistance; please try out the described process to draw a rectangle in your indicator. If the results you are getting when testing out the indicator are unexpected, please provide an example of the code you are using as well as an explanation of how you expect it to behave so I may assist you with specific questions.

    I appreciate your patience. Please don't hesitate to reach out if you encounter any unexpected behavior or have any specific questions.

    Comment


      #17
      How does this look in pic. I pasted it underneath and kept what I think I needed and replaced the rest, basically.

      I just noticed in Pic that I left out one of the ... Brushes,White,2); There has to be two.

      I'm just wanting the rectangle to be somewhat expanded but not much, because u could place a limit buy 1 tick or 2 ticks above, and easier to see.
      Attached Files
      Last edited by trdninstyle; 10-13-2022, 12:00 PM.

      Comment


        #18
        Hello trdninstyle,

        Thank you for your reply.

        In order to test out what the rectangles will look like, I recommend compiling your script and adding it to a chart to see. I added the following to an indicator (I change the tag so only one rectangle would be drawn) and this is what the rectangle looks like:

        Code:
        protected override void OnBarUpdate()
                {
                    if (CurrentBar < 10)
                        return;
        
                    if (Close[0] > Close[1])
                    {
                        Draw.Rectangle(this, "tag1", false, 10,- TickSize, 5, High[5] + TickSize, Brushes.White, Brushes.White, 2);
                    }
                }​
        Click image for larger version

Name:	2022-10-13_13-20-07.png
Views:	214
Size:	38.7 KB
ID:	1219338


        Taking a look at the method used for Draw.Rectangle, there are a couple of things that might be off from what you are expecting:

        Draw.Rectangle(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, Brush areaBrush, int areaOpacity)

        The values for startY and endY are for the y-axis start and end points. This is basically what prices your rectangle will start and end at. Your startY value is -TickSize, which will start the rectangle at a negative number and is why the rectangle goes down beyond what is shown in the screenshot. The builder generated code has Low[10] - TickSize instead, which would start the rectangle at the low of 10 bars ago minus 1 tick. Your endY matches what the builder shows which is the high of 5 bars ago plus one tick.

        The areaOpacity value of 2 sets the shading of the rectangle to 2%. There may be a slight white shading to it, but it is hardly noticeable. This value ranges from 0-100, with 0% being a completely transparent area (no shading) to 100 being a completely solid, shaded in rectangle. You may need to tweak this as desired depending on whether you want your rectangle to be shaded in or not.

        By adding the script to a chart as you compile along the way, you can see what parts are not what you were expecting and then you can go back and tweak the script as needed to observe the changes. Eventually, you should be able to hit that sweet spot and get the rectangles to plot exactly how you'd like them.

        Please let us know if we may be of further assistance.

        Comment


          #19
          I like the way u explain everything it's easier to understand and I can carry it out.

          I copied/pasted the code that u showed, and I get errors I'm probably not applying it right. In my pic I placed comment lines, so errors don't show.
          Perhaps I should do a new script w/ nothing else on it, bc when I paste this in its causing comma errors, I believe thats what it said if I remember right.

          We can do this tomorrow if it's more convenient for you.

          PS. Yes, I'm going to use a new script just for testing & see what I can learn. Got small issue not a big deal it can wait.

          Just posting the pic so tomorrow I don't have to.
          Attached Files
          Last edited by trdninstyle; 10-13-2022, 04:02 PM.

          Comment


            #20
            Hello trdninstyle,

            Thank you for your reply.

            What are the errors that are showing? Where are they showing, for example in the NinjaScript Editor, in the Log tab of the Control Center, or somewhere else? If you are able to provide the specific error message I would be glad to help you out or provide additional steps on how to debug your script.

            I look forward to your reply.

            Comment


              #21
              Thanks, line 74.

              Class member declaration expected.
              "}" expected
              Attached Files
              Last edited by trdninstyle; 10-13-2022, 04:18 PM.

              Comment


                #22
                Yesterday I forgot to put ... if ((Close[1] < Open[1]) && (Low[0]>= Low[1]) && High[0]<High[1] && (Close[0]>Open[0]) )

                before .... Draw.Rectangle(this, "tag1", false, 10,- TickSize, 5, High[5] + TickSize, Brushes.White, Brushes.White, 2);

                Now this pic has them both, its showing a red squiggly line indicating I'm missing something.

                Attached Files
                Last edited by trdninstyle; 10-14-2022, 07:33 AM. Reason: There was extra letters & #'s, so I erased those

                Comment


                  #23
                  Hello trdninstyle,

                  Thank you for that information.

                  It looks like you are missing one or two end curly braces '}' - I created a screenshot demonstrating where they should be added before you try to recompile:
                  World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


                  Please let me know if you are still receiving errors after adding one or both of these curly braces.

                  Comment


                    #24
                    That was perfect, it's always something simple like that. It compiled; I made a separate script to learn the nuances of adjusting the Rectangles.
                    No rectangle showed, I think I know what it is. The private bool?
                    Attached Files

                    Comment


                      #25
                      Stop the presses, I got it. I went and placed it on script that I know is correct. Now I'll adjust it.
                      Attached Files

                      Comment


                        #26
                        I think it may be a futile battle to get the rectangle to be the shape that I want. No matter what I do to adjust it, it still drops down to infinity.

                        What if I go back to Draw.Line and make the line thicker and an opacity 30% or something?

                        Comment


                          #27
                          I know I don't have this fitted in correctly, but am I using the right Syntax? To make the drawLines thicker and to adjust the opacity.

                          I won't spend much more time on this part because I can live with the regular rectangles the way they are.
                          I want to go over into building strategies next, I watched a whole video last night by ChelseaB that u gave me yesterday up in prev statement.
                          (It changes my wording)

                          But if I can do something with the lines, say, 3 times thicker and a light opacity, I'll do it.

                          Thank you, your patience is remarkable.
                          Attached Files

                          Comment


                            #28
                            Hello trdinstyle,

                            Thank you for your reply.

                            I addressed the LineDrawn bool and the bottom of the rectangle seeming infinite previously. Here is where I mentioned LineDrawn:

                            If you notice, I removed the (LineDrawn != true) part of the condition. This is not needed unless you plan to toggle LineDrawn between true/false with other conditions to enable/disable the line being drawn. Based on your screenshots and descriptions, this does not seem to be your plan which means the LineDrawn variable is extra.
                            With this information in mind, you should be able to completely remove line 30 of your script, as you are not using LineDrawn anywhere in your logic at this point.

                            As for the rectangle, please see this answer from post #18:

                            Taking a look at the method used for Draw.Rectangle, there are a couple of things that might be off from what you are expecting:

                            Draw.Rectangle(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, Brush areaBrush, int areaOpacity)

                            The values for startY and endY are for the y-axis start and end points. This is basically what prices your rectangle will start and end at. Your startY value is -TickSize, which will start the rectangle at a negative number and is why the rectangle goes down beyond what is shown in the screenshot. The builder generated code has Low[10] - TickSize instead, which would start the rectangle at the low of 10 bars ago minus 1 tick. Your endY matches what the builder shows which is the high of 5 bars ago plus one tick.
                            In order to adjust the bottom of your rectangle so it is not extended too low, you will need to change your startY value. A value you could test out could be something like "Low[0] - TickSize" instead of just being "- TickSize." This is what you previously had when you copied from the Strategy Builder, but it looks like a piece of it was missing when you copied it over into your manual script.

                            Your final screenshot in your most recent reply uses syntax related to the Lines collection which is only relevant if you have used AddLine() in your indicator. This is not related to the Draw.Line drawing method and is not the correct syntax. You were very close with the Draw.Rectangle method and it may be better to go back and tweak the rectangle code rather than drawing a really thick line.

                            If you would like more hands-on assistance and education with the development process, our Vendor Support team could provide you with more information about available NinjaScript consulting resources. If this option interests you, please let me know and I would be glad to get you the appropriate information.​

                            Comment


                              #29
                              I eliminated line 30 it composed and no problems.

                              I removed everything and just have one setup condition.


                              Now I just need a curly bracket in the right spot. Here's a screenshot.​
                              Attached Files

                              Comment


                                #30
                                I need to walk away from this for now, shut it down. Maranatha

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                648 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                369 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                572 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X