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 FatCanary, 06-11-2021, 09:11 AM
                17 responses
                1,042 views
                0 likes
                Last Post Laurentvan  
                Started by csrkkalyan, 11-18-2023, 08:38 PM
                4 responses
                54 views
                0 likes
                Last Post csrkkalyan  
                Started by sidlercom80, 10-28-2023, 08:49 AM
                94 responses
                1,121 views
                0 likes
                Last Post rare312
                by rare312
                 
                Started by Conceptzx, Yesterday, 06:56 PM
                1 response
                12 views
                0 likes
                Last Post bltdavid  
                Started by roblogic, Yesterday, 06:20 PM
                1 response
                26 views
                0 likes
                Last Post elirion
                by elirion
                 
                Working...
                X