Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to change chart background color from strategy?

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

    How to change chart background color from strategy?

    Hello.

    To change chart background color (and bar colors) from indicator I this simple way, that works perfectly:

    PHP Code:
    if( ChartControl != null && Bars != null )
    {
        ChartControl.Properties.ChartBackground =  System.Windows.Media.Brushes.Black;
        ChartBars.Properties.ChartStyle.UpBrush   = WmBrushes.Violet;
    } 
    


    But, in strategies, this way work from time to time (I tied to use it in all States, and in OnBarUpdate() method.
    In one of my strategies it don't work at all.

    Is there another [more correct] way to do it from strategy [and, may be, from indicator]?
    Last edited by fx.practic; 08-06-2017, 03:25 PM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    SOLVED:

    Manual, Best Practices
    "For objects which exist on the UI (e.g., ChartControl, ChartPanel, ChartBars, NTWindow, etc.) wait until the State has reached State.Historical. This practice is correct for both reading properties or should you wish to add custom elements to the existing UI."

    In hosted indicator specified code must be placed in State.Historical
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    Comment


      #3
      Still have problem to change background color when strategy run in StrategyAnalyser.
      Can't change color, even, from OnBarUpdate()

      Need good advice, please!
      Attached Files
      Last edited by fx.practic; 08-07-2017, 02:50 AM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Hello fx.practic,

        When using the Strategy Analyzer the ChartControl object is null.

        From the help guide:

        "Note: The ChartControl object is ONLY guaranteed to be available when a NinjaScript type initiates from a Chart Window. There are situations where an indicator or strategy starts from another Windows (such as the Control Center's Strategies Grid, or from a Strategy Analyzer), where the ChartContol object is NOT accessible. Therefore, the ChartControl object should always be safely accessed (e.g., from within a try-catch, or conditionally using null reference checks)"
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank You.
          I start to remember this part of manual while reading Your answer.
          Thank You, sorry for the question.

          NT8 manual is like Saint Book - I should read it again and again...
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          50 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          126 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X