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

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
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mongo, Today, 11:05 AM
        0 responses
        1 view
        0 likes
        Last Post Mongo
        by Mongo
         
        Started by Tim-c, Today, 10:58 AM
        0 responses
        1 view
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by traderqz, Yesterday, 09:06 AM
        3 responses
        22 views
        0 likes
        Last Post NinjaTrader_ThomasC  
        Started by f.saeidi, Today, 10:19 AM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by kujista, Today, 06:23 AM
        5 responses
        18 views
        0 likes
        Last Post kujista
        by kujista
         
        Working...
        X