Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Specifying input data series to indicator on code

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

    Specifying input data series to indicator on code

    Hi,

    I need to use an indicator output series as input data series on another indicator. I can do it manually using the "input" parameter, but I'm not able to do it via code.

    I've tried to put it as the first parameter but I always get errors; What's the correct way of doing it?

    #2
    Hello Manugarc,

    Thank you for writing in.

    I’ve provided an example of passing a SMA of the data series as the input for a SMA.
    SMA(SMA(14), 14)[0]

    Used in an if statement,
    if (SMA(SMA(14), 14)[0] < SMA(14)[0])

    If you’re able to build the statement in the strategy wizard, you could always hit the “view code” button, which will reveal the code. I’ve provided a screen shot.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your answer Alan,

      I would like (not sure if it's possible) to avoid to invoke the indicator on each OnbarUpdate for two reasons:

      1) If I'm running a simulation, it will take more time to be executed, since there are multiple values that will be calculated on each tick/candle that were already calculated on previous ticks/candles.

      2) I would like the indicator plot to be automatically added to the main chart when I run each simulation and avoid having to add it manually each time.

      I would be specially interested on point 2; Each simulation I run uses different parameters for indicator, which I can calculate from the code, but if I have to calculate them manually to add the indicator to the chart once each simulation ends It will take me more time.

      Isn't it possible to do something like this?:

      Code:
      protected override void OnStateChange()
      {
              ...
              if (State == State.Configure){
      
                      INDI_NORMAL indicator1 = INDI_NORMAL(1,2);
                      INDI_BASED_ON_INDI indicator2 = INDI_BASED_ON_INDI(indicator1[0]);
      
                      AddChartIndicator(indicator1);
                      AddChartIndicator(indicator2); // <==== I'm interested on this
              }
      }
      
      
      protected override void OnBarUpdate()
      {
      
          double val_aux = indicator2.Values[0][1]; // <==== Would be also great to be able to do this
          ...
      }
      Last edited by manugarc; 10-31-2016, 03:15 PM.

      Comment


        #4
        Hello Manugarc,

        I do not have the indicator code you are referencing so I’ve replicated what I believe you are trying to do using the SMA indicator.

        First you have to create private SMA variables,

        private SMA mySMA;
        private EMA myEMA;

        Then I add a plot under State.DateLoaded, set the value of mySMA equal to SMA(10) and then set the value of myEMA equal to the simple moving average of the myEMA EMA series.

        Under OnBarUpdate you can then set the plot equal myEMA.

        I have attached the code I describe above.

        Please let us know if you need further assistance.
        Attached Files
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by quantismo, 04-17-2024, 05:13 PM
        4 responses
        30 views
        0 likes
        Last Post quantismo  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        31 views
        0 likes
        Last Post love2code2trade  
        Started by cls71, Today, 04:45 AM
        2 responses
        10 views
        0 likes
        Last Post eDanny
        by eDanny
         
        Started by proptrade13, Today, 11:06 AM
        0 responses
        5 views
        0 likes
        Last Post proptrade13  
        Started by kulwinder73, Today, 10:31 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X