Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem in drawing a line

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

    Problem in drawing a line

    Dear All,

    I am new in NinjaSceipt. I tried to draw a line using DrawLine() method, but it doesn't work. I didn't see anything drawn on the panel. Why ?

    I write the code below in the Initialize() function:

    DrawLine("aaaa",AutoScale, 100, 1000, 200, 2000, Color.Green, DashStyle.Solid, 2);


    Thanks

    #2
    Hello,

    Thanks for your forum post and welcome to the NinjaTrader forum.

    In initialize the Bar Series objects do not exist yet. Therefor this would need to be moved down to OnBarUpdate(). So that it can be drawn on the chart.

    Also, you will need to add a check in OnBarUpdate() to only draw this once it has 200 bars on the chart or else you will get an error in the log tab in the control center if you run this as is in OnBarUpdate() as OnBarUpdate() starts running from the left of the chart to the right and then starts to run on live data as it comes in.

    Please follow these instructions:



    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Thanks very much for your help Brett.

      I have successful draw the line. Another question is how to draw some more lines on the palen? See the code below:

      if(CurrentBar > 200 && flag){
      DrawLine("aaaa",AutoScale, 100, 1000, 0, 2000, Color.Green, DashStyle.Solid, 2);
      DrawLine("aaaa",AutoScale, 100, 2000, 0, 1000, Color.Blue, DashStyle.Solid, 2);
      flag = false;
      }


      It only shows the second line, how to solve this problem?

      Also, I want to draw a line that indicates the maximun value of a bar segment( for example, 10bars)
      then the first thing I should do is to detect the maximum value of the 10 bars.
      Is there any build in function that I can use to achieve such goal ?
      If not, how to do that ?

      Thanks
      Last edited by keven; 02-16-2011, 09:32 AM.

      Comment


        #4
        Hello,

        This occurs as the tag aaaa is used for each line.

        If the same tag is used it will update the location of the line instead of draw a new one.

        If you always want a new line drawn all the time for example an easy way to do this is.

        DrawLine("aaaa" + CurrentBar,AutoScale, 100, 1000, 0, 2000, Color.Green, DashStyle.Solid, 2);
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        161 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        308 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        245 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        349 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        179 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Working...
        X