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

Set chart background in code

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

    Set chart background in code

    Hi.

    I'm trying to set the chart background in code (strategy). I create a brush and apply it inside OnRender() as below but nothing happens.

    ChartControlProperties myProperties = chartControl.Properties;
    myProperties.ChartBackground = myBrush;

    Is there a code example somewhere?

    I need it in realtime rather than historical, if it makes a difference.

    Thanks.

    #2
    Hello digibob,

    I see that our example shows changing these properties in OnRender(). That is very inefficient especially for the property being set in the example.

    I've noted our developers about this.
    I do not recommend that you try and change the ChartBackground in OnRender() if you can avoid it in any way, unless you are wanting to be able to change the color several times a second on each render pass.


    Attached is an example that changes the background in real-time.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea. I was hoping actually to avoid using OnRender(). That's exactly what I need. Many thanks.

      Comment


        #4
        Hello!!
        I want to flip from CrosshairType.Off to CrosshairType.Local but had no success.



        any advice how to achieve it??
        Thank you!!!

        Comment


          #5
          Hello efeuvejota01,

          Thanks for your note.

          You could set the CrosshairType by calling chartControl.CrosshairType within the OnRender() method in a NinjaScript.

          The sample code below demonstrates how to set the CrosshairType to Local.

          Code:
          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {
              //Set crosshair type to local
              chartControl.CrosshairType = CrosshairType.Local;
          
              //Print out the current crosshair type
              Print("CrosshairType: " + chartControl.CrosshairType.ToString());
          }
          See this help guide documentation for more information about CrosshairType: https://ninjatrader.com/support/help...sshairtype.htm

          Let me know if I may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            thank you!! let me try...
            worked perfecly!!

            Thank you!!

            Comment


              #7
              it also work as shown in the attached code...


              Code:
               protected override void OnBarUpdate()
              {
              if (State != State.Realtime)
              return;
              this.Dispatcher.InvokeAsync(() =>
              {
              if (flip)
              { //ChartControl.Properties.CrosshairCrosshairType = CrosshairType.Off;
              ChartControl.CrosshairType = CrosshairType.Off;
              Print("uno");}
              else
              { //ChartControl.Properties.CrosshairCrosshairType = CrosshairType.Local;
              ChartControl.CrosshairType = CrosshairType.Local;
              Print("dos");}
              });
              flip = !flip;
              }

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 05:00 AM
              0 responses
              5 views
              0 likes
              Last Post PaulMohn  
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              5 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              2 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              16 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              3 views
              0 likes
              Last Post DanielTynera  
              Working...
              X