Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Line Class / DrawHorizontalLine problems.

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

    Line Class / DrawHorizontalLine problems.

    Hi,

    I need an indicator, which looks like one in enclosed image - there is a red/yellow/green zone. The zones are just bunch of horizontal lines.

    Values of the lines are computed parameters passed to the indicator.

    I tried to create new Line objects during Initialize(). This approach works, however the lines are fixed - if I'm changing values of parameters, it seems Initialize() is not called, the lin values remain, but are not relevant anymore.

    Therefore I tried to using DrawHorizontalLine() in OnBarUpdate() . I tried to ensure it's done only once e.g.
    if (CurrentBar == 5)
    {
    for (i=y1 to y2)
    {
    strL = "Line" + i.ToString() ;
    // Add(new Line(new Pen(Color.Red,3), i, strL));
    DrawHorizontalLine(strL, true, i, Color.Red, DashStyle.Solid , 4) ;

    }

    for (i=y3 to y4)
    {
    strL = "Line" + i.ToString() ;
    // Add(new Line(new Pen(Color.Yellow,3), i, strL));
    DrawHorizontalLine(strL, true, i, Color.Yellow, DashStyle.Solid , 4) ;

    }

    for (i=y5 to y6)
    {
    strL = "Line" + i.ToString() ;
    // Add(new Line(new Pen(Color.Green,3), i, strL));
    DrawHorizontalLine(strL, true, i, Color.Green, DashStyle.Solid , 4) ;

    }

    This time NinjaTrader enters indefinite loop with 100% CPU utilization.
    }

    It seems, it's possible to use DrawRegion() , but I understand that in order to achieve the effect as in attached image, I should create 3 dummy data series and feed them with constant values in every bar. This approach seems to be resource consuming and I suspect there will be the same problem as described above with horizontal line, because I need to ensure DrawRegion is called only once in a particular bar.

    Did I misunderstand something ? Any other solution ? Thanks.
    Attached Files
    Last edited by xTrader1; 07-17-2009, 04:18 AM.

    #2
    xTrader1, correct for DrawRegion you would need two dataseries as region boundaries or one dataseries and a double value - http://www.ninjatrader-support.com/H...rawRegion.html

    I don't think you need to create your horizontal line with a unique tag for each bar if you work with DrawExtendedLine - http://www.ninjatrader-support.com/H...endedLine.html

    Comment


      #3
      Drawing lines

      Originally posted by NinjaTrader_Bertrand View Post
      xTrader1, correct for DrawRegion you would need two dataseries as region boundaries or one dataseries and a double value - http://www.ninjatrader-support.com/H...rawRegion.html

      I don't think you need to create your horizontal line with a unique tag for each bar if you work with DrawExtendedLine - http://www.ninjatrader-support.com/H...endedLine.html
      Much thanks for a quick reply.
      Could you comment what's wrong trying to create new line objects in OnBarUpdate() event, doing it only once ? I forgot to mention that in this case I received just an empty indicator display - probably an exception was thrown, I don't know about.

      What went wrong with DrawHorizontalLine that caused indefinite loop?


      Eventually a suggestion, I think an important one. Please provide an event OnParameterChanged() which will be fired when user changes indicator/strategy parameters. If there is something like that undocumented, please let me know. I'm not going to ask support regarding such issue.

      Comment


        #4
        xTrader1, you're welcome - there's nothing wrong with your lines creation in the OnBarUpdate() but I think your loop is not incrementing correctly and thus never ending, please see this link for the various available loop commands in NinjaScript - http://www.ninjatrader-support.com/H...gCommands.html

        Also: if you change parameters in your indicators and hit 'Apply' or 'Ok' the study will be recalculated based on your new inputs.

        If you can live without the region coloring the easiest for you would be to use a Plot in the Initialize() for your needed lines - http://www.ninjatrader-support.com/H...deV6/Plot.html

        For example like -

        Code:
         
        Add(new Line(Color.DarkGray, 80, "Upper2"));
        Add(new Line(Color.DarkGray, 70, "Upper1"));
        The y values for the lines are then adjustable under the 'Lines' paramter entry when you startup the indicator for display.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        606 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X