Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multi-threading problem? Scales[0]

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

    multi-threading problem? Scales[0]

    Hello, I have problem to access ChartControl.ChartPanels[0].Scales[0] .GetValueByY(y)

    In my class I need to use theObj.Dispatcher.InvokeAsync to get a valid ChartControl which is not null. That works fine.

    However, having the ChartControl I then need to use the function GetValueByY, and that means access the scale by using ChartControl.ChartPanels[0].Scales[0] … Here is the problem! Scales[0] is null (ChartPanels[0] is valid).

    I guess this is a multi-threading problem. If so, can anyone tell me how to the dispatcher/invoke code will look like to get a valid scale.

    Thank you, AndBro

    #2
    Hello AndBro, and thank you for your query.

    After testing with the attached script, I have determined that Indicator.ChartControl.ChartPanels[0] properties are only going to be visible once this panel has been physically drawn to your screen, and is only going to be available to the chart thread itself. The only reliable place to access this is from the indicator itself.

    Given this, I recommend storing this value during OnBarUpdate and exposing the stored value, rather than calling for Scales[0] directly.

    Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Hello Jessica, thank you for quick reply and your effort to find an answer. I will try your suggestion in my code.

      First, I want my indicator to work. After that, I will evaluate my indicator design to see how far away it will be from my original ideas. So far, I have a feeling that doing coding “outside” the indicator, very often generates problems, which you usually never step into in more “normal” C# programming.

      I will let you know in a few weeks.

      Thank you /AndBro

      Comment


        #4
        Still problem … ChartControl.ChartPanels[0].Scales[0].GetYByValue

        Hello Jessica,
        Still problem … Even I try to access the scale within my indicator at OnBarUpdate(), I can’t get a value other than null!

        This is my indicator: (file is attached)

        protected override void OnBarUpdate()
        {
        Print(String.Format(" at OnBarUpdate, CurrenBar is: {0}", CurrentBar));
        if (ChartControl.ChartPanels[0].Scales[0] != null)
        {
        Double max = ChartControl.ChartPanels[0].Scales[0].MaxValue;
        Print(String.Format(" y for maxvalue is: ",
        ChartControl.ChartPanels[0].Scales[0].GetYByValue(max)));
        }
        else
        {
        Print("no scale ... ");
        }
        }

        1. Please, let me see a working code of GetYByValue. (I can’t find any other way to do this, other then using Scales[0]. Am I right?)

        Thank you/AndBro
        Attached Files

        Comment


          #5
          Hello AndBro,

          Please take a look at the example code given for GetYByValue() in the help guide: https://ninjatrader.com/support/help...etybyvalue.htm

          The example code shows how you can get the value returned by GetYByValue() by using the OnRender() method: https://ninjatrader.com/support/help.../?onrender.htm

          You will need to ensure that the indicator is placed in the same panel as your chart's input series or you will not be obtaining values based on the scale of the price panel.

          Please, let us know if we may be of further assistance.
          Zachary G.NinjaTrader Customer Service

          Comment


            #6
            Hello ZacharyG, I think you replied to quick now  My problem is that I can’t get any ChartScale object at all! I cannot wait for “something” to call OnRender, just to pick up a ChartScale object (maybe I will do that as a very-very provisional solution, but this is a crazy way of programming ...)

            1. Due to Ninjahelp-doc it is possible to get the ChartScale object by the chain ChartControl.ChartPanels[0].Scales[0], but that doesn’t work in any situation. If you find a situation where that expression works, please let me know.

            Once I have the ChartScale object, I can of course easily call GetYByValue.

            Is it a beta8-bug that you never can get a ChartScale object?

            Thank you, AndBro

            Comment


              #7
              Hello AndBro,

              You would actually want to be using Scales[ScaleJustification.Right] rather than a Scales[0].

              Please, let us know if we may be of further assistance.
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Thank you ZacharyG and other I customer service. Works very well now 

                Maybe it is a good idea to show this in help section:

                ChartControl.ChartPanels[0].Scales[ScaleJustification.Right].Height // works fine
                ChartControl.ChartPanels[0].Scales[0].Height // complie OK, but run-time error

                Thank you/AndBro

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by aa731, Today, 02:54 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by BarzTrading, Today, 07:25 AM
                0 responses
                2 views
                0 likes
                Last Post BarzTrading  
                Started by i019945nj, 12-14-2023, 06:41 AM
                5 responses
                65 views
                0 likes
                Last Post i019945nj  
                Started by ruudawakening, Today, 12:58 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by thread, Yesterday, 11:58 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X