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

same actions with different variables

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

    same actions with different variables

    Hi,
    How do I organize its firmware function to perform the same actions with different variables?

    #2
    Hello,

    Thank you for the question.

    I am not sure I understand what you are asking, can you please add more detail to your question?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      How could I use other variables in my function, without duplicating code?
      (in one indicator file)

      Comment


        #4
        Hello,

        Are you asking how to use a variable in the entire script?

        If so you would need to define the variable outside of the methods body.

        Here are a couple of basic examples:

        Code:
        protected override void OnBarUpdate()
        {
             double lastPrice = 0;
        }
        This variable is defined inside of OnBarUpdate so it can only be used inside of OnBarUpdate.

        Code:
        private double lastPrice = 0;
        protected override void OnBarUpdate()
        {
              Print(lastPrice);
        }
        protected override void OnMarketData(MarketDataEventArgs e)
        {
             Print(lastPrice);
        }
        This variable is defined outside of the OnBarUpdate so it can be used in OnBarUpdate or any other method that is in the same scope as OnBarUpdate

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks! It really helped me

          Comment


            #6
            How to create my method inside the indicator

            Comment


              #7
              Hello,

              Thank you for the question.

              I will provide a simple example of this below, I would recommend reading some online tutorials on general C# syntax and logic, this will greatly help in understanding NinjaScript as NinjaScript is C#.

              For methods in NinjaTrader,

              Starting off in a indicator you will see the following lines near the top:
              Code:
              namespace NinjaTrader.Indicator
              {
                  [Description("Enter the description of your new custom indicator here")]
                  public class Test : Indicator
                  {
              All of your code will need to go in between the open bracket { of the public class and its closing bracket }

              To create a custom method you would need to define the method inside the class or:

              Code:
              namespace NinjaTrader.Indicator
              {
                  [Description("Enter the description of your new custom indicator here")]
                  public class Test : Indicator
                  {
                       private void TestMethod(string valueOfPrint)
                       {
                            Print(valueOfPrint);
                       }
              
                       protected override void OnBarUpdate()
                       {
                             TestMethod("Hello");
                       }
                   }
              }
              Please let me know if I may be of additional assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Thank you, now we understand each other. Great, it works !!! Thank NinjaTrader_Jesse
                Last edited by Andrew Sh; 01-16-2015, 03:08 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by spencerduran, Today, 11:48 AM
                4 responses
                9 views
                0 likes
                Last Post spencerduran  
                Started by kalli44100, 06-17-2024, 08:57 AM
                21 responses
                50 views
                0 likes
                Last Post kalli44100  
                Started by rene69851, Yesterday, 08:36 PM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_LuisH  
                Started by JLSwin, Today, 12:18 PM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by webus, Today, 06:17 AM
                8 responses
                28 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X