Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Math in Parameter Input field?

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

    Math in Parameter Input field?

    Hi,
    I have a parameter in a custom data series. Instead of entering a numerical value, can I enter a mathematical expression? So instead of entering 4, can I enter 5-1?

    Next, suppose I have Param1, which I set equal to 5.
    Now suppose I want Param2 to be equal to Param1-1 to get 4.

    Can I also use reserved words like High, Low, and Close in creating these mathematical expressions?

    This is available in other trading platforms I've worked with so hoping it is available here as well.

    Thanks in advance.
    biegea

    #2
    biegea, the data series itself would allow you to store any value for the given type of the series. You refer to a custom indicator here with a user input field, correct?

    Do you have an example for us what you want to setup?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by biegea View Post
      Hi,
      I have a parameter in a custom data series. Instead of entering a numerical value, can I enter a mathematical expression? So instead of entering 4, can I enter 5-1?

      Next, suppose I have Param1, which I set equal to 5.
      Now suppose I want Param2 to be equal to Param1-1 to get 4.

      Can I also use reserved words like High, Low, and Close in creating these mathematical expressions?

      This is available in other trading platforms I've worked with so hoping it is available here as well.

      Thanks in advance.
      biegea
      I'm not sure if you want to do this via code or the Indicator Settings window.
      ninZa
      NinjaTrader Ecosystem Vendor - ninZa.co

      Comment


        #4
        Originally posted by ninZa View Post
        I'm not sure if you want to do this via code or the Indicator Settings window.
        Thanks for the clarifying question. I am looking to do it via Indicator Settings window.

        I don't want to cut and paste the indicator code because I'm working with other people's code that I am not comfortable disclosing.

        But a simple (albeit trivial) example starting point would be this: Suppose I have a simple moving average that is expecting an integer input so I could enter "20" to make a standard 20-period moving average, for example. The first question is that instead of entering "20," for example, can I enter "4+16"?

        The next question would be if I can do straight math (enter "4+16" in the indicator parameter input field, for example), then can i also do math with variables. For example, if the moving average had an input representing what value I wanted the MA calc to be based on (traditionally the bar close), could I do math on variable values -- for example "(High+Low)/2" -- at least if we assume that the variables were defined in the underlying code?

        Thanks for the continued help,
        biegea

        Comment


          #5
          Originally posted by biegea View Post
          Thanks for the clarifying question. I am looking to do it via Indicator Settings window.

          I don't want to cut and paste the indicator code because I'm working with other people's code that I am not comfortable disclosing.

          But a simple (albeit trivial) example starting point would be this: Suppose I have a simple moving average that is expecting an integer input so I could enter "20" to make a standard 20-period moving average, for example. The first question is that instead of entering "20," for example, can I enter "4+16"?

          The next question would be if I can do straight math (enter "4+16" in the indicator parameter input field, for example), then can i also do math with variables. For example, if the moving average had an input representing what value I wanted the MA calc to be based on (traditionally the bar close), could I do math on variable values -- for example "(High+Low)/2" -- at least if we assume that the variables were defined in the underlying code?

          Thanks for the continued help,
          biegea
          #1 You can open an EMA and try entering 4+16 for the period and see what happens. 20 is understood as an integer, but 4+16 is understood as a string. So math expression is not supported when you input values for integers or doubles.

          #2 They are not supported by default. However you can add some codes to do this:

          Suppose you want the Input to be Factor1*Value1 + Factor2*Value2
          where possible values are:
          Factor1 and Factor2: any doubles like 0, 1, 2.5, 3,...
          Value1 and Value2: any of the series Low, High, Open, Close, Typical, Weighted, Median

          Declare:
          double Factor1, Factor2;
          PriceType Value1, Value2;
          DataSeries newSeries;
          So in Initialize of your code define a new series:
          newSeries = new DataSeries(this);
          In OnBarUpdate:
          Code:
          double price1;
          				switch (Value1) {
          					case PriceType.Open:
          						price1 = Open[0];
          						break;
          					case PriceType.High:
          						price1 = High[0];
          						break;
          					case PriceType.Low:
          						price1 = Low[0];
          						break;
          					case PriceType.Median:
          						price1 = Median[0];
          						break;
          					case PriceType.Weighted:
          						price1 = Weighted[0];
          						break;
          					case PriceType.Typical:
          						price1 = Typical[0];
          						break;
          					default:
          						price1 = Close[0];
          						break;
          				}
          Do similar for price2.

          And still in OnBarUpdate():

          newSeries.Set(Factor1*price1 + Factor2*price2);
          Compute EMA:

          Value.Set(EMA(newSeries, Period)[0]);
          ninZa
          NinjaTrader Ecosystem Vendor - ninZa.co

          Comment


            #6
            I apologize for the delay in my response, especially when yours was so quick. Thank you ninZa! I still have to try this out, but this looks like it just may answer the mail -- I am excited to give it a try. Thank you again!

            Comment


              #7
              Originally posted by biegea View Post
              I apologize for the delay in my response, especially when yours was so quick. Thank you ninZa! I still have to try this out, but this looks like it just may answer the mail -- I am excited to give it a try. Thank you again!
              My pleasure.
              Just leave a message here when you encounter any problem with the coding.

              Great weekend,
              Pi
              ninZa
              NinjaTrader Ecosystem Vendor - ninZa.co

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              6 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              2 views
              0 likes
              Last Post DanielTynera  
              Started by yertle, 04-18-2024, 08:38 AM
              9 responses
              41 views
              0 likes
              Last Post yertle
              by yertle
               
              Started by techgetgame, Yesterday, 11:42 PM
              0 responses
              12 views
              0 likes
              Last Post techgetgame  
              Started by sephichapdson, Yesterday, 11:36 PM
              0 responses
              2 views
              0 likes
              Last Post sephichapdson  
              Working...
              X