Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

State.Terminated - RC2

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

    State.Terminated - RC2

    State.Terminated
    Terminated is called once when the object terminates.
    • Notify the object is shutting down
    • Use to clean up/dispose of resources

    I found that after State.Terminated in OnStateChange() NT calls OnRender() method BEFORE OnRenderTargetChanged() and BEFORE any other calls to OnStateChange() with State.Configure!

    So if anyone would follow your help guide "Use to clean up/dispose of resources" indicator or strategy will crash.

    Any comments?

    Here is my debug log of what hapenned during placing indicator on clean chart
    WHY NT8 SETS STATE TO Terminated before putting it on chart???!

    STATE: SetDefaults
    STATE: SetDefaults
    STATE: Terminated 10.513 sec
    STATE: SetDefaults
    STATE: Configure 0.6 sec
    STATE: DataLoaded 0.11 sec
    STATE: Historical 0.11 sec
    OnRenderTargetChanged - creating graphics
    STATE: Terminated 5.166 sec
    IBStopPrice 2159,25, CurrentBar = 7
    STATE: Transition 0.789 sec
    STATE: Realtime 0.789 sec
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end
    OnRender - start
    OnRender - end


    code

    Code:
            protected override void OnStateChange()
            {
    #if DEBUG
                    if (startTime > DateTime.MinValue)
                        Print(string.Format("STATE: {0} {1}.{2} sec", State, DateTime.Now.Subtract(startTime).Seconds, DateTime.Now.Subtract(startTime).Milliseconds));
                    else
                        Print(string.Format("STATE: {0}", State));
    #endif
    ...
    PS
    My code is in extrenal dll
    Last edited by ren37; 11-11-2016, 01:03 PM.

    #2
    Hello,
    Thank you for the post.

    Terminated is called multiple times before the instance you see on the chart appears, this depends on the menus used and would be expected.

    Regarding OnRender being called before OnRenderTargetChanged, the prints you have provided seem to show the reverse or OnRender being called after OnRenderTargetChanged which is the output I would expect.

    STATE: Configure 0.6 sec
    STATE: DataLoaded 0.11 sec
    STATE: Historical 0.11 sec
    OnRenderTargetChanged - creating graphics
    STATE: Terminated 5.166 sec
    IBStopPrice 2159,25, CurrentBar = 7
    STATE: Transition 0.789 sec
    STATE: Realtime 0.789 sec
    OnRender - start

    If you are questioning the terminate that is coming after the render target change, this is likely one of the other instances used from the menu, is this what you are referring to as "before" rendertarget assuming the life cycle had started over at Terminated?

    If so, you could print a unique id to see which instance this is referring to, for example using the following print I can see the output as follows:

    Code:
    Print(State + " " + GetHashCode());
    SetDefaults 24059172 //indicator menu opened
    SetDefaults 30968385 //indicator double clicked to drop to lower list
    Terminated 24059172 // ok has been clicked
    SetDefaults 44458770
    Configure 44458770
    DataLoaded 44458770
    Historical 44458770
    Transition 44458770
    Realtime 44458770

    RenderTargetChange 44458770
    Terminated 30968385
    OnRender 44458770
    OnRender 44458770
    Are you seeing a specific error occurring in the script related to changing states?


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello Jesse

      You are right, instance Id now makes it clear.
      I got this errors sometimes. Some people have no errors at all:

      Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'HRESULT: [0x88990016], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_PUSH_POP_UNBALANCED/PushPopUnbalanced]

      Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error =
      'Object reference not set to an instance of an object.'

      Comment


        #4
        But this is what I have found

        42698199 STATE: Configure 2.66 sec
        42698199 STATE: DataLoaded 2.99 sec
        42698199 STATE: Historical 2.99 sec
        42698199 OnRenderTargetChanged - creating graphics
        42698199 STATE: Transition 3.310 sec
        42698199 STATE: Realtime 3.310 sec
        42698199 OnRender - start
        42698199 OnRender - end
        42698199 OnRender - start
        42698199 OnRender - end
        42698199 OnRender - start
        42698199 STATE: Terminated 24.863 sec
        Indicator 'MyIndicator': Error on calling 'OnRender' method on bar 0: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments]

        39123013 STATE: SetDefaults
        39123013 STATE: Configure 0.17 sec
        39123013 STATE: DataLoaded 0.20 sec
        39123013 STATE: Historical 0.20 sec
        39123013 OnRenderTargetChanged - creating graphics
        39123013 STATE: Transition 0.966 sec
        39123013 STATE: Realtime 0.966 sec
        39123013 OnRender - start
        39123013 OnRender - end

        As you can see State.Terminated event triggers before OnRender() ends!

        Comment


          #5
          Hello,

          Thank you for the extra details,

          What was the set of steps required to see this output, this appears to be different than the first output you had provided.

          Mainly I see two items, one being the times taken until termination. The time I see you have printed is quite a bit further out than the original post:

          24.863 sec
          5.166 sec

          Also the events seem to have changed, in the first post you had received what I had expected, in this case I can see the Termination print happening in the middle of the OnRender prints.

          Potentially this is a side effect of the error or some logic being executed, the error specifically is saying that on bar 0, the script encountered an error with a null object from OnRender. Something being used was null causing an exception.

          At this point have you tried to isolate what specific syntax that may be causing this to better identify what may be happening? If not, I would suggest to try and find a situation where this happens more often than not, and from that situation reduce the code until you are no longer to see this happen. This would give you a good baseline on what syntax is the root cause.

          Without knowing what is being done in the logic, describing what the error could be would really be the only information I could provide at this point until we know more about what syntax is throwing the exception.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TraderBCL, Today, 04:38 AM
          2 responses
          16 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          106 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          609 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          5 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X