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

Highest / Lowest Price within a certain Range; MIN(), MAX() Issue

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

    #16
    Hello JMont1,

    When calling Draw.HorizontalLine(), you can specify a the same drawing tag to update the drawing object to a new location so another drawing object is not created. For example:

    Code:
    bool firstbar = true;
    protected override void OnBarUpdate()
    {
        if(State == State.Historical)
            return;
    
        if (firstbar)
        {
            Draw.HorizontalLine(this, "MyTag", Close[0], Brushes.Red);
            firstbar = false;
        }
        else
            Draw.HorizontalLine(this, "MyTag", High[0], Brushes.Green);
    }
    Publicly available information on using drawing tools and Draw.HorizontalLine in particular can be found below.

    Drawing (Important notes at the bottom of the page - https://ninjatrader.com/support/help...us/drawing.htm

    Draw.HoriozontalLine() - https://ninjatrader.com/support/help...zontalline.htm

    Let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #17
      Hi,

      I am using

      double highPrice = 0;
      double lowPrice = double.MaxValue;

      int lastBar = ChartBars.ToIndex;
      int firstBar = firstBarIdxToPaint; // this is the first bar of the session.

      for (int idx = firstBar; idx <= lastBar && idx >= firstBar; idx++)
      {
      highPrice = Math.Max(highPrice, Bars.GetHigh(idx));
      lowPrice = Math.Min(lowPrice, Bars.GetLow(idx));
      }


      but when I am printing the highPrice and lowPrice, it is printing some wrong prices. Any idea why that might happen? I am just trying to print the highest and lowest price for the session.

      Comment


        #18
        Hello asmmbillah,

        ChartBars.ToIndex is the index of the last bar that is visible on the chart. As it is relative to what is visible, I would not suggest using it to see what is the highest/lowest price of the session. I would instead suggest using it in OnBarUpdate which would be based on incoming data.

        You can save the CurrentBar index to a private variable on Bars.IsFirstBarOfSession, and then loop from that saved index to CurrentBar. Within the loop, you can use Math.Min and Math.Max like you are to track the highest high and lowest low.

        We look forward to assisting.
        JimNinjaTrader Customer Service

        Comment


          #19
          Using 1 minute time series need the first hour of session high/low... ideas anyone?

          Comment


            #20
            Hello elliot5,

            I would suggest adding a 60 minute data series, and then in BarsInProgress 1 (or the BarsInProgress associated with your 60 minute data series) to check Bars.IsFirstBarOfSession. You can then save the High[0] and Low[0] to variables and use them throughout your script.

            Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by trilliantrader, 04-18-2024, 08:16 AM
            4 responses
            16 views
            0 likes
            Last Post trilliantrader  
            Started by mgco4you, Today, 09:46 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by wzgy0920, Today, 09:53 PM
            0 responses
            6 views
            0 likes
            Last Post wzgy0920  
            Started by Rapine Heihei, Today, 08:19 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by Rapine Heihei, Today, 08:25 PM
            0 responses
            9 views
            0 likes
            Last Post Rapine Heihei  
            Working...
            X