Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to draw line with plot and give it a value?

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

    How to draw line with plot and give it a value?

    Dear support
    I created a simple indicator it is a simple line that starts 10 bars ago and is at the height of this one


    but I would like to use plot to create this indicator


    1. Is there a way to stretch the line to the future without using time?


    in this example

    2. how to draw this line with plot?
    3. what is the value of this plot because i want to use it in the strategies builder?

    Many thanks.


    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyCustomIndicator";


    BarsAgo = 10;

    AddPlot(new Stroke(Brushes.Orange, 2), PlotStyle.Dot, "MyLine");
    }



    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {


    if (CurrentBar < 60)
    return;


    Draw.Line(this, "MyLine" , true, BarsAgo, High[BarsAgo] , 0, High[BarsAgo] , Brushes.Red, DashStyleHelper.Dot, 4);

    }

    #region Properties
    [NinjaScriptProperty]
    [Display(Name="BarsAgo", Order=1, GroupName="Parameters")]
    public int BarsAgo
    { get; set; }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> MyLine
    {
    get { return Values[0]; }
    }
    #endregion




    Last edited by aekzof; 03-28-2022, 06:47 AM.

    #2
    Hello aekzof,

    Thanks for your post.

    Instead of a Line drawing object, you could consider using a Ray drawing object to "project" the line into the future.

    For example, you could set the start point BarsAgo value to 1 and the end point BarsAgo value to 0 when calling Draw.Ray().

    See this help guide for more information about working with Draw.Ray: https://ninjatrader.com/support/help...8/draw_ray.htm

    "what is the value of this plot because i want to use it in the strategies builder?"

    Currently, in the code you shared the plot does not contain a value since you have not assigned a value to the plot. You would first need to assign a value to the plot using Value. For example, Value[0] = Close[0]; would set the plot value to be the current Close price.

    See this help guide for more information about working with plots: https://ninjatrader.com/support/help...t8/addplot.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you for your reply
      Precisely that's what I can't understand the value of the plot.

      the goal of this line is when price breaks this line from above and below

      Value[0] = signal1
      signal1 = condition (when price breaks the line)

      I don't know if that's right

      Comment


        #4
        Hello aekzof,

        Thanks for your note.

        You would need to assign a value to the plot for the plot to contain a value. Note that you can only assign values such as int values and double values to a plot. You cannot add a condition to a plot.

        For example, if you have a double variable called "signal1" and that variable holds a value of say Close[0], you would then apply that variable to the plot. See below.

        Code:
        private double signal1; //class level variable.
        
        protected override void OnBarUpdate()
        {
            //assign a value to the signal1 variable
            signal1 = Close[0];
        
            //assign the signal1 variable to the plot
            Value[0] = signal1;
        }
        Please see the sample code in the AddPlot() help guide page to see how a value could be assigned to the plot using Value[].

        AddPlot: https://ninjatrader.com/support/help...t8/addplot.htm
        Value: https://ninjatrader.com/support/help...nt8/value.htm\

        You could also work through the Developing Indicators tutorials to better understand how to create indicators.

        Developing Indicators: https://ninjatrader.com/support/help...indicators.htm

        Let us know if we may assist further.
        Last edited by NinjaTrader_BrandonH; 03-28-2022, 08:38 AM.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Thank you .

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          639 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          572 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X