Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sum of indicator

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

    Sum of indicator

    Hi there,

    This is what I like to have as a strategy:
    Buy when the sum from last 5 bars of RSI 2 period is below 35.

    I have coded this:

    PHP Code:
            #region Variables
            // Wizard generated variables
            private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
            private DataSeries myDataSeries;
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
                myDataSeries = new DataSeries(RSI(2,1));
                Add(RSI(2, 1));
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (SUM(myDataSeries, 5)[0] < 35)
                {
                    EnterLong(DefaultQuantity, "L1of2");
                }
            
                        // EXIT LONGS
                if (Close[0] > SMA(5)[0])
                {
                    ExitLong("EXIT", "");
                }
            } 
    
    But this doesn't work, the counting I think..
    Do you know what I'm doing wrong? thanks!
    Last edited by no111; 01-20-2011, 01:14 PM.

    #2
    Also this doesn't work:

    PHP Code:
     (CrossAbove(SUM(myDataSeries, 4), 35, 1)) 
    

    Comment


      #3
      Hello,

      Thanks for your forum post.

      RSI(2,1)

      Is already a data series so you dont want to create one for it in Initialize().

      Also, since your setting in Initialize this is only called once therefor it is not updating when the bar updates.

      So you need to get this moved down to OnBarUpdate for it to update.

      Let me know if I can be of further assistance.

      BrettNinjaTrader Product Management

      Comment


        #4
        Originally posted by NinjaTrader_Brett View Post
        Hello,

        Thanks for your forum post.

        RSI(2,1)

        Is already a data series so you dont want to create one for it in Initialize().

        Also, since your setting in Initialize this is only called once therefor it is not updating when the bar updates.

        So you need to get this moved down to OnBarUpdate for it to update.

        Let me know if I can be of further assistance.

        Ok, thanks but when I move this:
        myDataSeries = new DataSeries(RSI(2,1));
        to OnBarUpdate() it sill doesn't work properly

        Comment


          #5
          It does work!

          thanks

          Comment


            #6
            Great. Glad to hear your up and running.
            BrettNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            668 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            377 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            110 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            580 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X