• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Generic classes, runtime error

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

    Generic classes, runtime error

    Hello,
    I want to use help-classes/generic classes when developing indicators. I have not found out a recommended way to do this within Ninjatrader environment, so my approach is to use generic classes as “help-indicators”. I will be thankful if anyone in the forum can recommend other ways of using generic classes 

    I run into problem when my “help-indicator” ( public class GetChartControlData : Indicator ) is called from my indicator ( public class ClickEvent : Indicator).

    The help-indicator will return some Chartpanel and ChartControl values:

    Code in help-indicator:
    if ((indicatorObj.ChartPanel != null) && (indicatorObj.ChartControl != null))
    {
    Print(indicatorObj.ToString());
    MinX = indicatorObj.ChartPanel.X;
    MaxX = MinX + indicatorObj.ChartPanel.W;
    MinY = indicatorObj.ChartPanel.Y;
    MaxY = MinY + indicatorObj.ChartPanel.H;
    Height = (int) indicatorObj.ChartControl.AxisXHeight;
    }
    (the last line “Height = … “ compile, but gives a runtime error: “Indicator 'ClickEvent': Error on calling 'OnBarUpdate' method on bar 0: The calling thread cannot access this object because a different thread owns it.” If I remove this line, everything works fine …)


    The help class is used like this in my “main-indicator”:

    private GetChartControlData GetChartControlData_Obj; // at variable decl

    GetChartControlData_Obj = new GetChartControlData(this); // at State.SetDefaults

    GetChartControlData_Obj.GetData(); // at OnBarUpdate()


    1. How should I do to avoid the runtime error?
    2. Any ideas of different ways of using generic classes?

    Thank you, AndBro, using: 8.0.0.11 64-bit (Multi-Broker) - BETA

    #2
    Hello AndBro,

    You can use the Addon folder and namespace (or use the Indicator namespace from a file in the Addon folder) to have classes used in multiple scripts.

    Below is a link to a thread where I have posted an example using static classes in an Addon.
    http://ninjatrader.com/support/forum...980#post442980

    You need to use the dispatcher of the chart and invoke into the thread of the chart to make any changes to the chart or get information about the chart.

    Below is a link to the help guide on Multi-Threading Consideration for NinjaScript.
    http://ninjatrader.com/support/helpG...-threading.htm

    Attached is an example I've made that changes the quantity in the ChartTrader area when a button is clicked. Invoking is necessary to add the buttons, and when the button is clicked to change the chart.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello AndBro,

      You can use the Addon folder and namespace (or use the Indicator namespace from a file in the Addon folder) to have classes used in multiple scripts.

      Below is a link to a thread where I have posted an example using static classes in an Addon.
      http://ninjatrader.com/support/forum...980#post442980

      You need to use the dispatcher of the chart and invoke into the thread of the chart to make any changes to the chart or get information about the chart.

      Below is a link to the help guide on Multi-Threading Consideration for NinjaScript.
      http://ninjatrader.com/support/helpG...-threading.htm

      Attached is an example I've made that changes the quantity in the ChartTrader area when a button is clicked. Invoking is necessary to add the buttons, and when the button is clicked to change the chart.
      The way that your code is written means that it will probably be subject to the spurious termination events as described in this thread.

      ref: http://ninjatrader.com/support/forum...ad.php?t=83608

      Comment


        #4
        ChelseaB: Thank you for a fast reply. I will read your links carefully, and rewrite my code.
        I’m very impressed that the customer service team are so quick and patient in communication with NT users. Very good 

        Koganam: Thank you for pointing out the “mystery” of an objects lifecycle in the NT world. I have not yet enough experience of this subject. However, I have seen strange things in my output window.
        - I still get a trace-print, from an indicator that no longer exists. No files, nothing, and everything is deleted … somehow, I’m afraid that object is still alive 
        - I got a warning (Visual Studio) that I have a conflict with “@AndrewsPitchfork.cs”. I don’t remember if it was a compile or a run time error.It was something about Line ??? (I have never touched anything about @AndrewsPitchfork.cs).
        Anyway, I have not payed much attention to this yet. I tell you just for information.

        Comment


          #5
          Hi AndBro,

          Sometimes a file can end up in the wrong folder and make the print / log calls hard to find.
          Other times, they can be buried in regions.

          I'm happy to assist and look for the script causing the print. If you would like to schedule a call please send an email to platformsupport [at] ninjatrader [dot] com. In the email please include a link to this forum thread.

          With the visual studio warning, this could mean that a file is missing or has been replaced by a different version or may just be warning that a class being called is ambiguous.

          Do you get the same error in NinjaTrader's NinjaScript Editor?
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by reedstickets, Today, 07:53 PM
          0 responses
          5 views
          0 likes
          Last Post reedstickets  
          Started by Atilla, Today, 04:05 PM
          0 responses
          17 views
          0 likes
          Last Post Atilla
          by Atilla
           
          Started by Displacer, Today, 02:57 PM
          2 responses
          13 views
          0 likes
          Last Post Displacer  
          Started by SAILIKITY, 05-22-2019, 05:41 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by rmillar, 01-09-2019, 06:02 PM
          6 responses
          75 views
          1 like
          Last Post eDanny
          by eDanny
           
          Working...
          X