Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limiting results during first bars of day

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

    Limiting results during first bars of day

    The first bars of the day are always out of range. I'm looking for a simple way to mute these results. I want to write something like:

    if(any of the first 5 bars after my data feed starts are >= 100)
    { myPlot = 100}

    Could you tell me how to write something like that?

    Thank you.

    #2
    Hello,

    Thank you for the post.

    Assuming you are referring to the Close price as the "Bars" here, you could do something like the following:

    Code:
    if(Close[0] > 100)
    { 
        MyPlot[0] = 100;
    }
    This would always make this modification, to only do this for the first 5 bars of the session you could use BarsSinceNewTradingDay

    Code:
    if (Bars.BarsSinceNewTradingDay <= 5)
    {
        if(Close[0] > 100)
        {
            MyPlot[0] = 100;
        }
    }


    I look forward to being of further assistance.

    Comment


      #3
      Actually it would be:

      if(MyPlot[0] > 100)
      {
      MyPlot[0] = 100;
      }
      And I don't believe BarsSinceNewTradingDay will work. My custom indicator goes back a few bars and gives an average. A few bars have to go by before it's usable. If I start my data feed, say, 30 minutes before the open, the indicator value will spike, which makes my panel unreadable until time kicks it off the screen.

      Does this clear things up?

      Thanks.

      Comment


        #4
        Hello imalil,

        Thanks for your reply.

        Typically a chart will be loaded with multiple days of data so when adding the indicator it would have access to that historical data unless your indicator is real time only. Can you advise if your indicator is used on real time only (does not function on historical data).

        Can you post a screenshot of your indicator that shows the issue you are trying to resolve?

        Comment


          #5
          The indicator uses OnMarketData--all data disappears when I refresh.

          I've attached a screen shot. On a separate panel I've plotted a line that goes above and below the zero line. Again, the only issue I'm having is during the first few bars after I start the data feed. The line spikes to over 50,000 when the typical daily range is around 4000 for a particular time frame. For a smaller time frame the range is lower. So after this 50,000 bar all the normal data that follows becomes unreadable until the 50,000 bar leaves the screen.

          Is there any way to "disable" the first few bars that load after the data feed starts? Or something to that effect?

          Thank you.
          Attached Files

          Comment


            #6
            Hello imalil,

            Thanks for your reply.

            I understand your indicator depends on real-time data. In that case, you can check for state.real time and using a bar counter set your plot to a specific value for the first few bars. For example in OnBarUpdate():

            if (State == State.RealTime && numberOfBars < 5)
            {
            MyPlot[0] = 100;
            numberOfBars ++; // increment bar counter
            }

            You would need to declare numberOfBars as an int and set its initial value to 0. I've used 5 bars as the example you can set to what you wish.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            101 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X