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

Extend or reposition line

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

    Extend or reposition line

    I want to modify the CurrentDayOHL indicator that comes with NJ8 to use a solid line segment. However, regardless of line type, there are vertical sections of the line that run between previous high and new high (for example). Everything is connected.

    Would you please point me to an example that allows an unconnected horizontal line segment to be drawn, and then extended or repositioned as needed.

    For example:

    NinjaTrader.NinjaScript.DrawingTools.Line highLine = Draw.Line(this, "HighLine", false, 0, High[0], -4, High[0], Brushes.Red, DashStyleHelper.Solid, 2);

    gets me started. On the next bar, how do I extend highLine one bar to the right?

    Finally, when the next bar's high exceeds the Y price of my line, how do I reposition the line to the new bar and Y price value? Or must I dispose of the line and just create a new one?

    Many thanks.

    #2
    Hello,

    Thank you for the post.

    You would be correct in the sense everything is connected, this indicator uses Plots to store the values calculated so it is indeed one long continuous series of data. The indicator as it is now would use Plots and one of the effects of the style it uses is to "break" the line rather than plotting between sessions. When the style is changed, the plot can be seen better between sessions.

    I couldn't suggest anything to extend the line past the current bar, negative indexes are not technically supported. I could really only suggest to draw up to the CurrentBar or last bar on the chart which is the 0 BarsAgo index.

    To change the existing lines price, you would need to call its tag name again with the new price, so if the line was named MyLine, just call Draw.Line again using the tag "MyLine" and it would update the existing line. You could set a specific name for each line per session to know you will affect only the most recent line while the price changes.

    To draw use lines in this indicator rather than plots, you could use the existing plot data and add syntax/logic for the Draw.Line where needed. If you need to draw a line from the start of the session to the current bar, that could be like the following syntax:

    Code:
    if(CurrentBar < Bars.BarsSinceNewTradingDay) return;
    Draw.Line(this, "MyLine", Bars.BarsSinceNewTradingDay, Close[Bars.BarsSinceNewTradingDay], 0, Close[0], Brushes.Blue);
    In place of Close[] you could use the series from the indicator in which you want to draw the line for its value.


    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by zstheorist, Today, 07:52 PM
    0 responses
    5 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    6 views
    0 likes
    Last Post tkaboris  
    Working...
    X