Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Percentages from Close

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

    Percentages from Close

    Hi there.


    I have an indicator I'm developing. Right now it simply plots horizontal lines at different percentages since the previous days close. So it will plot lines at the 1,2 and 3% above or below the close of the previous day. Now I'd like some flexibility to be able to plot from the close of previous days back for example if I wanted to plot the lines to draw from the close of 3 days back. Any ideas on how I would achieve this?

    Now I have put a value in daysback as 3 but still does not plot lines 3 days back. Hmmm.

    Indicator code attached


    Thanks in advance
    DJ




    Click image for larger version  Name:	Screenshot 2022-12-18 230345.png Views:	0 Size:	200.8 KB ID:	1228052


    Last edited by djkiwi; 12-18-2022, 11:16 AM.

    #2
    Hello djkiwi,

    Thanks for your post.

    The Draw.HorizontalLine() method will draw a horizontal line that will span across the entire chart that the indicator is applied to. The horizontal line will be drawn at the 'double y' value you set it to.

    Draw.HorizontalLine(NinjaScriptBase owner, string tag, double y, Brush brush)

    Add prints before your Draw method is called that prints out the value being assigned to the line so that you can confirm exactly what the value being passed into the Draw.HorizontalLine() method is.

    I created a test script that draws one horizontal line at the PriorDayOHLC().PriorClose[0] and another horizontal line at the PriorDayOHLC().PriorClose[3].

    When adding the indicator to an ES 03-23 60-minute chart, we can see both lines draw on the chart for the entire span of the chart.

    See this demonstration video: https://brandonh-ninjatrader.tinytak...NF8yMDcwMDA0Ng

    See the help guide pages linked below for more information.

    Draw.HorizontalLine: https://ninjatrader.com/support/help...zontalline.htm
    PriorDayOHLC: https://ninjatrader.com/support/help...r_day_ohlc.htm

    Let me know if I may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you Brandon for the response. Unfortunately when I made those changes I could not see any change. I am going back 5 days and line still shows back 1 day. I have marked on the chart where the yellow line should appear 5 days back.


      The other item is I would like the lines to start from the beginning of the period chosen and not span the entire chart. I've included a a chart from thin or swim illustrating this.


      I've attached the code and charts. Any ideas on this?

      Thanks again

      DJ

      Attached Files
      Last edited by djkiwi; 12-18-2022, 09:29 PM.

      Comment


        #4
        Hello djkiwi,

        Thanks for your note.

        "I am going back 5 days and line still shows back 1 day. I have marked on the chart where the yellow line should appear 5 days back."

        In the screenshot you shared I am seeing a yellow horizontal line span across the entire chart window as expected (Dec 5 - Dec 17 in the screenshot). Is this the line you are referring to?

        The Draw.HorizontalLine() method will draw a horizontal line on the chart at the value you assign to it (double y parameter) and the line will span across the entire chart window.

        If you would like to draw a line from one point to another, you would need to use the Draw.Line() method instead of the Draw.HorizontalLine() method.

        The Draw.Line() method allows you to draw a line on the chart from a start point to an end point. You could use a DateTime value to define the start point and end point of your line drawing object.

        Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width)

        To get the start time of a session 3 days ago you could use a SessionIterator and pass it a time to get the session based on the time. The sample code in the SessionIterator help guide page linked below uses Time[0]. You would have to subtract 3 days from Time[0] to get the start time of the session 3 days ago.

        See the help guide documentation below for more information and example code.

        Draw.HorizontalLine(): https://ninjatrader.com/support/help...zontalline.htm

        Draw.Line(): https://ninjatrader.com/support/help.../draw_line.htm

        SessionIterator: https://ninjatrader.com/support/helpGuides/nt8/sessioniterator.htm

        Let me know if I may assist you further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X