Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

one event and more log/print

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

    one event and more log/print

    Hello,

    I would have question to the support. Below there are two sample codes, which do the following:
    • At all OnBarUpdate, it changes the value of static property of the static ClassOne.
    • ClassTwo, in its own constructor, subscribes the event of ClassOne PropertyChanged.
    • I define ClassTwo in the strategy.
    The difference between the two codes:
    • A TESTEventTrace1: it defines ClassTwo like this in the strategy
    Code:
    private ClassTwo cl2;
    protected override void OnBarUpdate()
    {
       if (cl2 == null)
          cl2 = new ClassTwo();
     
       // ... code
    }
    • A TESTEventTrace2 it defines ClassTwo like this in the strategy
    Code:
    private ClassTwo cl2 = new ClassTwo();
    The difference betweewn the two results (see the screenshots):
    • TESTEventTrace1:it works correctly and log
    • TESTEventTrace2: the event runs once (see the value of Counter), but writes it to more times.
    My questions: why does the class definition in TESTEventTrace2 incorrect like this? Why does the event write it to more times? What do I misununderstand in the operation of NT strategy (like class)?

    (Sorry, if i were too long, but it took 1 day to find not to write it to more times, but i still do not understand the reason.)

    Thanks in advance,
    Attached Files
    Last edited by tamas; 10-02-2009, 11:13 AM.

    #2
    tamas, if I follow correctly you attempt to cross communicate with two strategies - this is unfortunately not supported.

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      tamas, if I follow correctly you attempt to cross communicate with two strategies - this is unfortunately not supported.
      Bertrand, you dont follow me correctly. I did not say that the two strategies communicate cross.

      These are the same strategies, i wrote down what are the difference. This is simple event handler. Please read again, thanks

      Comment


        #4
        tamas,

        Unfortunately we do not support creation of classes and these C# concepts. We can only support the extent of NinjaScript. Hopefully more advanced community members here can help you out with these C# questions.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          for advanced users: one event and more log/print

          Originally posted by NinjaTrader_Josh View Post
          Unfortunately we do not support creation of classes and these C# concepts. We can only support the extent of NinjaScript. Hopefully more advanced community members here can help you out with these C# questions.
          Advanced Users the summary:

          If i create class in the strategy with early binding, the strategy will create more logs for one event. I think it is not correct. Maybe wrong work.

          If i create class in the strategy with late binding, the strategy will create one log for one event. But in this case the property of instance of class can not be set in Initialize method.

          (Josh, Bertrand: many times i feel that it is unnecessary to ask questions, because if the question is not one simple sentence, then the answeres are "not supported" or "not supported" and/or "not supported". I didnt ask support for C#. I didnt ask "how to create class" or "what is the static class" and/or "how to create and subscribe to event". NT is good beacause, i can coded it in C#. This would be the point, would not this? What i would like, i coded. It had strange working in strategy. I didnt ask help for C#, but why does strategy work in two different ways, if i create instance of class, if binding mode are different (early or late)? Thats all. Sorry for my oppinion, but it is confused, that a well prepared question with sample codes, screenshots are got template answeres.)

          Comment


            #6
            tamas,

            We can only cover the basic usage model of NinjaScript. You have already moved beyond that and are working outside of the scope of what we can support. Unfortunately we just can't cover these programming concepts. We can only cover the basics of scripting. Thank you for understanding.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Tamas,

              things are getting more obvious if you define a unique ID for your test class:

              private static int counter;
              private int myID = counter++;

              Print myID in both Initialize() and OnBarUpdate(). Then you can see, how often your test class is instantiated by the system and which of these instances survive and reach OnBarUpdate(). That finally could/should explain your observation.

              Regards
              Ralph

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                tamas,

                We can only cover the basic usage model of NinjaScript. You have already moved beyond that and are working outside of the scope of what we can support. Unfortunately we just can't cover these programming concepts. We can only cover the basics of scripting. Thank you for understanding.
                OK, i understand

                Comment


                  #9
                  Originally posted by Ralph View Post
                  things are getting more obvious if you define a unique ID for your test class:

                  private static int counter;
                  private int myID = counter++;

                  Print myID in both Initialize() and OnBarUpdate(). Then you can see, how often your test class is instantiated by the system and which of these instances survive and reach OnBarUpdate(). That finally could/should explain your observation.
                  Hello, i will check ...

                  Comment


                    #10
                    Originally posted by Ralph View Post
                    Print myID in both Initialize() and OnBarUpdate(). Then you can see, how often your test class is instantiated by the system and which of these instances survive and reach OnBarUpdate(). That finally could/should explain your observation.
                    Hello Ralph,

                    thanks your answer, it was good idea. It is clearly seen that more instance of class are generated by system. There are some wich dont survive, but more then 1 instance will be.

                    I see that instances are generated, when it gets the strategies (like when choose on the GUI, etc.) I have tried more than 20 solutions and what gets in to my mind, but none of them are good.

                    Is this problem can be solved, at all? (If i use my CustomClass, and that will get event from another class, then that has to run once in one instance in my strategy.)

                    Is it possible not to have more than one instance in my stategy?

                    Is there any soulition or am i muddle?

                    Comment


                      #11
                      Originally posted by tamas View Post
                      ...but more then 1 instance will be...
                      Hi Tamas,

                      I don't think so, my experience says that only one instance survives the initial phase.

                      Unless you prove the opposite, of course

                      Regards
                      Ralph

                      Comment


                        #12
                        Originally posted by Ralph View Post
                        I don't think so, my experience says that only one instance survives the initial phase.

                        Unless you prove the opposite, of course


                        As i see it now the problem could be that, i did not unsibscribe from my class event of my static class ... it seems to be like this

                        Comment


                          #13
                          Hi Tamas,

                          I evaluated custom event handling for indicators some time ago and implemented a standard approach: (1) Init the custom events on the first tick of the first bar, like you do in your first example file, (2) Shutdown the event handling in Dispose(). I don't use anything different, because is appeared unpredictable to me.

                          Regards
                          Ralph

                          Comment


                            #14
                            Originally posted by Ralph View Post
                            I evaluated custom event handling for indicators some time ago and implemented a standard approach: (1) Init the custom events on the first tick of the first bar, like you do in your first example file, (2) Shutdown the event handling in Dispose(). I don't use anything different, because is appeared unpredictable to me.
                            Yes, yes, i did exactly this ... i will post sample code, i hope it will be usefull the others (it was hard to figure out and test)

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            647 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            369 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            572 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X