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

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.
    Brandon H.NinjaTrader Customer Service

    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.
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by philmg, Today, 12:55 PM
        0 responses
        3 views
        0 likes
        Last Post philmg
        by philmg
         
        Started by Russ Moreland, Today, 12:54 PM
        0 responses
        2 views
        0 likes
        Last Post Russ Moreland  
        Started by f.saeidi, Today, 12:14 PM
        2 responses
        6 views
        0 likes
        Last Post f.saeidi  
        Started by TradeForge, 04-19-2024, 02:09 AM
        2 responses
        30 views
        0 likes
        Last Post TradeForge  
        Started by aprilfool, 12-03-2022, 03:01 PM
        3 responses
        327 views
        0 likes
        Last Post NinjaTrader_Adrian  
        Working...
        X