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

Return more values in a strategy from indicator

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

    Return more values in a strategy from indicator

    is 'possible to get 3 values ​​of an indicator in a strategy?

    If I put into value.set (Variable) in the indicator and I see this value when calling the indicator in the strategy ..

    But with 3 values ​​I do not know how you can do

    #2
    Hello esignal,

    Thank you for your note.

    You would need to set other DataSeries in the script if you want to get more access to more values.
    http://www.ninjatrader.com/support/h...ries_class.htm

    Let me know if I can be of further assistance
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      can you follow me in this stage of connection between indicator and strategy ... I'm new in programming ninja

      My Indicators:

      protectedoverridevoid Initialize()
      {
      Add(
      new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
      Add(
      new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
      Add(
      new Line(Color.FromKnownColor(KnownColor.DarkOliveGree n), 0, "P1"));
      Add(
      new Line(Color.FromKnownColor(KnownColor.Khaki), 0, "P2"));
      Overlay =
      false;

      pass1 =
      new DataSeries(this);
      pass2 =
      new DataSeries(this);
      }
      ///<summary>
      /// Called on each bar update event (incoming tick)
      ///</summary>
      protectedoverridevoid OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.
      Plot0.Set(Open[0]);
      Plot1.Set(Close[
      0]);

      pass1.Set(Open[
      0]);
      pass2.Set(Close[
      0]);

      }



      OK...i create indicators with 2 dataseries...
      And now what do I write in the strategy to retrieve the values ​​ pass1 pass2?

      Comment


        #4
        Esignal,

        You will need to call the indicator name and the property that you wish to grab

        Example of this is the MACD -

        Code:
        MACD(int fast, int slow, int smooth).Avg[0];
        This will create a new instance of the MACD in the Strategy. You will need to pass values through it for the fast, slow, and smooth. The Avg tells the script to access the data from the Avg plot and [0] will index the current bar's value for the Avg plot.

        This will be a similar setup with your custom indicator.

        Let me know if I can be of further assistance.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Instread of MACD(int fast, int slow, int smooth).Avg[0]

          i put MyIndicator(parameters).pass1[0]

          Is correct?

          thanks you...now i test it

          Comment


            #6
            I did a test with your example:

            double contalevel2 = 0;
            contalevel2 = MACD (3,3,6). Avg [10];

            Print (contalevel2);

            OUTPUT:
            0
            0
            0

            are all zero

            what did I do wrong?

            Comment


              #7
              ///</summary>
              protectedoverridevoid OnBarUpdate()
              {
              // Use this method for calculating your indicator values. Assign a value to each
              // plot below by replacing 'Close[0]' with your own formula.

              double contalevel2=0;
              if (CurrentBar < 20) return;

              contalevel2=MACD(
              3,3,6)[10];

              Print(Time[
              0] + "$ " + contalevel2);

              }


              OUTPUT :

              0
              0
              0
              0
              0
              0
              0

              Comment


                #8
                Esignal,

                That is because your Fast and Slow settings are the same.

                MACD(3,3,6)[10];

                You will need to offsetting values here.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  you're right ... what a stupid I am .. I took the only example in case that does not work

                  Comment


                    #10
                    I continue in this thread other problems due to the recall indicators..


                    I use my previous indicator

                    DELETELEVELS (Name indicators)
                    -------

                    double
                    gg=OBV_Ratio;

                    Value.Set (dd);

                    -------


                    I tried to recall from another indicator
                    ---------------------------------
                    if (CurrentBar <20) return;

                    double contalevel2;
                    contalevel2=DELETELEVELS (5) [1];


                    Print (Time [0] + "$" + contalevel2);
                    --------------------------------

                    but I get this error (see below)
                    Attached Files
                    Last edited by esignal; 01-15-2014, 11:27 AM.

                    Comment


                      #11
                      Esignal,

                      Can you please attach your custom script that you are trying to call in the new script so that I can test it on my end?

                      You can attach documents by clicking Go Advanced -> Paperclip in the top tool bar
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Ok .. I have attached the file ... (DELETELEVELS is the beginning of a program .. so you will not find in a code that works))

                        The indicator BobbyTest called DELETELEVELS
                        Attached Files

                        Comment


                          #13
                          Esignal,

                          I tested out your script and you shouldn't have to pass 5 through the ().
                          Just leave it blank as your indicator does not take any 'Arguments' for the script
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you ...

                            still 2 questions

                            1) When I run bobbytest to display the data that is passed from deletelevels gives me the following error (the error is in real time) :
                            Error on calling 'OnBarUpdate' method for indicator 'DELETELEVELS': Object reference not set to an instance of an object"

                            *******
                            i noticed that the error is due to this instruction"ChartControl.ChartPanel.Invalidate ()"
                            inside the indicator DELETELEVELS...

                            How can I fix this error in maintaining that istruction?

                            2)if I want to pass a parameters(depthLevel) ... How do I set the indicator DELETELEVELS?

                            Thanks for the time you lose with me
                            Last edited by esignal; 01-16-2014, 12:16 PM.

                            Comment


                              #15
                              Why no one answer me?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              938 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              27 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X