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

New Question

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

    New Question

    I have a custom indicator that has three levels, a high, low and average. If I write to exit a position( if close[0] < stopleves(3, 3, 3) then exit long) which price will it use? I'm assuming the lowest but do not know it that would be the case.

    Also, I need to reference the closing price yesterday at 4:15 for calculations today, and do not have a clue how to do this. Any help would be appreciated.

    Thanks.

    Bobby

    #2
    It will use the default value which I believe should be the first plot added in the indicator.

    See GetSessionBar() for retrieving the prior sessions close.

    RayNinjaTrader Customer Service

    Comment


      #3
      Didn't help

      I'm aware of this, but I need it to pull a specific time, 4:15. Since this is an electronic market, it doesn't consider the close to be 4:15. How would I use it to get the close at 4:15?

      Thanks.

      Comment


        #4
        Try playing around with GetBar()

        RayNinjaTrader Customer Service

        Comment


          #5
          Another Question

          The indicator plots 3 different values at the same time, so I'm not sure what you are saying when you refer to it being higher or lower than the first plot. I'm assuming that if you say > it will use the highest value of the indicator for that period, and the < the inverse. Is this true?

          Also, I am trying to refer the the close using the BarsArray method. When I use close(barsarray[1]) [1], it states that this is an indicator method, so how do I refer to the close of an added bar?

          Thank you.

          Comment


            #6
            I am not sure what you are referring to when you say I was referring to "high or lower etc...".

            Try:

            Closes[1][0]

            See - http://www.ninjatrader-support.com/H...V6/Closes.html
            RayNinjaTrader Customer Service

            Comment


              #7
              Talking about this

              It will use the default value which I believe should be the first plot added in the indicator.

              Top of post is where this is. Again, it plots 3 values at the same time, so does it use all of them?

              Comment


                #8
                bobby1001,

                Let us touch base here. The indicator you are using as your entry condition has 3 separate plots? You want to use the Close value of a secondary bars object that you added to your NinjaScript Strategy as part of your entry condition?

                What you are trying to determine is which of the three plots from the indicator will be tested?

                Normally you can compare to whichever plot value you want. I will provide a theoretical example here:
                Code:
                if (Close[0] > stopleves(3, 3, 3).High[0])
                     EnterLong();
                Code:
                if (Close[0] > stopleves(3, 3, 3).Low[0])
                     EnterLong();
                Code:
                if (Close[0] > stopleves(3, 3, 3).Avg[0])
                     EnterLong();
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thank you

                  Thank you, that makes sense. After the paratheses behind my indicator, you used a period. Why?

                  Yes, you are corrects in all your assumptions.

                  Again, thanks for all your help.

                  Comment


                    #10
                    I am not exactly sure of the proper implementation of your custom indicator, but most indicators will use DataSeries or plots to maintain its values. The reason I passed an index value is to access the exact value at a given bar as opposed to referencing the DataSeries object itself.

                    [0] means the value at the current bar. [1] means the value at the previous bar. [2] means the value two bars ago. etc etc.

                    So the implications of this usage is as follows:
                    • Close[0] means the close value on the current bar
                    • stopleves(3, 3, 3).Avg[0] means the average value of your indicator on the current bar
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Still problems

                      Thanks Josh. I understand all that. But for some reason, this isn't working, and I don't know why. Can you possibly tell me what I'm screwing up here.

                      Thanks.

                      Add(PeriodType.Tick, 4500);
                      Add(PeriodType.Tick, 2250);
                      CalculateOnBarClose = true;
                      }
                      ///<summary>
                      /// Called on each bar update event (incoming tick)
                      ///</summary>
                      protectedoverridevoid OnBarUpdate()
                      {
                      if (BarsInProgress != 0)
                      return;
                      // Condition set 1
                      if (TRIX(BarsArray[1], Trixin, 1).Signal[0] > TRIX(BarsArray[1], Trixin, 1).Signal[1]
                      && TRIX(BarsArray[1], Trixin, 1).Signal[1] < TRIX(BarsArray[1], Trixin, 1).Signal[2]
                      && TRIX(Trixinlong, 1).Signal[0] > TRIX(Trixinlong, 1).Signal[1])
                      {
                      EnterLong(DefaultQuantity, "");
                      }
                      // Condition set 2
                      if (TRIX(BarsArray[1], Trixin, 1).Signal[0] < TRIX(BarsArray[1], Trixin, 1).Signal[1]
                      && TRIX(BarsArray[1], Trixin, 1).Signal[1] > TRIX(BarsArray[1], Trixin, 1).Signal[2]
                      && TRIX(Trixinlong, 1).Signal[0] < TRIX(Trixinlong, 1).Signal[1])
                      {
                      EnterShort(DefaultQuantity, "");
                      }
                      // Condition set 3
                      if (Closes[2][0] > StopLevels(Middle, Top, Bottom).Plot0[0])
                      {
                      ExitShort("", "");
                      }
                      // Condition set 4
                      if (Closes[2][0] < StopLevels(Middle, Top, Bottom).Plot0[0])
                      {
                      ExitLong("", "");
                      }
                      }

                      Comment


                        #12
                        Please add this at the beginning of OnBarUpdate() method.

                        Code:
                        if (CurrentBar < 2)
                             return;
                        You can read up on this on this tip here: http://www.ninjatrader-support.com/v...ead.php?t=3170
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by MacDad, 02-25-2024, 11:48 PM
                        7 responses
                        158 views
                        0 likes
                        Last Post loganjarosz123  
                        Started by Belfortbucks, Today, 09:29 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post Belfortbucks  
                        Started by zstheorist, Today, 07:52 PM
                        0 responses
                        7 views
                        0 likes
                        Last Post zstheorist  
                        Started by pmachiraju, 11-01-2023, 04:46 AM
                        8 responses
                        151 views
                        0 likes
                        Last Post rehmans
                        by rehmans
                         
                        Started by mattbsea, Today, 05:44 PM
                        0 responses
                        6 views
                        0 likes
                        Last Post mattbsea  
                        Working...
                        X