Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Confirmation by a slower Timeframe

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

    #16
    Baruch,

    I played a bit with the "Closes" concept and it works well when I use it like you suggested, ie:
    Closes[1][0]

    With the MACD however, the expression MACD(12, 26, 9)[1][0] <0 produces the following error message:
    Cannot apply indexing with [] to an expression of type 'method group'

    I understand the error message, but I don't know why it appears in this case because I use the same MACD expression in my single-timeframe code a lot without any problems.

    Any pointer as to what I'm missing would be greatly appreciated.

    Thanks

    Comment


      #17
      Hi laocoon,

      Here's what you can use for MACD calculated on secondary series:

      double secondarySeriesMacd = MACD(Closes[1], 12, 26, 9)[0];
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        Brilliant, thanks a lot RyanM.

        Happy New Year!

        Comment


          #19
          Originally posted by laocoon View Post

          if (BarsInProgress == 1) //Code for slower timeframe

          {
          if (Open[1] <Close [1])
          {
          SlowTimeframeLong = true;
          }


          if (Open[1] >Close [1])
          {

          SlowTimeframeShort = true;
          }

          }
          Look again at this code section, and you will see that after the first green and red bars, both your bools are identically true, as you have never reset them. Therefore, they are now essentially ignored and do not gate your faster time frame signals anymore.

          Comment


            #20
            Thanks for pointing that out Koganam, I was struggling with the "BarsInProgress" approach anyway (probably also because of the mistake you highlighted) and find the "Closes[1][0]" way of incorporating a second timeframe much easier.

            Comment


              #21
              RyanM,

              Just a quick question: I'm using the "Closes" command and it works very well, but I'm still having
              some trouble with its syntax from time to time. For example, when apyling it to the Slope function, I'm getting an error message.

              Here's the original code snippet: Slope (SMA(20), 14, 0)
              When I add the "Closes" bit, it doesn't work anymore so I guess I'm getting something mixed up here:

              Slope(Closes[1]SMA(20), 14, 0)[0]

              Thanks for giving me a hint.

              Comment


                #22
                Hello,

                When you want to output an indicator value of a secondary series you would need to do the following.

                SMA(BarsArray[1], 14)[0];


                This is detailed here in the section using bars objects as input to indicator methods.

                BrettNinjaTrader Product Management

                Comment


                  #23
                  Hello Brett

                  Thanks for your reply. I found the "Closes" method much easier to implement than the "BarsArray" method and use it already successfully with a few other indicators. RyanM was kind enough to show me how it works when he posted this example for the MACD:

                  "Here's what you can use for MACD calculated on secondary series:
                  double secondarySeriesMacd = MACD(Closes[1], 12, 26, 9)[0]; "

                  I want to achieve exactly the same thing with the Slope indicator, but as I said I somehow got my syntax mixed up.

                  Thanks

                  Comment


                    #24
                    Yes you can use this way.

                    Slope(SMA(Closes[1], 20), 14, 0)[0]
                    BrettNinjaTrader Product Management

                    Comment


                      #25
                      Thanks Brett. I did as you suggested, but I'm getting CS 1501 & CS 0021 Error Messages for the following code:

                      if (Slope(SMA(Closes[1], 20), 14, 0)[0] >-5)
                      {
                      LongEntry = true;
                      }

                      Thanks

                      Comment


                        #26
                        Try this:

                        if (Slope(SMA(Closes[1], 20), 14, 0) >-5)

                        Compiled on my side when I tested. Slope is not a data series method.

                        -Brett
                        BrettNinjaTrader Product Management

                        Comment


                          #27
                          Brilliant, thanks a lot for your help Brett.

                          Comment


                            #28
                            Hello Brett

                            Sorry to bother you again with a small syntax issue, but I'm having trouble getting the following snippet to compile: (the condition is that the latest candle of the secondary series closes above the 100 SMA of the secondary series.

                            (Closes[1][0]> SMA(100)[1][0])

                            Thanks for helping me out.

                            Comment


                              #29
                              SMA(Closes[1], 100)[0]
                              BrettNinjaTrader Product Management

                              Comment


                                #30
                                Thanks a lot Brett, have a great day.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by argusthome, Yesterday, 10:06 AM
                                0 responses
                                22 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                19 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                14 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                10 views
                                0 likes
                                Last Post TheRealMorford  
                                Started by Mindset, 02-28-2026, 06:16 AM
                                0 responses
                                41 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X