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

NinjaScript/NT Limitations here?

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

    NinjaScript/NT Limitations here?

    Hi -

    I've got a couple of questions that I'm unable to find a clear answer on.

    1) What is the best way to limit one intrabar entry PER BAR. At times the profit objective that is hard coded in will be hit, and it'll re-enter on the same bar because the conditions in OnBarUpdate() are still met. I thought of using a limit order for entry that would prevent this... but even then if price drops below the limit value it'll trigger again. Is there any way to do this when CalculateOnBarClose() is set to false?

    2) For backtesting, intrabar entries are displayed incorrectly and shown on the NEXT bar after the correct entry bar had the method been called in realtime. Is this just a bug in NT? This is a HUGE pain in the ass, and basically makes all of the backtesting functionality in NT useless for intrabar entries if that's the case. And if there's a built in functionality for Question #1, then you could at least get accurate backtesting results within a standard deviation based on inside/outside bars.

    3) The EXACT same code generated by the Wizard will not compile once the code has been unlocked. At first I thought it was a syntax error(s) on my part, but after checking and rechecking it seems that it generates the same types of errors (mostly missing }, {, 0, ;, and crap about initializing arrays). What I'd really like to do is take a lot of the code generated by the wizard and move it into a separate class and define it as a series of functions with polymorphisms so I can keep reusing my code across strategies, but at the moment I can't even get the same code generated by the wizard to compile, much less my own.

    Any help is much appreciated. And apologies in advance if these issues are addressed in bold type somewhere in the manual that I missed

    #2
    Hi,

    Welcome to NinjaScript.

    1) Unfortunately we do not have a internal property that can be set to limit entries to once per bar. You would have to code a workaround by using a bool variable that is reset on the start of a new bar. So, on your entry condition being true, set this variable to true, then reset it to false on using FirstTickOfBar property.

    2) CalculateOnBarClose property is irrelevant during a historical backtest. Backtests are *ALWAYS* performed on a bar close basis.

    3) Could you provide a reproducible sample that we could debug? I am assuming that you generate a strategy via the wizard, compile it, then Unlock it later, immediately try to compile (no editing of the wizard generated code) and then try to compile?

    Thanks.
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      Hi,

      Welcome to NinjaScript.

      1) Unfortunately we do not have a internal property that can be set to limit entries to once per bar. You would have to code a workaround by using a bool variable that is reset on the start of a new bar. So, on your entry condition being true, set this variable to true, then reset it to false on using FirstTickOfBar property.

      2) CalculateOnBarClose property is irrelevant during a historical backtest. Backtests are *ALWAYS* performed on a bar close basis.

      3) Could you provide a reproducible sample that we could debug? I am assuming that you generate a strategy via the wizard, compile it, then Unlock it later, immediately try to compile (no editing of the wizard generated code) and then try to compile?

      Thanks.
      Ray, thanks for such a quick response.

      1) Absolutely awesome. That will fix my problem. Thank you.

      2) So then, forgive me if I'm just missing something blindingly obvious, there is no way to backtest a strategy where orders are filled at a limit price intrabar? (I'm going to feel pretty stupid here if you point out an answer here that I'm just missing.)

      3) Definitely. Let me just code up something real quick, so you're actually debugging what I'm trying to get working instead of an arbitrary example. I was actually trying to use the wizard just to see the concept applied to a chart so I could run a backtest real quick to check for conceptual errors in the strategy, with the intention of going back and re-coding it in a way that makes changing the strategy much less cumbersome, vs. editing individual conditions set by the wizard.

      I know it's just a matter of efficiency and scalability, but for example, if you're going to be changing around something like the way you identify pivots, there's no reason to have to change the code for pivot identification for each condition in OnBarUpdate(), or even for whether it's a pivot in price or a pivot on an oscillator you're talking about, if I can just define pivot functionality in a separate method outside of OnBarUpdate() that gets called from within OnBarUpdate() and knows whether it's a pivot in price or a pivot on an oscillator line based on the parameters passed to it.

      Comment


        #4
        Okay, here's a great example. This code was generated ENTIRELY by the wizard, then gives me an error when I hit "Finish". Ideally I'd like to circumvent the wizard entirely, but just to show a point here I like this example because it was generated by the wizard itself, so the question of whether I made a syntax error doesn't even apply.

        Last edited by eeisen; 08-28-2007, 12:40 PM.

        Comment


          #5
          Please PM me the strategy to "dierk AT ninjatrader DOT com". Thanks

          Comment


            #6
            Hey Evan, your best bet is to do something like this:
            In your variables, declare a bool hasEnteredTrade = false;

            and then in your code when you enter use:
            if(SomeTrueCondition && !hasEnteredTrade){
            EnterLongPostion("MyStrategy");
            hasEnteredTrade = true;
            }


            and then at the beginning of the OnBarUpdate(), use:

            if (FirstTickOfBar){
            hasEnteredTrade = false;
            }

            This way, once it enters a trade, it will block out all other signals. Also, you're missing a ) somewhere. Note that when you compile a ninja trader strategy or indicator, it compiles everything. So the error may not be in the specific file that you are editing and could be somewhere else.

            Steve
            Last edited by mazachan; 08-28-2007, 06:41 PM.

            Comment


              #7
              Originally posted by mazachan View Post
              Hey Evan, your best bet is to do something like this:
              In your variables, declare a bool hasEnteredTrade = false;

              and then in your code when you enter use:
              if(SomeTrueCondition && !hasEnteredTrade){
              EnterLongPostion("MyStrategy");
              hasEnteredTrade = true;
              }


              and then at the beginning of the OnBarUpdate(), use:

              if (FirstTickOfBar){
              hasEnteredTrade = false;
              }

              This way, once it enters a trade, it will block out all other signals.

              Steve
              Thanks for the advice Steve, that's pretty much what I ended up doing, albeit kind of in a round-a-bout way due to some compile errors. Did you have inconsistent problems compiling when you coded up those indicators for Nate?

              It's really weird, since the Ninja Editor updates the bottom pane with syntax errors and little stuff like trying to compare 2 different types with something like an == in realtime, sometimes after the error is corrected it'll still choke on compile or not update the bottom pane to reflect the correction.

              It's been a real pain in the ass, I ended up just writing the code in Vi and then pasting it into the Ninja Editor, exact same code that choked before, and it compiled.

              Regardless, I got it the strategy finished and working this afternoon, but it's been a pain in the ass.
              Last edited by eeisen; 08-28-2007, 06:51 PM.

              Comment


                #8
                You shouldn't have to use Vi, as the editor is sufficient. However, you can make ninja trader not check for compilation errors while you type. Like I said, the problem can exist elsewhere in some other file and ninja trader will throw an error when you compile.

                Comment


                  #9
                  Originally posted by mazachan View Post
                  You shouldn't have to use Vi, as the editor is sufficient. However, you can make ninja trader not check for compilation errors while you type. Like I said, the problem can exist elsewhere in some other file and ninja trader will throw an error when you compile.
                  That's the thing though, it's not like there's errors in the code (I know everyone says this). But I know, because like in the screenshot above, I pasted in the exact same code that I pasted out of the Ninja Editor in the first place into Vi, and shut down NT and restarted it, and pasted it into a new NS strategy template, and it compiled.

                  I'm going to turn off the auto-error check now though, thanks for pointing that out.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by jclose, Today, 09:37 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post jclose
                  by jclose
                   
                  Started by WeyldFalcon, 08-07-2020, 06:13 AM
                  10 responses
                  1,414 views
                  0 likes
                  Last Post Traderontheroad  
                  Started by firefoxforum12, Today, 08:53 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post firefoxforum12  
                  Started by stafe, Today, 08:34 PM
                  0 responses
                  11 views
                  0 likes
                  Last Post stafe
                  by stafe
                   
                  Started by sastrades, 01-31-2024, 10:19 PM
                  11 responses
                  169 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Working...
                  X