• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:

        https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

        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 superkolleech, Today, 12:46 AM
              1 response
              11 views
              0 likes
              Last Post MojoJojo  
              Started by davidwade, Today, 02:51 AM
              0 responses
              3 views
              0 likes
              Last Post davidwade  
              Started by aviat72, 04-26-2020, 09:41 PM
              10 responses
              91 views
              0 likes
              Last Post kissandfly  
              Started by healthooa, Today, 01:28 AM
              0 responses
              7 views
              0 likes
              Last Post healthooa  
              Started by harjinderjit, Yesterday, 08:24 PM
              0 responses
              20 views
              0 likes
              Last Post harjinderjit  
              Working...
              X