Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

variable line level in panel of strategy

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

    variable line level in panel of strategy

    Hi all,

    I am trying to display a level or HorizontalLine in an indicator panel in a strategy. The level is to be changed from within the strategy.

    I am using the ConstantLines indicator to draw the level in the panel.

    However, when I try to adjust the line level from the strategy the line does not visibly change, except when the strategy is restarted.

    Where rThreshold holds the level to be displayed, the code in the strategy is

    ConstantLines(rThreshold, 0, 0, 0).Line1Value = rThreshold;

    This changes the Line1Value of the indicator.

    In the ConstantLines indicator we have

    protected override void OnBarUpdate()
    {
    if (Line1Value != 0) Line1.Set(Line1Value);

    ......

    so, on each bar update, the plotted level ( Line1 series) of the line should reflect the value in Line1Value.

    However it does not. I have searched other threads and tried all the solutions I have found but none have worked so far. Has anyone a definite solution?

    #2
    Hello,

    Thank you for the question.

    If you are trying to update the indicator from the strategy this may not work as you have found,
    I would like to ask is it needed that you use the ConstantLines indicator?

    If not you can draw a horizontal line directly from the strategy and update it as needed.

    Here is an example of using a drawing object in code that can be updated

    Code:
    private IHorizontalLine horizontalLine;
    protected override void OnBarUpdate()
    {
         horizontalLine = null; 
         horizontalLine = DrawHorizontalLine("Test", Close[0], Color.Red);
    }
    You should be able to just update the value without using the null, I add the null in to clear the prior line completely before drawing the new line to ensure it is refreshed.


    Please let me know if I may be of additional assistance.

    Comment


      #3
      Hi Jesse,

      Thank you for your quick reply.

      Firstly, no ConstantLines is not essential.
      Your solution would indeed work for drawing a line on the chart. However I need the line in an indicator panel.
      I have buttons on the chart to manually adjust a threshold level for an indicator in the running strategy. On pressing a button the new level is currently passed to the ConstantLines indicator variable Line1Value. During OnBarUpdate this value should set for the new Plot value for the Line1 series.

      The ideal solution would plot the threshold values actively but any horizontal line would do at a pinch.
      Last edited by ManicMonk; 09-24-2014, 02:54 PM.

      Comment


        #4
        Hello,

        If you need to specify a drawing panel you can or if you want to use the indicators panel you can.

        The most simple approach is to use the following inside the indicator that needs to plot in its own panel
        Code:
        protected override void Initialize()
        {
             DrawOnPricePanel = false;
        }
        This prevents the indicators drawn objects from appearing on panel 0 or your chart but rather in the panel they were added.

        If you do not get the desired result using that, you could try to use the Plotting from a strategy example located here:
        When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


        This allows you to call any indicators of your choosing and specify what panel they go into from code. Each indicator would need to have the DrawOnPricePanel false for this to work as well .


        Please let me know if I may be of additional assistance.

        Comment


          #5


          Thank you Jesse.

          That link to SampleStrategyPlot did the trick. I had tried something similar already but the trick is in the detail. Just one minor difference was the problem.

          Problem solved.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X