Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Overnight gap Indicator

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

    Overnight gap Indicator

    Hi There,
    Need some help as I am a bit puzzled why this is not working. I am trying to create an indicator that tells me how big was the gap (Open Today minus Close yesterday). It seems to let me calculate Open today - close today but not open today vs close yesterday. I tried following the sample script for SampleCustomDataSeries. I am sure its something dumb but have not been able to fix it. My current code is below.
    Appreciate your help!


    /// <summary>
    /// Reference sample demonstrating how to use DataSeries objects to store self calculations.
    /// </summary>
    [Description("Reference sample demonstrating how to use DataSeries objects to store self calculations.")]
    public class TestONRange : Indicator
    {
    #region Variables
    private int period = 5;
    private int period2 = 10;

    // Defines the DataSeries object
    private DataSeries myDataSeries; // Define a DataSeries variable

    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    // Adds a plot to our NinjaScript Indicator
    Add(new Plot(Color.Red, PlotStyle.Line, "Average Range"));

    // Create a new DataSeries object and assign it to the variable myDataSeries declared in the ‘Variables’ region above

    myDataSeries = new DataSeries(this); // "this" refers to the indicator, or strategy
    // itself. This syncs the DataSeries object
    // to historical data bars

    CalculateOnBarClose = true;
    Overlay = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    // Calculate the range of the overnight gap and set the value as an average of the last x days (note on the error: if I write the below as myDataSeries.Set(Close[0] - Open[0]); i.e calculate the //intraday range, then the indicator shows up in my charts fine.
    //however if I set it to take Close 1 bar ago i.e yesterdays close minus todays open it does not work...…

    myDataSeries.Set(Close[1] - Open[0]);

    AvgR.Set(SMA(myDataSeries, Period)[0]);

    }


    #2
    Hello alfonso,

    If you are trying to get the prior day close, I would suggest trying the PriorDayOHLC indicator to gather this value. Close[1] may or may not represent the yesterdays close depending on the series being used and when this is called.



    This would not require adding a secondary series or doing other series related tasks, mainly just calling the indicator to retrieve the value.

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    601 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    347 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    559 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    558 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X