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

Plot inside c# async Callbacks or Task.Run

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

    Plot inside c# async Callbacks or Task.Run

    Hi,

    I do calculation outside of NJ8 and would like to plot bars as soon as results are available. Therefor I use async functionality from .Net. Unfortunately I can’t plot anything from the callback and receive an error message saying that the index is out of range.

    How can I plot something inside a callback like this:

    Code:
    QClient.OnMessageAsync(async message =>
    {
       //read result...
       //Plot result
       Plot[0] = message.result; // this doesn't work
    }
    Any help is greatly appreciated.
    Thx,
    Anton

    #2
    Hello Anton,

    I will not be able to assist with a 3rd party application.

    However, if this code is being called from within a NinjaScript, in what method is this being called?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      I initialize this callback in the OnStateChange (State == State.Configure) method.
      Thing that also doesn't work for me (same error saying that index is out of range) is when I try to plot a bar inside a Task.Run like this in the OnBarUpdate() method:

      Code:
      Task completeRequests = Task.Run( async () =>
      {
         //Work with data
         //Plot data
         Plot[barsago] = 3;
      }
      Last edited by antonma; 04-05-2016, 04:25 PM.

      Comment


        #4
        Hello antonma,

        You will not be able to set plots before that historical bar is processed. In other words, you will not be able to set a plot when State == State.Configure.

        Also, if you are running code in a Task, or OnRender, or in a custom timer, the data series and plots are not going to be synced. So TriggerCustomEvent must be called to sync those series.
        http://ninjatrader.com/support/helpG...ustomevent.htm

        Attached is an example of setting the last few bars in a Task. (Keep in mind that Tasks are not supported by NinjaTrader to do, however, I thought this would be a good example of when TriggerCustomEvent is necessary.
        Attached Files
        Last edited by NinjaTrader_ChelseaB; 04-08-2016, 07:02 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          thank you very much. This is exactly what I need.

          Cheers,
          Anton

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by swestendorf, Today, 11:14 AM
          1 response
          1 view
          0 likes
          Last Post swestendorf  
          Started by Sparkyboy, Today, 10:57 AM
          0 responses
          4 views
          0 likes
          Last Post Sparkyboy  
          Started by TheMarlin801, 10-13-2020, 01:40 AM
          21 responses
          3,917 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by timmbbo, 07-05-2023, 10:21 PM
          3 responses
          156 views
          0 likes
          Last Post grayfrog  
          Started by Lumbeezl, 01-11-2022, 06:50 PM
          30 responses
          812 views
          1 like
          Last Post grayfrog  
          Working...
          X