Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ChartControl.BackColor - can have some side-effects ?

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

    ChartControl.BackColor - can have some side-effects ?

    Hi,
    I have an indicator, that uses ChartControl.BackColor. This indicator
    makes some simple calculations and paints the candles on the chart.
    When it is used as an indicator - it woks without any problem.

    When I make some simple strategy, that uses this indicator mentioned above,
    the strategy fails, because the strategy and indicator bars are not in sync.
    (I call Update() correctly when accessing internal data, that is not source of the problem)
    That means, the indicator is not updated properly to be in sync with strategy.

    I have very curious problem (I spent half day to isolate to find the cause),
    where using ChartControl.BackColor causes the problem and replacing it
    with Color.Black (any color constant) removes the problem.

    This code causes failure:
    Code:
    BarColor = isRisingBar ? barColor : ChartControl.BackColor;
    This code works like a charm:
    Code:
    BarColor = isRisingBar ? barColor : Color.Black;
    I can reproduce it easily anytime.

    Do you have any idea, how can this be possible?
    Can it have some side effects?
    Last edited by misova; 12-08-2014, 06:32 AM.

    #2
    misova, when you run this code is there any error seen in your Control Center log tab? I would definitely add a proper check for null in before trying to access any property from the ChartControl.

    Comment


      #3
      Hi,
      I have attached totally minimalistic example of strategy & indicator.

      Steps to reproduce:
      1. Run the strategy (has no settings)
      2. It fails.
      3. Fix it by un/commenting lines 51-54 in indicator.
      4, Now you see the change.
      Attached Files

      Comment


        #4
        You are really right.

        ChartControl is not null - when indicator is used just on chart.
        and it is null in case, when indicator is used from strategy.

        Why is it null when inside indicator itself it works?
        OR
        How can I detect the background color of the chart from indicator safely?


        Indicator self is working correctly and it should not behave differently based
        on where it is used: placed on chart / or read from strategy.
        Last edited by misova; 12-08-2014, 08:12 AM.

        Comment


          #5
          Right, you will need that check for null for sure included before calling your Colorize bar.

          What are you trying to access from the indicator?

          If you want the strategy to call the indicator's visualizations make sure to Add() the indicator script.

          protected override void Initialize()
          {
          CalculateOnBarClose = true;
          BarsRequired = 0;
          Add(ProblematicIndicator());
          }

          Comment


            #6
            Thanks,

            for that part - where I need to see the visualization on backtested chart,
            this works excellently.

            This works great - visualizations are just added to the backtested chart.
            Code:
            protected override void Initialize()
            {
            Add(ProblematicIndicator());
            }
            Question 1:
            Do I understand it correctly, that all indicators attached to some chart have
            non-NULL ChartControl and all indicators not attached to the chart (used within strategy for their values) have it NULL?

            Question 2:
            Is there any elegant way how to distinguish, if any indicator as attached to some chart
            or just used in memory for calculations?

            Comment


              #7
              Originally posted by misova View Post
              Thanks,

              for that part - where I need to see the visualization on backtested chart,
              this works excellently.

              This works great - visualizations are just added to the backtested chart.
              Code:
              protected override void Initialize()
              {
              Add(ProblematicIndicator());
              }
              Question 1:
              Do I understand it correctly, that all indicators attached to some chart have
              non-NULL ChartControl and all indicators not attached to the chart (used within strategy for their values) have it NULL?

              Question 2:
              Is there any elegant way how to distinguish, if any indicator as attached to some chart
              or just used in memory for calculations?
              Yes, Just check if ChartControl is null and act accordingly.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 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
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X