Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rdtdale, Today, 01:02 PM
          0 responses
          2 views
          0 likes
          Last Post rdtdale
          by rdtdale
           
          Started by alifarahani, Today, 09:40 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by RookieTrader, Today, 09:37 AM
          4 responses
          18 views
          0 likes
          Last Post RookieTrader  
          Started by PaulMohn, Today, 12:36 PM
          0 responses
          7 views
          0 likes
          Last Post PaulMohn  
          Started by love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          41 views
          0 likes
          Last Post love2code2trade  
          Working...
          X