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

Is there a DrawLine() Example?

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

    Is there a DrawLine() Example?

    Hi, I'm just starting with NinjaScript and trying to use the drawline function to draw a simple line between the closing price of the current bar and the closing price of the 5th bar ago.

    protected override void OnBarUpdate()
    {
    DrawLine("line", 5, Close[5], 0, Close[0], Color.Blue);
    }

    No line appears on my chart. What am I missing?

    I have another question also. The indicator that I want to create will draw stairstepping lines - lines plotted, say, from a swing low on an early bar to a swing high on a later bar, then from that swing high to an even more recent swing low... etc.

    I understand that the OnBarUpdate() function is called for every bar.

    1. Does this mean that every bar on the chart becomes Bar[0] when the function is called for that bar?

    2. If so, how can I have OnBarUpdate() called only for the last (current) bar, OR have the code inside OnBarUpdate() only executed for the current bar? For my indicator I only need to call the function on the current bar, determine my swing points from the price dataseries, and draw my stair stepping lines once, would that be correct?

    Thankyou.

    #2
    Welcome to our forums, first place to check would be the log tab of your Control Center - are there any errors listed? You likely run into this issue here - http://www.ninjatrader.com/support/f...ead.php?t=3170

    The OnBarUpdate() is called for all on bar on the chart with the leftmost bar being Bar 0.

    You could compare CurrentBar to the Bars.Count to call on the last bar.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Still cant get a simple drawline to work, can you give me a starting point?

      Hi, I checked that there are bars on the window, there are. My indicator is behaving slightly differently now. When I add the indicator to my price chart the price bars are squashed to the top of the window and the price scale starts at zero at the bottom, to highest price at the top. I can't see if my line is actually drawn or not.

      this is my code, can you tell me what I am doing wrong, or point me in the direction of a simple example that uses DrawLine()?

      thanks.

      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Bar , "Plot0"));
      CalculateOnBarClose = true;
      Overlay = true;
      PriceTypeSupported = false;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      DrawLine("line", false, 1, Close[1], 2, Close[2], Color.Orange, DashStyle.Solid, 2);
      }

      Comment


        #4
        Also, I can't find the 'log tab' you mentioned in Control Centre.

        Thanks again.

        Comment


          #5
          The log tab is on the far right side in the Control Center - http://www.ninjatrader.com/support/h...7/log_tab2.htm

          Please find attached a small sample showing a trendline from session open to the current high dashed.
          Attached Files
          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          66 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          18 views
          0 likes
          Last Post benmarkal  
          Started by f.saeidi, Today, 01:38 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X