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

How to return value for indicator?

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

    How to return value for indicator?

    I am developing my first DMI cross indicator , basically what it is supposed to do is to return value of 1 when DI Plus cross above di Minus and return value of -1 when Di Minus cross above Di Plus .

    The weird thing is the indicator don't return +1 or -1 or even DIPlus, DIMinus or ADX value, it returns value that I have no idea at all of what it is ..

    Here are some screen shots .... of my code and the value returned . I am pulling out my hair.. help ....
    Attached Files

    #2
    cowcool, please make sure the CalculateOnBarClose settings for your chart and Market Analyzer loaded indicators match - http://www.ninjatrader-support.com/H...BarClose1.html

    Then recheck the values you get.

    Another good practice is to work Print() statements in your code to check the calculated indicator / variable values - http://www.ninjatrader-support2.com/...ead.php?t=3418

    Also, if you're new to coding in NinjaScript, those tutorials will be a good start - http://www.ninjatrader-support.com/H...verview18.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Done, Still experiencing the same result, what is command to return value for an indicator? I need this value to get showed on market analyzer ,

      it is supposed to be Value.Set , correct?


      Originally posted by NinjaTrader_Bertrand View Post
      cowcool, please make sure the CalculateOnBarClose settings for your chart and Market Analyzer loaded indicators match - http://www.ninjatrader-support.com/H...BarClose1.html

      Then recheck the values you get.

      Another good practice is to work Print() statements in your code to check the calculated indicator / variable values - http://www.ninjatrader-support2.com/...ead.php?t=3418

      Also, if you're new to coding in NinjaScript, those tutorials will be a good start - http://www.ninjatrader-support.com/H...verview18.html
      Last edited by cowcool; 06-01-2009, 06:56 AM.

      Comment


        #4
        Yes, the Value or Values[0] is the primary indicator value dataseries - http://www.ninjatrader-support.com/H...AndValues.html

        How many bars lookback to you use in the Market Analyzer?

        BertrandNinjaTrader Customer Service

        Comment


          #5
          14 bars ...


          I even entered Value.Set(1) right after protected override void OnBarUpdate() but I still don't see value of 1 in market analyzer ...




          protected override void OnBarUpdate()
          {
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.


          Value.Set(1);

          Comment


            #6
            Please use a larger setting in the Market Analyzer lookback, so the values can align properly. This works for me displaying the value of 1 on the chart as well as in the Market Analyzer -

            Code:
             
            protected override void OnBarUpdate()
            {
            Value.Set(1);
            }
            Please post the full code you use so we can take a look.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              I found it, The indicator returns the ADX value . May I know why it returns ADX value . Thx



              Code:
                  protected override void Initialize()
                      {
               
                          CalculateOnBarClose = true;
                          Add(new Plot(Color.FromKnownColor(KnownColor.DarkGreen), PlotStyle.Line, "Dplus0"));
                          Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Dminus0"));
                          Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Adx0"));
                      
                          Add(new Line(Color.FromKnownColor(KnownColor.Black), 0, "Above20"));
                          CalculateOnBarClose    = true;
                          Overlay                = false;
                          PriceTypeSupported    = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          // Use this method for calculating your indicator values. Assign a value to each
                          // plot below by replacing 'Close[0]' with your own formula.
                          
                                  
              Value.Set(1);
                          
                          //Print(DM(14).DiPlus[0]);
                      
                          if (DM(14).DiPlus[0] > DM(14).DiMinus[0]) 
                             
              
              {
                  
                          //Alert("myAlert", NinjaTrader.Cbi.Priority.High, "DPLUS CROSSABOVE DMINUS", "Alert1.wav", 10, Color.Black, Color.Yellow);
              
              Value.Set(1);
                          }
                          if (CrossAbove(DM(14).DiMinus,DM(14).DiPlus, 1)) 
              
                          {
                  
                          //Alert("myAlert", NinjaTrader.Cbi.Priority.High, "DMINUS CROSSABOVE DPLUS", "Alert1.wav", 10, Color.Black, Color.Yellow);
              
                              Value.Set(-1);
                          }
              
                                      
                          Dplus0.Set(DM(14).DiPlus[0]);
                          Dminus0.Set(DM(14).DiMinus[0]);
                          Adx0.Set(ADX(Close, 14)[0]); 
                          //Add(new Line(Color.Gray, 20, "diatas20"))

              Comment


                #8
                Because this is one of the three plots you have in your code...you can select which plot to display when loading the indicator in your Market Analyzer page. You need to check to which Values those Plots are 'linked; in the 'Properties' section in your code, I think you're into a conflict there because you assign two different values to Values[0], the primary indicator value.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Thx pal ... here is the code , how to find the linked plot ?

                  Please note ADEX is not ADX , it's a parameter I created on wizard


                  Code:
                  #region Properties
                          [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Dplus0
                          {
                              get { return Values[0]; }
                          }
                  
                          [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Dminus0
                          {
                              get { return Values[1]; }
                          }
                  
                          [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                          [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                          public DataSeries Adx0
                          {
                              get { return Values[2]; }
                          }
                  
                          [Description("")]
                          [Category("Parameters")]
                          public int ADEX
                          {
                              get { return aDEX; }
                              set { aDEX = Math.Max(1, value); }
                          }
                  
                          [Description("")]
                          [Category("Parameters")]
                          public int PERIOD
                          {
                              get { return pERIOD; }
                              set { pERIOD = Math.Max(1, value); }
                          }
                          #endregion
                      }
                  }
                  Originally posted by NinjaTrader_Bertrand View Post
                  Because this is one of the three plots you have in your code...you can select which plot to display when loading the indicator in your Market Analyzer page. You need to check to which Values those Plots are 'linked; in the 'Properties' section in your code, I think you're into a conflict there because you assign two different values to Values[0], the primary indicator value.

                  Comment


                    #10
                    You can see the Dplus0 being 'linked' to the Value or Values[0] dataseries

                    Code:
                    public DataSeries Dplus0
                            {
                                get { return Values[0]; }
                            }
                    I would perhaps just start with a simple version of your indicator doing one plot for your DI+ / DI- crossover condition.
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PaulMohn, Today, 03:49 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post PaulMohn  
                    Started by inanazsocial, Today, 01:15 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Jason  
                    Started by rocketman7, Today, 02:12 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post rocketman7  
                    Started by dustydbayer, Today, 01:59 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post dustydbayer  
                    Started by trilliantrader, 04-18-2024, 08:16 AM
                    5 responses
                    23 views
                    0 likes
                    Last Post trilliantrader  
                    Working...
                    X