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

Help in coding HighestBar & LowestBar

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

    Help in coding HighestBar & LowestBar

    I want to get the value of the Last Bar close with reference to 3 days Highest High & Lowest Low on a -1 to +1 scale into Market Analyzer.

    double L1 = -1 + 2 * ( Close[0] - LowestBar(Low, 3)[0])/ (HighestBar(High, 3)[0] - LowestBar(Low, 3)[0]);

    Above code gives the error as attached.

    Any help is very much appreciated.

    Thanks.
    murthymsr
    Attached Files

    #2
    murthymsr,

    you would want use the MAX and MIN methods for this task instead -



    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks, Bertrand, it worked fine, just as desired.
      But I couldn't make out the difference, though !

      Thanks a Lot.
      murthymsr

      Comment


        #4
        I´ll borrow this thread for a related query;

        I realize how these two differe, one returning bars ago, the other the value of that bar. However, "LowestBar" has no "[int barsAgo]". How do I get that method to start looking (in retrospect) on a historic bar?! As it is it looks from the current bar back.

        MIN(IDataSeries input, int period)[int barsAgo]

        LowestBar(IDataSeries series, int lookBackPeriod)

        TNX!

        Comment


          #5
          Hi Freen,

          Unfortunately LowestBar() does not offer this bars ago field. As you indicate, all lookbacks start from the current bar.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Tnx Ryan. Strange reasoning giving one of the methods this capability mind these methods are closely related and often used in conjuction. Can I put this on my "wishlist" : )?


            This is my workaround if someone else bumps into the same need:

            // "LowshiftDS" substitutes the X barsAgo shifted array:
            LowshiftDS.Set(Lows[0][X]);

            // ...and is put in the method
            int lowestbar = LowestBar(LowshiftDS, lookback);

            // ...and is shifted back to come in sync again;
            int lowest = lowestbar + X


            This makes the X most current bars a "blind spot" for the LowestBar() method. I´m not a programmer so there´s surely some more efficient way.
            Last edited by FREEN; 02-10-2011, 04:59 AM.

            Comment


              #7
              Thank you for sharing this work- around, FREEN. That seems like a good technique for this. I will forward your suggestion to offer a bars ago value to this method.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thanks for forwarding this Ryan. The coded ended up pretty complicated due to the lack of the barsAgo field in LowestBar/HighestBar. If the barsAgo field was on the LowestBar() / HighestBar() methods instead there would have been no need for the MIN() / MAX() methods at all. As bellow;

                int lowestbar = LowestBar(Low, lookback)[barsAgo];
                double lowestprice = Low[lowestbar]
                Last edited by FREEN; 02-10-2011, 04:57 AM.

                Comment


                  #9
                  Trying to narrow down on a problem that seem to be caused by the MIN/MAX methods. Doesn´t the MIN/MAX methods work in multiseries? Ie:

                  MAX(Highs[0], lookback)[0];

                  Edit: It seems the code run once for each dataseries. "Print(CurrentBar);" outputs current bar ID once for one dataseries, twice for two dataseries etc. This is the code that cause trouble:


                  if(HS && buy)
                  {
                  buy =
                  false;
                  res = Highs[
                  0][0];
                  resistance = Highs[
                  0][0];
                  end = CurrentBar;
                  lookback = CurrentBar - start;
                  if (lookback < 256) // Error if >256
                  {
                  lowestbar = LowestBar(LowshiftDS, lookback)+
                  1;
                  lowestprice = MIN(Lows[
                  0], lookback)[1];
                  DrawDiamond(
                  "Lowdiamond"+CurrentBar.ToString(), true, lowestbar, lowestprice, Color.Gray);
                  DrawText(
                  "Lowtext"+CurrentBar.ToString(), lowestprice.ToString(), lowestbar, lowestprice -.5, Color.Black);
                  }
                  DrawText(
                  "Restext"+CurrentBar.ToString(), Highs[0][0].ToString(), 0, resistance +.3, Color.Black);
                  }
                  LowestpriceDS.Set(lowestprice);
                  ResistanceDS.Set(resistance);
                  Last edited by FREEN; 02-22-2011, 09:31 AM.

                  Comment


                    #10
                    Frederik,
                    Thanks for the note.
                    I believe they should, what issues do you see?
                    protected override void OnBarUpdate()
                    {
                    if (BarsInProgress == 0 && CurrentBars[0] > BarsRequired && CurrentBars[1] > BarsRequired)
                    Plot0.Set(MAX(Highs[1], 10)[0]);
                    }

                    Thanks Bertrand, kindly see post bellow for details. I seems the OnBarUpdate() method gets called once for each dataseries I add to the indicator. This conclusion is made from doing a Print(CurrentBar). This returns a, b, c... when using one ds; a, a, b, b, c, c for two ds; a, a, a, b, b, b, c, c, c... for three ds etc.

                    Comment


                      #11
                      Correct, OnBarUpdate() is called for each Add()ed series you need to filter in your code like in my example with the BarsInProgress to see which series calls it.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Thanks Bertrand! That´s clearly stated in the description of the "BarsInProgress" method, sorry my ignorance. I´ll have to read some more on this. I´m confused on the use of that feature. I´ll get back if I don´t get it sorted out.

                        Comment


                          #13
                          No worries - have you checked into this intro link yet? The basic concept is the same for indicators and strategies now in NT7:

                          BertrandNinjaTrader Customer Service

                          Comment


                            #14
                            Yeah, I did. Obviously I´ll have to read it again with a bit more experienced eyes this time. Never worked in 6.5 - started when beta 7 was released.

                            Wrapping a large codeblock with a BarsInProgress if statement did the trick, not sure why yet : )

                            Thanks!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by stafe, 04-15-2024, 08:34 PM
                            9 responses
                            42 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by frslvr, 04-11-2024, 07:26 AM
                            7 responses
                            111 views
                            1 like
                            Last Post caryc123  
                            Started by rocketman7, Today, 09:41 AM
                            3 responses
                            8 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by traderqz, Today, 09:44 AM
                            2 responses
                            5 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by rocketman7, Today, 02:12 AM
                            7 responses
                            31 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Working...
                            X