Announcement

Collapse
No announcement yet.

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 toughiee, Today, 12:04 AM
            0 responses
            2 views
            0 likes
            Last Post toughiee  
            Started by vdoan20, Yesterday, 08:30 PM
            0 responses
            6 views
            0 likes
            Last Post vdoan20
            by vdoan20
             
            Started by gupagoer, Yesterday, 07:42 PM
            0 responses
            9 views
            0 likes
            Last Post gupagoer  
            Started by Holligoly, Yesterday, 05:13 PM
            2 responses
            11 views
            0 likes
            Last Post Holligoly  
            Started by Raginpower, Yesterday, 01:53 PM
            0 responses
            14 views
            0 likes
            Last Post Raginpower  
            Working...
            X