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

No Trades when adding a 2nd Timeframe to a Strategy

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

    No Trades when adding a 2nd Timeframe to a Strategy

    Hello

    I've read the other thread that deals with a pretty similar question, but the answers didn't help me.

    I have a strategy that works perfectly in a single timeframe (100 Volume bars) environment. When I add a slower timeframe (500 Volume bars) to it with the BarsInProgress method, it compiles OK but then nothing happens, the strategy doesn't take a single trade anymore. When I apply it to a chart, its name appears in the upper left corner, but the two brackets "()" don't show, as they should when the strategy is enabled (I use Ninja V7 B15).

    I'm at a loss as to what to do.

    Thanks

    #2
    Hello,

    Can you plase check the log tab in the Control Center when you enable the strategy. Sounds like the strategy is encountering an error and then disabling it self.

    I look forward to assisting you further.

    Comment


      #3
      Hi Brett

      Just checked the log and you're right, there's an error message:
      "CountIf can't be run in multi-series strategies"

      I don't really understand the message though, because the CountIf method is clearly defined and only applies to the faster timeframe, so there shouldn't be any confusion in the code.

      Thanks

      Comment


        #4
        Hello,

        This is a method that will not run when you use a multi series strategy. This is why you are seeing this error. Even though you are using it in the correct BarsInProgress it will not run when a MultiSeries strategy is used.



        Let me know if I can be of further assistance.

        Comment


          #5
          This would require custom coding what the method does for use in a Multiseries strategy.

          Comment


            #6
            ok, thanks for the clarification Brett.

            Comment


              #7
              Are you by any chance aware of a code snippet that deals with this issue on the forum?

              Thanks

              Comment


                #8
                No I do not.

                You could setup a for loop to emulate this functionality However.

                Comment


                  #9
                  ok, will do that. Thanks a lot.

                  Comment


                    #10
                    Hi Brett

                    This is my original line of code (works very well):

                    if (Close [0] <SMA(200)[0] && (CountIf(delegate {return High[0] >= SMA(200)[0]-5*TickSize;}, 50) < 1)

                    {
                    // Do something here
                    }

                    I've followed your advice to use a for loop instead, but I'm struggling to integrate the "if" function in a for loop.

                    Could you point me in the right direction?

                    Comment


                      #11
                      Hello,

                      Can you please post what you have for the for loop so far so that I can point you in the write direction.

                      Thank You.

                      Comment


                        #12
                        Hi Brett

                        Thanks for your reply. This is what I've done so far, but it doesn't compile correctly yet:

                        for (int x = 0; x < 50; x++)

                        {
                        if (Close [0] <SMA(200)[0] && High[0] <= (SMA(200)[0]-5*TickSize)

                        {
                        // Do something here
                        }

                        }

                        Comment


                          #13
                          Hello,

                          Please see my below edits, your for loop is testing 50 bars back. Make sure that you have 50 bars before you start to execute your NinjaScript or you will get an error when you try to run this. See how I replaced the Zero's with X so that this is updated in the loop. ( I also revered back you >= and removed a ( so that it would compile and reflect what you had earlier in the post)

                          counterVariable = 0;

                          for (int x = 0; x < 50; x++)
                          {
                          if (Close [x] <SMA(200)[x] && High[x] >= SMA(200)[x]-5*TickSize)
                          {
                          counterVariable += 1;
                          }
                          }

                          then you would check how many times this occurred in the last 50 bars. Since your only looking for at least 1 occurrence you would then do the below.

                          if(counterVariable >= 1) // This would be how many occurances back your looking for
                          {
                          // Do Something
                          }

                          Let me know if I can be of further assistance.

                          Comment


                            #14
                            Thank you so much Brett. I'll integrate the code into my strategy and let you know how it goes.

                            Thanks again.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ScottWalsh, 04-16-2024, 04:29 PM
                            6 responses
                            27 views
                            0 likes
                            Last Post ScottWalsh  
                            Started by frankthearm, Today, 09:08 AM
                            10 responses
                            35 views
                            0 likes
                            Last Post frankthearm  
                            Started by GwFutures1988, Today, 02:48 PM
                            0 responses
                            2 views
                            0 likes
                            Last Post GwFutures1988  
                            Started by mmenigma, Today, 02:22 PM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by NRITV, Today, 01:15 PM
                            2 responses
                            9 views
                            0 likes
                            Last Post NRITV
                            by NRITV
                             
                            Working...
                            X