Announcement

Collapse
No announcement yet.

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.

    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.

        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.

              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 Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                546 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X