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

Vertical Bar

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

    Vertical Bar

    Is it possible to draw a vertical line between 2 indicators. For example, if I have 2 moving averages on the chart and I want to draw a vertical line between them, is it possible?

    I'm transitioning from traderstation and they had a feature called Paintbar which would allow me to pass a high value and a low value and it would paint a vertical bar on the chart.

    Hoping someone can help.

    #2
    Hi vsolv,

    Yes, you could use DrawLine(), which has startY and endY inputs:


    You may want to check out DrawRegion() as well. There's a sample showing how to work it between Bollinger lines here:
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      When using the Drawline
      startY - The starting y value co-ordinate where the draw object will be drawn
      EndY - The end y value co-ordinate where the draw object will be drawn

      Drawline is expecting me to provide the StartY and EndY values. I'm guessing that the coordinate system is in pixels. So question is, how do I take my indicator's High and Low values and convert it to the proper Y coordinate ?

      Sorry --- newbie here and just learning NScript.

      Comment


        #4
        StartY and EndY are the values of your moving averages. Let's say you have a 5 period and 50 period SMA. You would draw lines between them with something like this:

        Code:
        DrawLine("Lines" + CurrentBar, 0, SMA(5)[0], 0, SMA(50)[0], Color.Blue);
        This can be a bit of a performance drain, so I would also take a look at that DrawRegion sample which can do this sort of thing with more efficiency.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Apologize for these newbie questions.
          In my indicator, I have 2 local variables that I'm trying to plot.
          MyHigh, MyLow - these are double

          I do my calculations to populate these in the indicator.

          when I try to plot them as follows:

          DrawLine("Lines" + CurrentBar, 0, <MyLocalVar_High>, 0, <MyLocalVar_Low>, Color.Blue);

          I get the following errors:

          Use of unassigned local variable MyHigh
          Use of unassigned local variable MyLow


          What am I doing wrong? Can someone help.

          Comment


            #6
            Mistyped:

            in my indicator I try to plot them as follows:

            DrawLine("Lines" + CurrentBar, 0, <MyHigh>, 0, <MyLow>, Color.Blue);

            Comment


              #7
              For basic C# syntax, I would check out the following link:


              Example with doubles:
              double myHigh = SMA(5)[0];
              double myLow = Low[0];

              Then refer in code with just myHigh or myLow. (no extra < or > needed)
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by vsolv View Post
                Mistyped:

                in my indicator I try to plot them as follows:

                DrawLine("Lines" + CurrentBar, 0, <MyHigh>, 0, <MyLow>, Color.Blue);
                Why the pointy brackets?

                Comment


                  #9
                  Hi Kogaman and Ryan,
                  The pointy brackets mean nothing. I mistyped. I did not use them in my code. I come from a programming background and that is a way write pseudocode.

                  Anyway,
                  What I was trying to ask was that, in my indicator I have 2 variables that I've declared as Double in the OnBarUpdate() procedure as follows:
                  double MyHigh;
                  double MyLow;

                  // I did some calculations to populate MyHigh and MyLow variables
                  //Now what I want to do is print a vertical line between MyHigh and MyLow
                  //When I use the Drawline as Ryan suggested
                  DrawLine("Lines" + CurrentBar, 0, MyHigh, 0, MyLow, Color.Blue);

                  //I get the following errors:
                  Use of unassigned local variable MyHigh
                  Use of unassigned local variable MyLow

                  Any ideas what I'm doing wrong? From my 1 day experience with NinjaScript, it seems like it is expecting a dataseries (i.e. an array of doubles). For example if I use
                  DrawLine("Lines" + CurrentBar, 0, High[0], 0, Low[0], Color.Blue);
                  it compiles fine.

                  Thanks for helping.

                  Comment


                    #10
                    Originally posted by vsolv View Post
                    Hi Kogaman and Ryan,
                    The pointy brackets mean nothing. I mistyped. I did not use them in my code. I come from a programming background and that is a way write pseudocode.

                    Anyway,
                    What I was trying to ask was that, in my indicator I have 2 variables that I've declared as Double in the OnBarUpdate() procedure as follows:
                    double MyHigh;
                    double MyLow;

                    // I did some calculations to populate MyHigh and MyLow variables
                    //Now what I want to do is print a vertical line between MyHigh and MyLow
                    //When I use the Drawline as Ryan suggested
                    DrawLine("Lines" + CurrentBar, 0, MyHigh, 0, MyLow, Color.Blue);

                    //I get the following errors:
                    Use of unassigned local variable MyHigh
                    Use of unassigned local variable MyLow

                    Any ideas what I'm doing wrong? From my 1 day experience with NinjaScript, it seems like it is expecting a dataseries (i.e. an array of doubles). For example if I use
                    DrawLine("Lines" + CurrentBar, 0, High[0], 0, Low[0], Color.Blue);
                    it compiles fine.

                    Thanks for helping.
                    It means what it says. You declared the variables without initializing them. Local variables must be initialized before being used in calculations. Try explicitly initializing the doubles (usually to zero).

                    Comment


                      #11
                      That did the trick. Thanks a lot koganam. Really appreciate it.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by wzgy0920, 04-20-2024, 06:09 PM
                      2 responses
                      26 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, 02-22-2024, 01:11 AM
                      5 responses
                      32 views
                      0 likes
                      Last Post wzgy0920  
                      Started by wzgy0920, Yesterday, 09:53 PM
                      2 responses
                      49 views
                      0 likes
                      Last Post wzgy0920  
                      Started by Kensonprib, 04-28-2021, 10:11 AM
                      5 responses
                      191 views
                      0 likes
                      Last Post Hasadafa  
                      Started by GussJ, 03-04-2020, 03:11 PM
                      11 responses
                      3,230 views
                      0 likes
                      Last Post xiinteractive  
                      Working...
                      X