Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Problem - too many buys on backtest

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

    Simple Problem - too many buys on backtest

    Hi,
    I am totally new to Ninja Trader.
    I have set up a strategy to backtest which is mis-firng because I don't understand simple boolean properly.

    Go Long if
    StochRSi rising
    StochRSi below 15
    Long term moving average (SMA 50) rising

    The sell condition is StochRSI falls.

    This strategy is buying on every day the buy conditions are valid. so I have thousands of buys per stock.
    I want to buy ONCE the first time the conditions are satisfied, hold, then sell as soon as the sell condition is satisfied. Only after that buying again.

    What am I not including?

    Thanks, Simon

    #2
    Further Detail

    I found one reason. My sell condition was set to close out each day.

    But, the system continues to keep buying as long as the buy conditions each day when I want to only buy once , hold, then sell - then buy if entry conditions are correct.

    Attached is a screenshot of the Strategy Analyzer.
    Attached Files
    Last edited by GeminiSi; 07-17-2016, 06:43 AM.

    Comment


      #3
      Hello,
      Can you provide the code that you are using?
      There may be a logic error within the code that is causing it to continuously buy and sell.
      I look forward to your reply.
      Cody B.NinjaTrader Customer Service

      Comment


        #4
        Simple ways to avoid this. You could just use the built in way:

        if (Position.MarketPosition == MarketPosition.Flat && whatever else is your code)
        {
        LongEntry();
        }

        ^^ This way you will only enter a long position, if you have no position in that stock.

        Or you could create your own character

        boolean enter;

        if (enter==False & code)
        {
        LongEntry();
        enter == true;
        }

        Then you would use your own character like a switch and on follow up conditions, you could change it to enter==false.

        That's useful if you don't only want to check if you have a position, but if you want additional conditions if you JUST got into a trade.

        Comment


          #5
          Hi Cody,

          I have been trying to fix it.
          With the current code below, no buys or sells occur at all.
          I don't know how to set the Stoch RSI up for the following:
          Buy on first move up off zero of Stoch RSI (but first move must not take Stoch RSI higher than 15)
          I also want to sell short on first move down off 100 of the StochRSI. (but first move must not take StochRSI value lower than 90)
          The input for the StochRSI is the Hull 26 period MA

          Here are the conditions code.

          // Condition set 1
          if (CrossAbove(StochRSI(HMA(26), 26), DefaultInput, 0) == true
          && Rising(SMA(50)) == true)
          {
          EnterLong(DefaultQuantity, "");
          }

          // Condition set 2
          if (Falling(StochRSI(HMA(26), 26)) == true)
          {
          ExitLong("", "");
          }

          Comment


            #6
            Hello,
            I do not see anything wrong with the code. I have tested it on my end but I have not seen any situation where the conditions are true. What instrument are you testing on? Are you back testing or running this on real time data?
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              Hi Cody,

              I am backtesting.
              Yes, it generates no buys.
              My code is wrong and I don't know how to set up the condition builder to do what I want (which is pretty simple, but I am too dense to figure it out)

              I want to buy the first time the StochRSI rises off zero (so crossing through a range of 1-15). Hold. Then only sell once the StochRSI falls. I get the sell okay, and also the rising longer term MA, but I can't design the condition for StochRSI part buying the first time it rises off zero.

              Simon

              Comment


                #8
                Hello,
                I think your logic for the code my be off. I'm not seeing the StochRSI go below 0 so it would not cross 0. You could however check if the StochRSI is between 0 and 15. You can do this by doing the following:

                if(StochRSI(HMA(26), 26)[0] > 0 && < 15)
                EnterLong;

                Please let me know if this is not what you are meaning for your entry.
                Cody B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_CodyB View Post
                  Hello,
                  I think your logic for the code my be off. I'm not seeing the StochRSI go below 0 so it would not cross 0. You could however check if the StochRSI is between 0 and 15. You can do this by doing the following:

                  if(StochRSI(HMA(26), 26)[0] > 0 && < 15)
                  EnterLong;

                  Please let me know if this is not what you are meaning for your entry.
                  No sir: that is incomplete. It should not even compile.
                  Code:
                  if(StochRSI(HMA(26), 26)[0] > 0 && StochRSI(HMA(26), 26)[0] < 15)
                          EnterLong;

                  Comment


                    #10
                    Hello,
                    My deepest apologies and my mistake Koganam you are of course correct thank you for spotting error.
                    Cody B.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Cody. I will give this a try.

                      Comment


                        #12
                        Can you speak louder?







                        ----------------------------------------------------------------------------------------------------------------------------------
                        Dich vu tham tu thuę thám tử theo dői chồng chi phí thuę dịch vụ thám tử
                        Last edited by ledong123; 08-03-2016, 09:25 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        72 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        43 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        25 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        28 views
                        0 likes
                        Last Post TheRealMorford  
                        Started by Mindset, 02-28-2026, 06:16 AM
                        0 responses
                        59 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Working...
                        X