Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Market Analyzer - How does the threading work?

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

    Market Analyzer - How does the threading work?

    Hi, I have market analyzer on a couple hundred symbols and 4 columns that are using an indicator that I created myself that actually computes a bunch of other indicators at a time inside my indicator.

    Example
    Symbol 10 Min Indicator 65 Min Indicator 1 Day Indicator 1 Week Indicator
    AAPL 0.5 1.2 4.3 4.0
    NVDA 0.2 3.4 3.7 5.6
    MSFT -0.1 1.2 4.5 2.4
    When I have it set to Calculate 'on price change' it does too much work and gets behind because it is doing too much processing. I would like the 10 Minute indicator to update maybe once per minute, 65 minute indicator update once every 5 minutes, 1 day indicator once every half hour, and 1 week indicator twice a day.

    I can't use calculate on bar close to accomplish what i need because otherwise 1 week indicator will only get calculated once per week for example.

    I am wondering if each cell in the market analyser is it's own thread or not and if I can use like Thread.sleep() or something on it to make it wait before trying again.
    Such as 9:30AM AAPL price updates and the indicator runs.. then before it returns I can put the thread to sleep for a minute or however long I want so that it is not trying to fire every time the price changes.
    In the code it also sends the data of my indicator to my database so I don't really care if it doesn't update on the market analyzer due to me putting the thread to sleep.

    Any info would help me. If I have it set to 'On bar close" i have no problems but if I have 'On price change' it tries to process basically all day and can't keep up. I need a way to do something in the middle where I can control the indicator running as I want. 'On bar close' is not enough times, and 'On Price Change' is too many times. So I need to control 'On Price Change' somehow and my thought was to try putting the thread to sleep. Let me know

    Please add an option to update/run the cell's indicator on a user defined interval to the market analyzer. This is the only pet peeve I have with the software and it's a big problem for me.
    Last edited by JustinCross; 09-04-2020, 02:34 PM.

    #2
    Hello JustinDross,

    Thanks for your question.

    OnBarUpdate and data processing methods will update in realtime on an instrument thread. Instrument threads are spawned for the number of logical cores you have on your CPU.

    Because of which, sleeping the instrument thread can affect other instrument updates and would not be advised.

    Unfortunately, I do not have any additional insight I could share to change the Calculate interval, or to force a suspended state from the Market Analyzer.

    We are tracking feedback to allow for having indicators calculate on different intervals other than OnEachTick/OnPriceChange/OnBarClose in the Enhancement request ticket SFT-3230. I have added a vote on your behalf and have noted your interest to update values on a different interval.

    We receive many change/enhancement/feature requests and we cannot offer an ETA or promise of fulfillment, but we do note new features in the Release Notes page of the Help Guide once implemented.



    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Ok thanks for adding +1

      Now, I am trying to think of an alternative solution for now.
      What I am thinking is I'll set my indicator to calculate 'On Bar Close'.
      Then, in my indicator do you know if there is a way to configure it to either:
      1. Get it to process whatever data is available with the onBarUpdate() with a timer. I am looking at https://ninjatrader.com/support/help...ustomevent.htm to try to see if I can do anything with that.
      2. If not using a timer, spawn a new async thread that will Sleep for a certain amount of time and then somehow call the cell to update.
      Both of these options I don't know how to do yet or if they are viable or not. I am just trying to think of anything at this point.

      The options we have by default are too extreme. For example on daily data:
      On Price Change/On Tick Change: THis will update almost every second so like 20000+ times during a 6.5 hour market session.
      On Bar Close: This will update 1 time per day.

      So basically the option is to run 20000 times or 1 time per day. That seems crazy to not have another option where the user can control it.


      Edit: Also it is my understanding that in the market analyzer each instrument has it's own thread that I assume is getting the real time data and ends up firing off the indicator scripts of the other columns cells in their own thread. Is there any way to modify the code related the instrument thread to work differently? Can I overwrite the default way it works?
      Last edited by JustinCross; 09-04-2020, 09:45 PM.

      Comment


        #4
        Hello JustinCross,

        Instrument threads are spawned to match the number of logical cores on your CPU. Each instrument does not get their own thread and this cannot be customized.

        OnBarUpdate is event based and most indicators use this to assign indicator values because indicator plots and Series objects are synchronized to the data series the indicator is applied against. If we try to skip calculating for bar we would alter the indicator's calculation.

        Something you might consider, though, is to have a custom indicator set to calculate OnPriceChange, have guaranteed "OnBarClose" calculations set on IsFirstTickOfBar, and then to use a timer to signal when your indicator logic should process something outside of IsFirstTickOfBar. This could reduce the number of times an indicator is calculated intrabar. I would not recommend this for scripts that absolutely need Calculate.OnEachTick since we would not be updating the indicator plot that often.

        IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #5
          going from your idea i might have figured something out. Actually an easier solution than i thought possible. I didn't realize the class level variables were accessible throughout multiple executions of the indicator. For whatever reason, in my mind they were getting reset every time the indicator ran and I never tested it.

          So I added a DateTime variable at the class level called executeTime and basically after the indicator runs the main code that does calculations I update this time to current time + N minutes from now, Then I only allow my indicator code to execute that main code if DataTime.Now > executionTime. Every other time it doesn't do anything besides print this output line below.

          I am seeing the results I want now. I don't know yet if my PC will handle everything well now or not, I'll find out tomorrow when I have a couple hundred symbols updating at once. Thanks!

          Code:
          BTCUSD 65 Minute counter: 1 updates: 0
          BTCUSD 65 Minute counter: 2 updates: 1
          BTCUSD 65 Minute counter: 3 updates: 1
          BTCUSD 65 Minute counter: 4 updates: 1
          BTCUSD 65 Minute counter: 5 updates: 1
          BTCUSD 65 Minute counter: 6 updates: 1
          BTCUSD 65 Minute counter: 7 updates: 1
          BTCUSD 65 Minute counter: 8 updates: 1
          BTCUSD 65 Minute counter: 9 updates: 1
          BTCUSD 65 Minute counter: 10 updates: 1
          BTCUSD 65 Minute counter: 11 updates: 1
          BTCUSD 65 Minute counter: 12 updates: 1
          BTCUSD 65 Minute counter: 13 updates: 1
          BTCUSD 65 Minute counter: 14 updates: 1
          BTCUSD 65 Minute counter: 15 updates: 1
          BTCUSD 65 Minute counter: 16 updates: 1
          BTCUSD 65 Minute counter: 17 updates: 1
          BTCUSD 65 Minute counter: 18 updates: 1
          BTCUSD 65 Minute counter: 19 updates: 1
          BTCUSD 65 Minute counter: 20 updates: 1
          BTCUSD 65 Minute counter: 21 updates: 1
          BTCUSD 65 Minute counter: 22 updates: 1
          BTCUSD 65 Minute counter: 23 updates: 1
          BTCUSD 65 Minute counter: 24 updates: 1
          BTCUSD 65 Minute counter: 25 updates: 1
          BTCUSD 65 Minute counter: 26 updates: 1
          BTCUSD 65 Minute counter: 27 updates: 1
          BTCUSD 65 Minute counter: 28 updates: 1
          BTCUSD 65 Minute counter: 29 updates: 1
          BTCUSD 65 Minute counter: 30 updates: 1
          BTCUSD 65 Minute counter: 31 updates: 1
          BTCUSD 65 Minute counter: 32 updates: 1
          BTCUSD 65 Minute counter: 33 updates: 1
          BTCUSD 65 Minute counter: 34 updates: 1
          BTCUSD 65 Minute counter: 35 updates: 1
          BTCUSD 65 Minute counter: 36 updates: 1
          BTCUSD 65 Minute counter: 37 updates: 1
          BTCUSD 65 Minute counter: 38 updates: 1
          BTCUSD 65 Minute counter: 39 updates: 1
          BTCUSD 65 Minute counter: 40 updates: 1
          BTCUSD 65 Minute counter: 41 updates: 1
          BTCUSD 65 Minute counter: 42 updates: 1
          BTCUSD 65 Minute counter: 43 updates: 1
          BTCUSD 65 Minute counter: 44 updates: 1
          BTCUSD 65 Minute counter: 45 updates: 1
          BTCUSD 65 Minute counter: 46 updates: 1
          BTCUSD 65 Minute counter: 47 updates: 1
          BTCUSD 65 Minute counter: 48 updates: 1
          BTCUSD 65 Minute counter: 49 updates: 1
          BTCUSD 65 Minute counter: 50 updates: 1
          BTCUSD 65 Minute counter: 51 updates: 1
          BTCUSD 65 Minute counter: 52 updates: 1
          BTCUSD 65 Minute counter: 53 updates: 1
          BTCUSD 65 Minute counter: 54 updates: 1
          BTCUSD 65 Minute counter: 55 updates: 1
          BTCUSD 65 Minute counter: 56 updates: 1
          BTCUSD 65 Minute counter: 57 updates: 1
          BTCUSD 65 Minute counter: 58 updates: 1
          BTCUSD 65 Minute counter: 59 updates: 1
          BTCUSD 65 Minute counter: 60 updates: 1
          BTCUSD 65 Minute counter: 61 updates: 1
          BTCUSD 65 Minute counter: 62 updates: 1
          BTCUSD 65 Minute counter: 63 updates: 1
          BTCUSD 65 Minute counter: 64 updates: 1
          BTCUSD 65 Minute counter: 65 updates: 1
          BTCUSD 65 Minute counter: 66 updates: 1
          BTCUSD 65 Minute counter: 67 updates: 1
          BTCUSD 65 Minute counter: 68 updates: 1
          BTCUSD 65 Minute counter: 69 updates: 1
          BTCUSD 65 Minute counter: 70 updates: 1
          BTCUSD 65 Minute counter: 71 updates: 1
          BTCUSD 65 Minute counter: 72 updates: 1
          BTCUSD 65 Minute counter: 73 updates: 1
          BTCUSD 65 Minute counter: 74 updates: 1
          BTCUSD 65 Minute counter: 75 updates: 1
          BTCUSD 65 Minute counter: 76 updates: 1
          BTCUSD 65 Minute counter: 77 updates: 1
          BTCUSD 65 Minute counter: 78 updates: 1
          BTCUSD 65 Minute counter: 79 updates: 1
          BTCUSD 65 Minute counter: 80 updates: 1
          BTCUSD 65 Minute counter: 81 updates: 1
          BTCUSD 65 Minute counter: 82 updates: 1
          BTCUSD 65 Minute counter: 83 updates: 1
          BTCUSD 65 Minute counter: 84 updates: 1
          BTCUSD 65 Minute counter: 85 updates: 1
          BTCUSD 65 Minute counter: 86 updates: 1
          BTCUSD 65 Minute counter: 87 updates: 1
          BTCUSD 65 Minute counter: 88 updates: 1
          BTCUSD 65 Minute counter: 89 updates: 1
          BTCUSD 65 Minute counter: 90 updates: 1
          BTCUSD 65 Minute counter: 91 updates: 1
          BTCUSD 65 Minute counter: 92 updates: 1
          BTCUSD 65 Minute counter: 93 updates: 1
          BTCUSD 65 Minute counter: 94 updates: 1
          BTCUSD 65 Minute counter: 95 updates: 1
          BTCUSD 65 Minute counter: 96 updates: 1
          BTCUSD 65 Minute counter: 97 updates: 1
          BTCUSD 65 Minute counter: 98 updates: 1
          BTCUSD 65 Minute counter: 99 updates: 1
          BTCUSD 65 Minute counter: 100 updates: 1
          BTCUSD 65 Minute counter: 101 updates: 1
          BTCUSD 65 Minute counter: 102 updates: 1
          BTCUSD 65 Minute counter: 103 updates: 1
          BTCUSD 65 Minute counter: 104 updates: 1
          BTCUSD 65 Minute counter: 105 updates: 1
          BTCUSD 65 Minute counter: 106 updates: 1
          BTCUSD 65 Minute counter: 107 updates: 1
          BTCUSD 65 Minute counter: 108 updates: 1
          BTCUSD 65 Minute counter: 109 updates: 1
          BTCUSD 65 Minute counter: 110 updates: 1
          BTCUSD 65 Minute counter: 111 updates: 1
          BTCUSD 65 Minute counter: 112 updates: 1
          BTCUSD 65 Minute counter: 113 updates: 1
          BTCUSD 65 Minute counter: 114 updates: 1
          BTCUSD 65 Minute counter: 115 updates: 1
          ...
          ...
          ...
          BTCUSD 65 Minute counter: 296 updates: 1
          BTCUSD 65 Minute counter: 297 updates: 1
          BTCUSD 65 Minute counter: 298 updates: 1
          BTCUSD 65 Minute counter: 299 updates: 1
          BTCUSD 65 Minute counter: 300 updates: 1
          BTCUSD 65 Minute counter: 301 updates: 1
          BTCUSD 65 Minute counter: 302 updates: 1
          BTCUSD 65 Minute counter: 303 updates: 1
          BTCUSD 65 Minute counter: 304 updates: 1
          BTCUSD 65 Minute counter: 305 updates: 1
          BTCUSD 65 Minute counter: 306 updates: 1
          BTCUSD 65 Minute counter: 307 updates: 1
          BTCUSD 65 Minute counter: 308 updates: 2
          BTCUSD 65 Minute counter: 309 updates: 2
          BTCUSD 65 Minute counter: 310 updates: 2
          BTCUSD 65 Minute counter: 311 updates: 2
          BTCUSD 65 Minute counter: 312 updates: 2
          BTCUSD 65 Minute counter: 313 updates: 2
          BTCUSD 65 Minute counter: 314 updates: 2
          BTCUSD 65 Minute counter: 315 updates: 2
          BTCUSD 65 Minute counter: 316 updates: 2
          BTCUSD 65 Minute counter: 317 updates: 2
          Last edited by JustinCross; 09-08-2020, 09:06 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mjairg, 07-20-2023, 11:57 PM
          3 responses
          213 views
          1 like
          Last Post PaulMohn  
          Started by TheWhiteDragon, 01-21-2019, 12:44 PM
          4 responses
          544 views
          0 likes
          Last Post PaulMohn  
          Started by GLFX005, Today, 03:23 AM
          0 responses
          3 views
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          12 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          7 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X