Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SR Level Indicator

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

    SR Level Indicator

    Hi,

    I'm having trouble setting up a basic indicator that can show me support and resistance levels that occur at a specific time.
    What seems to happen is that it only actually recognizes when ToTime(Time[0]) == 130000 about 25%, and when ToTime(Time[0]) == 063000 about 10% of the time.
    The other issue is that it seems to combine priceLevel1 and priceLevel2 into the same plot rather two separate ones. The other plot is just at 0.

    How do I set this up so it will carry the selected price into the next day, and how do I get it to show both plots and not just one.

    I'm not trying to set up the Prior Day OCHL Indicator, I'm just using these times as examples.

    Bellow is a snippet of my code.

    Thank you so much for your time and help!

    public class SRLevels : Indicator
    {

    private double priceLevel1 = 0;
    private double priceLevel2 = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    AddPlot(Brushes.Red, "Level1");
    AddPlot(Brushes.Blue, "Level2");
    }
    }

    protected override void OnBarUpdate()
    {

    if (ToTime(Time[0]) == 130000)
    {
    priceLevel1 = Close[0];
    }
    if (ToTime(Time[0]) == 063000)
    {
    priceLevel2 = Open[0];
    }

    Level1[0] = priceLevel1;
    Level2[0] = priceLevel2;

    }

    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Level1
    {
    get { return Values[0]; }
    }

    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Level2
    {
    get { return Values[1]; }
    }
    }




    #2
    Hello Kreyanhagen,

    Thank you for your post.

    What is the interval of the primary series of the chart? You're only assigning the plot values at specific bar timestamps, so if you're using a non-time-based bar it's very possible there might not be a bar with that time stamp and the value might not get assigned.

    It would be expected that both plots would plot as 0 until you reach one of the 2 times at which you assign price levels. Since sessions begin the evening of the day prior, if you've got, say, 5 days to load on a chart and apply the strategy, we'd expect to see that until the indicator reaches the first instance of a 6:30 am bar on the chart.

    I've attached an example of what I see after it's reached a point at which the plots are being assigned values other than 0. Are you not seeing the same?

    Thanks in advance; I look forward to assisting you further.


    Attached Files

    Comment


      #3
      Hi Kate,

      I appreciate you reaching out and helping me with this issue.
      I am using a 2000 tick chart on /ES primarily. Is there a way to set something like this up using a none time based chart?

      Thanks again!

      Comment


        #4
        Hello Kreyenhagen,

        Thank you for your reply.

        What I'd suggest is adding a secondary 1 minute data series to the indicator and using that to update the plot value:

        Code:
         public class SRLevels : Indicator
        {
        private double priceLevel1 = 0;
        private double priceLevel2 = 0;
        
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Indicator here.";
        Name = "SRLevels";
        Calculate = Calculate.OnBarClose;
        IsOverlay = false;
        DisplayInDataBox = true;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = true;
        PaintPriceMarkers = true;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;
        
        AddPlot(Brushes.Red, "Level1");
        AddPlot(Brushes.Blue, "Level2");
        }
        else if (State == State.Configure)
        {
        AddDataSeries(BarsPeriodType.Minute, 1);
        }
        }
        
        protected override void OnBarUpdate()
        {
        if(CurrentBars[0] < 1) return;
        
        if(BarsInProgress == 1)
        {
        if (ToTime(Time[0]) == 130000)
        {
        priceLevel1 = Close[0];
        }
        if (ToTime(Time[0]) == 063000)
        {
        priceLevel2 = Open[0];
        }
        // assign plot here so we see the change immediately
        Level1[0] = priceLevel1;
        Level2[0] = priceLevel2;
        }
        else
        {
        // also assign plot on primary series so it's continuous
        Level1[0] = priceLevel1;
        Level2[0] = priceLevel2;
        }
        }
        
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> Level1
        {
        get { return Values[0]; }
        }
        
        [Browsable(false)]
        [XmlIgnore()]
        public Series<double> Level2
        {
        get { return Values[1]; }
        }
        }
        I suspect that approach will work better on a tick based primary series that may not have timestamps at exactly those times for you.

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

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