• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate and Color Region

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

    Calculate and Color Region

    Dear Members,

    I'm trying to add some functions this "GetHighLowByTimeRange" Indicator.
    Fist I need to calculate two drawn lines region,

    Then I need to add condition like that;
    - if region more then "15" color that region "red"
    - if region less then "15" color that region "green"

    Also I need change that "15" in indicator settings tab and I need to get that value in Plot value for use Strategy Builder.

    Thanks for your help.

    Code Part
    -------------------
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    ///
    /// </summary>
    [Description("")]
    public class GetHighLowByTimeRange : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int startHour = 9; // Default setting for StartHour
    private int startMinute = 30; // Default setting for StartMinute
    private int endHour = 10; // Default setting for EndHour
    private int endMinute = 15; // Default setting for EndMinute
    // User defined variables (add any user defined variables below)
    #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()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "HighestHigh"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "LowestLow"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    }

    private DateTime startDateTime;
    private DateTime endDateTime;

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Check to make sure the end time is not earlier than the start time
    if (EndHour < StartHour)
    return;

    //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
    if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
    return;

    // If the stored date time date is not the same date as the bar time date, create a new DateTime object
    if (startDateTime.Date != Time[0].Date)
    {
    startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
    endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);
    }

    // Calculate the number of bars ago for the start and end bars of the specified time range
    int startBarsAgo = GetBar(startDateTime);
    int endBarsAgo = GetBar(endDateTime);

    /* Now that we have the start and end bars ago values for the specified time range we can calculate the highest high for this range

    Note: We add 1 to the period range for MAX and MIN to compensate for the difference between "period" logic and "bars ago" logic.
    "Period" logic means exactly how many bars you want to check including the current bar.
    "Bars ago" logic means how many bars we are going to go backwards. The current bar is not counted because on that bar we aren't going back any bars so it would be "bars ago = 0" */
    double highestHigh = MAX(High, startBarsAgo - endBarsAgo + 1)[endBarsAgo];

    // Now that we have the start and end bars ago values for the specified time range we can calculate the lowest low for this range
    double lowestLow = MIN(Low, startBarsAgo - endBarsAgo + 1)[endBarsAgo];

    // Set the plot values
    HighestHigh.Set(highestHigh);
    LowestLow.Set(lowestLow);
    }

    #region Properties
    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries HighestHigh
    {
    get { return Values[0]; }
    }

    [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries LowestLow
    {
    get { return Values[1]; }
    }

    [Description("")]
    [Category("Parameters")]
    public int StartHour
    {
    get { return startHour; }
    set { startHour = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int StartMinute
    {
    get { return startMinute; }
    set { startMinute = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int EndHour
    {
    get { return endHour; }
    set { endHour = Math.Max(1, value); }
    }

    [Description("")]
    [Category("Parameters")]
    public int EndMinute
    {
    get { return endMinute; }
    set { endMinute = Math.Max(1, value); }
    }
    #endregion
    }
    }

    #region NinjaScript generated code. Neither change nor remove.
    ----------------
    Attached Files
    Last edited by nedserbest; 05-26-2015, 08:05 PM.

    #2
    Hello,

    Thank you for the post.

    I would like to ask, have you attempted this as of yet? I do not see any code related to the region you are creating is the reason I ask.

    If you have not, we do have an item in the Indicator sharing section that shows how to use a region and color it according to a condition. Here is the link: http://www.ninjatrader.com/support/f...d=4&linkid=491

    Also there is help in the help guide for regions here: http://www.ninjatrader.com/support/h...ightsub=region


    For the User Input, you have posted a few in this script already that you can copy to create your own, here is one for example:

    Code:
    private int startHour = 0;
    
    [Description("")]
    [Category("Parameters")]
    public int StartHour
    {
    get { return startHour; }
    set { startHour = Math.Max(1, value); }
    }
    Anytime you need a user to have input in the platform, you would need to create a property like the above example. This would show up in the grid category you specify as the name of the public property so in this case StartHour.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by memonolog, Today, 07:07 AM
    0 responses
    2 views
    0 likes
    Last Post memonolog  
    Started by juanram, Today, 06:01 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by dastaan, Today, 06:29 AM
    0 responses
    6 views
    0 likes
    Last Post dastaan
    by dastaan
     
    Started by random9570, Yesterday, 09:01 PM
    2 responses
    19 views
    0 likes
    Last Post Emma1
    by Emma1
     
    Started by SDaCosta30, Today, 04:19 AM
    0 responses
    10 views
    0 likes
    Last Post SDaCosta30  
    Working...
    X