Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate not working properly or what the hell?

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

    OnBarUpdate not working properly or what the hell?

    Hello, i'm trying to develop a custom strategy, scripting in "NinjaScript", putting all my logic into the OnBarUpdate (CalculateOnBarClose = true), as suggested in help, but i'm getting some very weird behavior:

    1. OnBarUpdate certainly doesn't run for every tick, i made a strategy that entered a position each time OnBarUpdate is called, just to test this, and for about first 10 or 15 bars after enabling it, nothing happened, then it started responding/working... this behavior was consistent between several custom strategies (some of them had some indicator conditions) - none of them seem to be working from the moment of activating, all of them start to work after about 10 bars have passed from their activation

    2. In second attempt (changed the strategy to call custom dll to log into file, as i can't seem to force the NT Log call to work, added dll references, saved, compiled, exited NT, started NT, opened strategy, compiled again just to be sure), already 18 bars from its start have passed, and strategy doesn't seem to be working (it's active in the list of strategies, but it doesn't trade (again, just dumb "Enter long" and "call dll function to log into file" on every OnBarUpdate call).

    Status update: 28 bars passed from strategy activation, and it finally noticed that it's active.


    Another status update: edited the strategy to CalculateOnBarClose = true, 7 bars passed since its new activation (before which i also disabled all the indicators on chart), still waiting for it to kick in.

    Am I missing something? Am I stupid? Is your help file stupid?

    In that regard, i've been also unable to make the DrawText function from custom strategy to work, despite generating the call from the Strategy Wizard (after several unsuccessful attempts to write the call by hand) - no error in logs, no text in chart, nothing.

    On a somewhat (un)related note, what the hell is going on with the "remove reference, re-add reference, save strategy, exit NT, start NT, compile strategy" routine i have to do every time I make a change to my external dll, for NT to notice it? Why can't it just properly and fully re-bind to the external dll after the first two (remove reference, re-add reference) steps?

    Conclusion: The API seems inconsistent, strange and counter-intuitive in its behavior, and this inconsistency and strangeness doesn't seem to be noted anywhere in help. If it's just my stupidity and I'm misunderstanding some principles that cause this apparent inconsistency, i'd be grateful to anyone who would explain it to me.
    Last edited by sh code; 10-05-2011, 02:36 AM. Reason: status update

    #2
    sh code, welcome to the forums and thanks for the post.

    1. Do you run on historical data or the simulated feed and what BarsRequired setting are you working with? http://www.ninjatrader.com/support/h...srequired2.htm

    2. Do you use the 'WaitUntilFlat' or the 'Immediately Submit' option as you start the strategy?



    3. For the DrawText issue: what code snippet did you use before using the wizard to complete the task?

    4. I'm not 100% following what issues you have with your custom dll loading, a compile all in the NT environment has to be done for any code changes and will then compile all NT scripts (indicator and strategies) into one DLL file for highest performance runtime use.

    Comment


      #3
      1. Simulated feed, i didn't know/didn't notice the BarsRequired value which means i used the default one which seems to be 20. However in my current test there's already way more than 20 bars and the strategy doesn't seem to work. It ran Initialize and OnStartUp, but not even one OnBarUpdate has ran.

      2. I didn't know about this option either, so i'm using the default value (Wait for flat), however if i understand correctly this relates only to historical data*?

      3. Not really important, i tried all the overloads with various parameters, among them was also a call that looked nearly the same as the wizard generates, but not even wizard-generated call works.

      4:
      - i write/edit my custom dll in Visual Studio, compile/build it, copy it to NT Custom folder.
      - i open strategy in NT, add reference to my custom dll in the NT Custom folder
      - i have to completely restart NT for its intellisense and compile functions to work and see the methods i added to my custom dll in latest edit

      *talking about historical data, i can't seem to find a way/place to display imported (Tools->Historical data manager->import) historical data, respectively, i think i found where they should be displayed (File->New->Strategy analyzer, select the imported dataset, choose "Chart" tab, but the chart itself is empty)

      **thinking about all the issues i have with NT (basically anything i try to do turns out to be issue - whether it doesn't work, or doesn't work as i'd expect, or i can't even find where/if i can do it), do people new to NT tend to have this problem - being unable to do nearly anything in NT?

      Comment


        #4
        What exact condition would you then use to trigger any reaction from the strategy, are you sure this is evaluating to 'true' then? Have you tried for example the default SampleMACrossOver as well we ship with NT as demo strategy?

        The 'on starting a realtime strategy setting' determines how NT's handles a historical strategy position, in WaitUntilFlat only a newly generated entry signal is traded, as NT then waits for the historical 'taken over' position to be closed first.

        It would definitely be important, in order to understand why the call didnt work for you, we would need to know precisely what you tried.

        That would be expected for your custom DLL handling here, the DLL is loading at NT startup - I will forward a suggestion to product management to consider enhancing this in the future, thanks for the input.

        What symbol / expiry have you imported data for and how? The Historical Data Manager would be the place to double-check the imported data / stored data.

        For free end of day data access for various instruments, you can also connect to the 'Kinetick Free End of Day' connection we presetup with NT7.

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          What exact condition would you then use to trigger any reaction from the strategy, are you sure this is evaluating to 'true' then? Have you tried for example the default SampleMACrossOver as well we ship with NT as demo strategy?
          I used no condition, just

          Code:
          protected override void OnBarUpdate()
          {
            EnterLong();
          }
          or any other function i wanted to try

          i have tried the sample strategy, it kicked in after those 20 bars.

          Originally posted by NinjaTrader_Bertrand View Post
          It would definitely be important, in order to understand why the call didnt work for you, we would need to know precisely what you tried.
          how can the call not work, if it compiles, or even if it was generated by the Wizard? i can't give you precise calls, because i've tried dozens of them, and none of them worked, both of which also brings me to conclusion that it's irrelevant.

          Originally posted by NinjaTrader_Bertrand View Post
          That would be expected for your custom DLL handling here, the DLL is loading at NT startup - I will forward a suggestion to product management to consider enhancing this in the future, thanks for the input.
          it shouldn't be hard to change it so the dll at least reloads on adding/removing reference, thank you for forward.

          Originally posted by NinjaTrader_Bertrand View Post
          What symbol / expiry have you imported data for and how? The Historical Data Manager would be the place to double-check the imported data / stored data.
          S&M 500 if i'm not mistaken, custom data downloaded as a text file. I have checked, but i'll check again, it's hard for me to grasp the UI logic in NT yet...

          i imported it through the historical data manager, didn't change any of the settings, not sure what format the data were in but i'd expect an error if it was different from what was set in NT, and i didn't get any.

          Originally posted by NinjaTrader_Bertrand View Post
          For free end of day data access for various instruments, you can also connect to the 'Kinetick Free End of Day' connection we presetup with NT7.
          thank you for the tip, but i need intraday data, which are pretty hard to come by
          Last edited by sh code; 10-05-2011, 09:19 AM. Reason: added repetition of myself describing the historical data import

          Comment


            #6
            Glad to hear the sample worked - are you sure that the other strategy is not just Long for example since the start of the session? You have not exit rules defined, besides the per default running ExitOnClose.

            Compilation does not have to mean you get the results you seek, if you draw at an unreasonable value >> you won't see it even if the compile is technically ok and accepted.

            Ok, for the ES future please name the fiel ES 12-11.Last.txt and import it again then in the outlined format here :

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 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
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X