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

Noobs Strategy Starts In The Past

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

    Noobs Strategy Starts In The Past

    Hello, I'm new to trading and strategy writing. So new that I'm not even sure if my question will make sense.

    I'm working in NT7 and have written a strategy algorithm that scans different things on stock charts to narrow down the number of charts to only those that are in what I think is the optimal position for trading.

    When I open my strategy in a chart, it doesn't start on the current time. It appears to go back a certain distance (almost seems arbitrary) and then "catches up" by executing on several past bars. Why is it doing this? If it isn't a necessity, how can I make it stop and instead have my strategy start working on the time that it is launched?

    Hope that made sense. Sorry to bother you with what is probably a very basic question but I've searched the forums and the net and can't seem to get any traction. Probably because i don't even know the right lingo. Thanks in advance for any help you might give.

    #2
    Hello MajMattMason,

    Thank you for your note.

    When you start up your strategy and its going back and plotting trades, its plotting historical trades, or what the strategy would have done had it been running at the time.

    To stop the strategy from doing this and forcing it to only execute in real time, you could add the following to the top of your code under OnBarUpdate(),

    if (Historical) return;

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hello, AlanP,

      Thank you for your assistance.

      I've copied and pasted this: if (Historical) return;

      directly under this:
      protected
      overridevoid OnBarUpdate()
      {

      at the very beginning of my script. Doesn't seem to be helping. I just now launched my strategy on a stock and it got hung up on a 9:01 am bar after starting on 8:55.


      Comment


        #4
        Hello MajMattMason,

        Thank you for writing in.

        I would suggest adding print statements to check whether your conditions are becoming true. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:

        Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


        I’ve provided a link covering debugging which you may find helpful.

        Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

        If you’d like to send a copy of the strategy you’re running, I can take a look and see if anything jumps out

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thank you, AlanP, If I could ask you for one more bit of info, please.

          In "if (Historical) return;" the "if (Historical) part appears to be a Boolean meaning "if the time bar being tested is less than the current time bar" (or something like that), it happened in the past and assumes a value of true.

          I'm guessing that triggers the "return" part.

          return to what? return to where? what exactly does "return" mean?

          Thanks

          Comment


            #6
            It means exit OnBarUpdate.

            Return back to the main event processing loop which called your OnBarUpdate, that way NT can continue to work.

            There general coding practices that say you should only have 1 return point in a function/procedure/method.

            But it does get kind of silly to keep indenting your code while trying to maintain this sometimes.

            So this would be acceptable and live up to 1 return at the end... but maintaining such indentation gets silly in my opinion.


            Code:
            OnBarUpdate....
            
            if (!Historical)
            {
                Your code here
            
            }
            I prefer the if (Historical ) return;

            Then I worry about my logic after.

            Comment


              #7
              Originally posted by MajMattMason View Post

              In "if (Historical) return;" the "if (Historical) part appears to be a Boolean meaning "if the time bar being tested is less than the current time bar" (or something like that), it happened in the past and assumes a value of true.
              It's more like they just "flip a switch" when processing historical data versus going forward data. They know the difference of what processing state it is in.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kaywai, 09-01-2023, 08:44 PM
              5 responses
              601 views
              0 likes
              Last Post NinjaTrader_Jason  
              Started by xiinteractive, 04-09-2024, 08:08 AM
              6 responses
              22 views
              0 likes
              Last Post xiinteractive  
              Started by Pattontje, Yesterday, 02:10 PM
              2 responses
              19 views
              0 likes
              Last Post Pattontje  
              Started by flybuzz, 04-21-2024, 04:07 PM
              17 responses
              230 views
              0 likes
              Last Post TradingLoss  
              Started by agclub, 04-21-2024, 08:57 PM
              3 responses
              17 views
              0 likes
              Last Post TradingLoss  
              Working...
              X