Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Turn On and Off Plot

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

    Turn On and Off Plot

    I am trying to turn on and off a plot by using a true/false statement. This is what I have:

    #region Variables

    private bool showplot = true;
    private Color defaultColor = Color.Transparent; // to make line Blank initially but is overridden by showplot = true which sets it to Red.

    protected override void Initialize()
    {

    if (showplot)
    {
    defaultColor = Color.Red; // to turn on line with Red Color
    }
    else
    {
    defaultColor = Color.Transparent; // to turn off line with Transparency
    }

    Add(new Plot(new Pen(defaultColor, 3), PlotStyle.Line, "MyPlot"));

    When I compile there are no errors, so where am I going wrong?
    When I load the indicator the plot lines come on as Red which tells me the first part of the "If" statement is working ok.
    When I change showplot to False, the red lines should be gone by turning Transparent, but nothing happens and the Red lines stay on the chart.

    What am I missing here?

    Thanks
    Last edited by velocity; 11-28-2009, 10:43 PM.

    #2
    The Initialize function is called only once per Strategy instance (at load time)...so I think the problem is, you can't dynamically toggle inside of Initialize.

    Right now, your code will just set it to Red, and never change, since Initialize will never be called again.

    You would want to toggle inside of OnBarUpdate or some other spot that is frequently called to give you the dynamic toggling that you are after.

    Hope that helps

    Comment


      #3
      I figured it out as follows

      protected override void OnBarUpdate()
      {

      if (showplot)
      {
      Plots[0].Pen = new Pen(Color.Red);
      }
      else
      {
      Plots[0].Pen = new Pen(Color.Transparent); // to turn off line with Transparency
      }


      Thanks for taking a look.
      Last edited by velocity; 11-29-2009, 06:38 AM.

      Comment

      Latest Posts

      Collapse

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