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

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by sidlercom80, 10-28-2023, 08:49 AM
    170 responses
    2,273 views
    0 likes
    Last Post sidlercom80  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    17 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post adeelshahzad  
    Started by CortexZenUSA, Today, 12:53 AM
    0 responses
    3 views
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Working...
    X