Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

whats wrong here?

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

    whats wrong here?

    Im trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades. Code is pasted in txt file.
    Attached Files

    #2
    meegwell, how are you testing this strategy?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Sorry I should have provided more info - Im backtesting it against a basket of stocks that I have backtested many strategies against. I've also just run it against a single stock in a chart.

      Attached is a couple pics of the param setup and results.

      THis seems like the most basic stratgey I just cant figure out whats going on.
      Attached Files

      Comment


        #4
        Your code evaluates to flat.

        Originally posted by meegwell View Post
        Im trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades. Code is pasted in txt file.
        As you ask what is wrong with your code, I am going to presume that you want an explanation of how the code logic does not produce the results that you expect. If my understanding is wrong, then, as one other poster whose code I analyzed, and to which I gave a solution wrote back, you can just "ignore my crass admonishments."

        If I may be allowed to wax pedantic for a while,
        • Your Condition 1 will make a long entry on EVERY bar
        • Your Conditon 2 will exit a long position on EVERY bar after bar 5.

        Hence from bar 6 onwards, there will be an entry AND an exit on every bar. As you do not have a BarsRequired directive, this will only show evaluation after bar 20. Therefore, all the evaluated bars shown will have entry and exit on the bar. Given the way the OnBarUpdate() function returns, the most likely return is a logical evaluation of the entire block, which in this case means that it would simply make neither entry nor exit, as that is logically flat on the bar.

        To do what you seem to be describing you would have to filter your entries so that you only enter if there is not an existing position.

        Code:
        // Condition set 1
        
        if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0)
        
        {
        
        EnterLong(DefaultQuantity, "long");
        
        }
        Because of the way that ExitLong() functions, the market position filter is implied. Nonetheless, so as to avoid any possible unintended consequences, I would make it explicit thus.

        Code:
        // Condition set 2
        
        if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6)
        
        {
        
        ExitLong("long");
        
        }
        Note that your ExitLong() syntax also seems incorrect, at least according to the syntax primitives in the NT help.
        Last edited by koganam; 02-07-2011, 12:50 AM.

        Comment


          #5
          koganam:
          • Your Condition 1 will make a long entry on EVERY bar
          • Your Conditon 2 will exit a long position on EVERY bar after bar 5.
          I am limited to one position per direction. So I would expect to see this enter a long position (labeled "long") at the first available bar.

          Then, the second condition will exit long position 5 bars from entry of long position "long"...correct?

          I have i one position per direction limit, and the exit is 5 bars from the entry of position labeled "long" ...?

          At a minimum, shouldn't I see one entry at the very beginning into a long position?

          Because of the way that ExitLong() functions, the market position filter is implied. Nonetheless, so as to avoid any possible unintended consequences, I would make it explicit thus.
          I will try this.

          Note that your ExitLong() syntax also seems incorrect, at least according to the syntax primitives in the NT help.
          I did not code anything, it was all created by the Wizard so maybe NT support can explain why the syntax is wrong.

          Thank you for your intput. Note that my goal for this strategy is to simply enter into many short lived long positions regardless of market/price action. Obviously it is for informational testing purposes and not to make a profit.

          Thanks for the input and suggestions,

          Meegwell

          Comment


            #6
            I am limited to one position per direction. So I would expect to see this enter a long position (labeled "long") at the first available bar.

            Then, the second condition will exit long position 5 bars from entry of long position "long"...correct?

            I have i one position per direction limit, and the exit is 5 bars from the entry of position labeled "long" ...?

            At a minimum, shouldn't I see one entry at the very beginning into a long position?
            You may have missed this paragraph from the original reply:

            "Hence from bar 6 onwards, there will be an entry AND an exit on every bar. As you do not have a BarsRequired directive, this will only show evaluation after bar 20. Therefore, all the evaluated bars shown will have entry and exit on the bar." (emphasis added)

            Here, you were asking about the first 6 bars. Their evaluation will not be shown as they are before bar20.

            Comment


              #7
              why would there be an exit on bar 7?

              Comment


                #8
                I changed the code to this, as you suggest, with the same results...zero trades:

                Code:
                 
                ///<summary>
                /// Called on each bar update event (incoming tick)
                ///</summary>
                protectedoverridevoid OnBarUpdate()
                {
                // Condition set 1
                if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0)
                {
                EnterLong(DefaultQuantity, "long");
                }
                // Condition set 2
                if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6)
                {
                ExitLong("long");
                }
                }

                Comment


                  #9
                  Originally posted by meegwell View Post
                  why would there be an exit on bar 7?
                  Because per "Condition 1" there was an entry on bar1. Bar7 is 6 bars after bar 1, so "Condition 2" is an exit.

                  Comment


                    #10
                    If someone could suggest something for this simple goal (can be achieved w/ wizard) that works I would appreciate it. I'll restate my goal:

                    Im trying to do a very simple strategy for testing purposes where I simply enter a long position, hold it for x days, exit, repeat. I built a condition where if close>0, enter long. After 5 bars, exit long. I assumed this would just keep creating positions one after another. It produces zero trades.

                    Comment


                      #11
                      Let us try a little debugging. Add the code in red, then check the output window to see if you get any text telling you about the entries.

                      In the meantime, do you have any entries in the NT log relating to errors from the strategy?

                      Code:
                      protectedoverridevoid OnBarUpdate()
                      {
                      // Condition set 1
                      if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0)
                      {
                      [COLOR="Red"]Print("");
                      Print("Long entry on bar: " + CurrentBar);[/COLOR]
                      EnterLong(DefaultQuantity, "long");
                      [COLOR="Red"]Print("Long entry should have been made on bar: " + CurrentBar);[/COLOR]
                      }
                      // Condition set 2
                      if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6)
                      {
                      [COLOR="red"]Print("");
                      Print("Long exit on bar: " + CurrentBar);[/COLOR]
                      ExitLong("long");
                      [COLOR="Red"]Print("Long exit should have been made on bar: " + CurrentBar);[/COLOR]
                      }
                      }

                      Comment


                        #12
                        I just copied your code so that I could see what is going on. Right from the start, you are generating an exception because your variable (which is not even used), is called bars, so the property is generated as Bars, which is a reserved name in NT, so is causing problems in the getter/setter.

                        As it did not take very long once I input your code, I have simply written the strategy for you, and corrected the variable, and also turned it into a parameter, just in case you may want to optimize the number of bars.

                        I must say I am a bit surprised that the strategy may actually be viable. Well, they do say; "Simple is better".

                        EDIT: Oops. It looks like I misspelled your name. Sorry.
                        Attached Files

                        Comment


                          #13
                          I appreciate your trying to help but we are getting way too complex for such a simple request...its well beyond my desire to keep it simple w/ the wizard at this point.

                          Thanks


                          Originally posted by koganam View Post
                          Let us try a little debugging. Add the code in red, then check the output window to see if you get any text telling you about the entries.

                          In the meantime, do you have any entries in the NT log relating to errors from the strategy?

                          Code:
                          protectedoverridevoid OnBarUpdate()
                          {
                          // Condition set 1
                          if (Position.MarketPosition != MarketPosition.Long && Close[0] > 0)
                          {
                          [COLOR=red]Print("");[/COLOR]
                          [COLOR=red]Print("Long entry on bar: " + CurrentBar);[/COLOR]
                          EnterLong(DefaultQuantity, "long");
                          [COLOR=red]Print("Long entry should have been made on bar: " + CurrentBar);[/COLOR]
                          }
                          // Condition set 2
                          if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry() == 6)
                          {
                          [COLOR=red]Print("");[/COLOR]
                          [COLOR=red]Print("Long exit on bar: " + CurrentBar);[/COLOR]
                          ExitLong("long");
                          [COLOR=red]Print("Long exit should have been made on bar: " + CurrentBar);[/COLOR]
                          }
                          }

                          Comment


                            #14
                            Understood. However, you did have a basic initial problem with the strategy, that I found when I copied your code, run it, and looked in the log. I have already made another post, with an attachment for you. It really would not have taken so long if I had just downloaded your code and tried it in the first place. Sometimes when we who think we are teachers try to help, we make things more difficult than they need be. Regards.

                            Comment


                              #15
                              I really appreciate your effort and thank you. I posted a different thread to try to start fresh because I really feel like this is simple...Ill follow up there.

                              As far as being viable, its not - or I should say it shouldn't be. Thats not the point. It is to be used as a adaptable statistical benchamark...adaptable to the different markets I throw at it. Its purpose is not to implement live, but as a tool for my elaborate testing and development process....which, at the end of the day, produces simple strategies!!!

                              go figure...
                              Thansk again,

                              Meegwell

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by michi08, 10-05-2018, 09:31 AM
                              2 responses
                              737 views
                              0 likes
                              Last Post Denver_Wayne  
                              Started by sightcareclickhere, Today, 01:55 PM
                              0 responses
                              1 view
                              0 likes
                              Last Post sightcareclickhere  
                              Started by Mindset, 05-06-2023, 09:03 PM
                              9 responses
                              258 views
                              0 likes
                              Last Post ender_wiggum  
                              Started by Mizzouman1, Today, 07:35 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post Mizzouman1  
                              Started by philmg, Today, 01:17 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X