Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How would I express the math for the lowest of 4 bars?

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

    How would I express the math for the lowest of 4 bars?

    The high of 3 bars ago and the low of the current bar is not always the lowest of the last 4 bars, sometimes the lowest low of the 4 bars is 1bar ago.

    When the current bars low is the lowest of 4, of course I have this: 3, High[3], 0, Low[0]. How would I express the math for the lowest of the 4 bars?
    -thanks

    Click image for larger version

Name:	2024-12-30 12_38_21-Chart - 5m RTH.png
Views:	132
Size:	2.3 KB
ID:	1329438 ​

    #2
    Hello trdninstyle,

    You can use LowestBar and HighestBar or the MAX or MIN indicators to find the lowest and highest bars ago or prices.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

    Comment


      #3
      I just did the Math.Min ... Thanks !!

      High[3], 0, Math.Min(Low[1], Low[0]),

      Click image for larger version

Name:	2024-12-30 13_53_58-Chart - 5m RTH.png
Views:	128
Size:	2.7 KB
ID:	1329454

      One other thing, have you ever run across this? It stays there even when I'm on the internet doing other stuff, not just over my charts.
      Click image for larger version

Name:	2024-12-30 14_03_29-Chart - 5m RTH.png
Views:	118
Size:	23.2 KB
ID:	1329455





      Comment


        #4
        Hello trdninstyle,

        I haven't run into that specifically while using the editor. Are there any specific steps to see that happen? For example are you doing something like hovering a type to have the intelleprompt open and then using a windows command to change the window to the browser?

        Comment


          #5
          No, not that. The last time this happened was when I imported an indicator so I removed it then it stopped happening.

          Yesterday I converted my strategy over to an indicator then once I applied it to my charts it started to happen. Its a bit odd.
          I can remove my own indicator to see if it goes away but before I do, I'll drop it here so I can retrieve it. Any thoughts? Should I try that?

          Comment


            #6
            I ran into where 2 bars ago was lower than both 1 and 0 bars ago, then added that additional argument but put me over the limit.
            I seen Math.Extensions but I did not apply it right.

            Is this what Math.Extensions is for?

            Click image for larger version  Name:	2024-12-30 15_26_57-2024_12_30_15_26_06_NinjaScript_Editor_Indicator_Channels.png - Paint.png Views:	0 Size:	17.3 KB ID:	1329468
            Click image for larger version  Name:	2024-12-30 15_38_12-Chart - 5m RTH.png Views:	0 Size:	4.1 KB ID:	1329469

            Comment


              #7
              Hello trdninstyle,

              When you import items the NinjaScript system is refreshed so that may have had something to do with it. If that was after importing a specific item and it stopped after removing it then it could also relate to that item. I am otherwise not aware of anything specific that would cause that to happen.

              Regarding MathExtensions, that is not a standard NinjaScript type so that may relate to something you have imported. To find the low of X bars ago you can use either MIN or LowestBar, both support a lookback period and series.

              Comment


                #8
                When I initially changed strategy over to indicator I accidently forgot to change the name space to indicator and left it strategy then had errors, I tried to work those out then I noticed my mistake and fixed it but then I think I must have had issues after that, including that intelleprompt item hovering in the top left corner.

                I started over and placed my indicator back in the strategy as a strategy, deleted the indicator and then converted it back to indicator w/out that mistake. That thing is not showing up in the top right corner. What would cause my indicator not still being on the chart after closing down NT? This time I only disconnected power reconnected power and it stayed.
                -I tried again, shut down > saved changes.. I waited this time, turned NT back on then my indicator's not on chart. My other one is, Gaps.


                With the MIN and MAX I can only with 2 arguments, I put a 3rd in there like 2 bars ago along with current bar & 1 bar ago it won't allow me. What does LowestBar look like?
                I did read those two links tried it got it to compile but didnt do something quite right.

                Comment


                  #9
                  Hello trdninstyle,

                  I wouldnt be certain what the problem is, if you are converting a strategy to an indicator the best way to do that is to make a new indicator so you have the default structure and then copy your logic back into the new file. It would not be suggested to try and change namespace/types from a copy because there could be errors.

                  You can copy/paste from the help guide lowestbar page for an example, that is the valid syntax.

                  Comment


                    #10
                    I resolved the issue of the indicator remaining on my chart after closing and reopening NT. I had too many channel types. I used an earlier script with fewer channels and tested it, and it remained on the chart. I then began adding more channels, one type at a time for both directions. I would close down, save changes, and it stayed on the chart until I reached the limit of too many channels.

                    Can a script be too large? It seems so, but perhaps there is a solution that I am unaware of. I am inexperienced but learning.

                    I will address the lowest bar of the past four bars later. Thank you.

                    Comment


                      #11
                      Hello trdninstyle,

                      There is not a specific limit to script size, it sounds like the script you were using may have had some kind of coding error potentially.

                      Comment


                        #12
                        "it sounds like the script you were using may have had some kind of coding error potentially."
                        I identified the issue, isolated it within a standalone script, and then rewrote it in my revised script. Everything is functioning correctly now.

                        I'm using an option to select _onlyPlotToday but I want to make it for two days rather than one day, or maybe 3 days:



                        private bool _onlyPlotToday = false;
                        SessionIterator _sessionIterator;

                        ***************

                        if (State == State.Historical)
                        {
                        //stores the sessions once bars are ready, but before OnBarUpdate is called
                        _sessionIterator = new SessionIterator(Bars);
                        }

                        *******

                        protected override void OnBarUpdate()
                        {

                        if(_onlyPlotToday)

                        {
                        _sessionIterator.GetNextSession(Time[0], true);
                        TimeSpan ts = DateTime.Now - _sessionIterator.ActualTradingDayExchange;
                        if(ts.Days == 0) //is today
                        PlotIndy();
                        }
                        else
                        {
                        PlotIndy();
                        }
                        }

                        private void PlotIndy()
                        {

                        *******

                        [NinjaScriptProperty]
                        [Display(Name = "OnlyPlotToday", Description = " Uses Less Data"+"\n"+"\nOn the next day once this indicator loads: hit reset (reset - Apply - OK) to reload the bars"+"\n"+"\n Go to Indicator > template > reset = (template >> save load reset)"+"\n -to keep from the continuation of painting of strong bars where it applies", Order = 1, GroupName = "FibDrawn_1R")]
                        public bool OnlyPlotToday
                        {
                        get { return _onlyPlotToday; }
                        set { _onlyPlotToday = value; }
                        }
                        Last edited by trdninstyle; 01-06-2025, 08:05 AM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        44 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        124 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        65 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        42 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        46 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X