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

Add indicator line with configurable level

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

    Add indicator line with configurable level

    Is it possible to add a horizontal line to an indicator with:

    Add(new Line(Color.Gray, SetLevelVar, "whatever"));

    where it is possible to configure the level in SetLevelVar through the Indicator parameters?

    Since the Add() function much be called in Initialize() I am not finding how I can change this variable and plot the line at different levels.

    #2
    I assume you mean you want to change the level dynamically by passing different parameters to your indicator on each bar. Correct?

    To change it dynamically, I would write

    Whatever.value = newvalue;

    but you need to make sure that there's an entry for "Whatever" in your indicator properties section.

    For me, an easier way would simply be to use DrawLine(). The first time you call it, it creates a line. The second time you call it with the same identifier, it simply moves the line to the new location you set.

    -Alex

    Comment


      #3
      Not quite..

      I want to configure horizontal lines in an indicator based on input in the Parameters dialog box.

      Depending on the instrument I am trading, I may be looking for the oscillator or plot to reach a different level. I want to be able to configure that in the parameters dialog box. From what I have working now, it is not possible to change the level since the Add() function is called in Initialize().

      As I type, it does not make sense that I need this in OnBarUpdate(), but the lines are being created in Initialize() and the system throws an error if I try to create the lines in OnBarUpdate().

      Comment


        #4
        Well, the first time you load an indicator into a chart, the parameters box shows you options for the line levels you want. However, once, set, you can't change them. I tried this in one of my indicators:

        (intitialize)
        Add(upperline = new Line(System.Drawing.Color.Silver, 55, "Upper"));

        and then I set upperline.Value to some other value and nothing happened. It didn't matter if I set this on every bar in OnBarUpdate() either.

        As I said before, your best bet is to call DrawLine() in OnBarUpdate like this:

        DrawLine("MyLine", CurrentBar-1, linevalue, 0, linevalue, Color.Gray, DashStyle.Solid, 1);

        Linevalue is your parameter. If you call that on every bar, the line should always update its length to span all the bars.

        -Alex

        Comment


          #5
          Sample of This "DrawLine" indicator

          Have either of you been able to make a sample of this indicator that the rest of us can test along with you?

          Please post and let us know your findings.

          KZ

          Comment


            #6
            Not sure I understand your question entirely, but here is what I did to get to a point where I can draw lines in an indicator that have configurable "levels" on the y-axis.

            Initialize () {
            DrawOnPricePanel = false;
            }

            OnBarUpdate() {
            DrawHorizontalLine("TagName", false, AxisLevel, Color.Yellow, DashStyle.Dot, 1);
            }

            The only downside to this method is that the lines are selectable and moveable.
            (or a feature...) :-)

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            5 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            5 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            3 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by GwFutures1988, Today, 02:48 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X