• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Newbie - Help with simple programming

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

    Newbie - Help with simple programming

    I am attempting to learn how to do simple programming to create strategies. I wish to just take the sum of all prices from 200 bars ago and display them.

    I need help with:

    When I attempt to compile, I get an error message saying sumBarPrice is already defined
    Also, I would like to draw the number on the chart somewhere in the right top corner fixed... something like 'DrawTextFixed(string tag, string text, TextPosition textPosition)' but I am unsure of how to implement this this
    Any help is greatly appreciated!

    This is what I have so far using a for loop

    Code:
    namespace NinjaTrader.Indicator {
    
    public class NewStrategy101 : Indicator
    {
        #region Variables
    
        int sumBarPrice = 0;
    
        #endregion
    
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
    
            for (int barsAgo = 0; barsAgo < 200; barsAgo++)
                {
                    sumBarPrice = sumBarPrice + Input[barsAgo];
                }    
        }
    
        protected override void OnBarUpdate()
        {
        }
    
        #region Properties
    
        public int sumBarPrice
        {
            get { return sumBarPrice; }
            set { sumBarPrice = Math.Max(1, value); }
        }
        #endregion
    
    }
    
    }
    Last edited by NinjaTrader_Matthew; 12-27-2012, 01:34 PM.

    #2
    I've highlighted in Red below where the error was coming from and correct it for you. You will want to ensure the Public variable for the property does not have the same namecase as the private variable. Notice how I've simply changed it from sumBarPrice to SumBarPrice

    Code:
            #region Properties
            
            public int SumBarPrice
            {
                get { return sumBarPrice; }
                set { sumBarPrice = Math.Max(1, value); }
            }
            #endregion
            
        }
    }
    Below is an example of how to use DrawTextFixed:

    Code:
    DrawTextFixed("myText", sumBarPrice.ToString(), TextPosition.TopRight);
    Please let me know if you have additional questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      help!

      This is what I have so far, I load the strategy but it doesn't seem to show anything on the chart I load it on. Help please! To summarize, I just want the sum of the last 200 bars of price data shown in the top right corner fixed.

      Code:
      namespace NinjaTrader.Strategy
      {
      
          [Description("Take sum of last 200 bars")]
          public class Newbie101 : Strategy
          {
              #region Variables
      
              double sumBarPrice; 
      
              #endregion
      
              protected override void Initialize()
              {            
                  for (int barsAgo = 0; barsAgo < 200; barsAgo++)
                      {
                          sumBarPrice = sumBarPrice + Input[barsAgo];
                      }
                      
                  DrawTextFixed("myText", sumBarPrice.ToString(), TextPosition.TopRight);
              }
              
              protected override void OnBarUpdate()
              {
              }
              
              #region Properties
              [Description("")]
              [GridCategory("Parameters")]
              public double SumBarPrice
              {
                  get { return sumBarPrice; }
                  set { sumBarPrice = Math.Max(1, value); }
              }
              #endregion
      
          }
      }

      Comment


        #4
        Sorry, I missed this yesterday - you want to put your logic in OnBarUpdate().

        Initialize() is only called when you first start the strategy. OnBarUpdate() will run through each historical bar on the chart and will continue to be called when each new bar is updated.
        MatthewNinjaTrader Product Management

        Comment


          #5
          I tried that but still I cannot see anything. Nothing is displayed

          Comment


            #6
            Check the log tab of the Control Center for any errors.

            You'll also want to try using Print() statements to verify that the information that is being calculated is what you expect.

            We've gathered more information on debugging your code in the thread below:

            http://www.ninjatrader.com/support/f...ead.php?t=3418

            Additionally, we have a native SUM() method to give you the summation of a data series:

            http://www.ninjatrader.com/support/h...mation_sum.htm

            Code:
            protected override void OnBarUpdate()
            {
            sumBarPrice = SUM(200)[0];
            
             DrawTextFixed("myText", sumBarPrice.ToString(), TextPosition.TopRight);
            }
            Last edited by NinjaTrader_Matthew; 12-28-2012, 12:05 PM.
            MatthewNinjaTrader Product Management

            Comment


              #7
              This thing doesn't seem to do anything at all

              Code:
              DrawTextFixed("tag1", sumBarPrice.ToString(), TextPosition.TopRight);

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by tecmisc1, Today, 09:57 AM
              0 responses
              2 views
              0 likes
              Last Post tecmisc1  
              Started by mbesha, Today, 09:26 AM
              0 responses
              1 view
              0 likes
              Last Post mbesha
              by mbesha
               
              Started by Brillo, Today, 08:58 AM
              0 responses
              6 views
              0 likes
              Last Post Brillo
              by Brillo
               
              Started by avrege, Today, 01:48 AM
              2 responses
              14 views
              0 likes
              Last Post avrege
              by avrege
               
              Started by markbb10, Today, 07:14 AM
              0 responses
              7 views
              0 likes
              Last Post markbb10  
              Working...
              X