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

Need indicator to return true/false

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

    Need indicator to return true/false

    Hi I used some info from a previous post I found to write this indicator. The indicator will compare today's close to yesterday's and the day before that ,day before that etc..and returns a value of true or false if the conditions are met.
    I want to use this true/false value as a filter inside "market analyzer". My question. How do I use the value of the Boolean variable outside of the indicator code. When I apply this indicator to a chart it doesn't show any values.
    I guess if I could somehow plot a 1 or 0 value I could filter on that right? I'm not very skilled at programming so help would be much appreciated.
    Here is the code..

    /// </summary>
    private bool overextend = false;
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    Overlay = false;
    }
    protected override void OnBarUpdate()
    {
    Plot0.Set(Close[0]);
    if (CurrentBar < 1)
    return;

    if (Close[0]>(1.20*Close[1]) || Close[0]>(1.20*Close[2]) || Close[0]>(1.30*Close[3]) || Close[0]>(1.30*Close[4]) || Close[0]>(1.30*Close[5]) || Close[0]>(1.30*Close[6]) || Close[0]>(1.30*Close[7]) || Close[0]>(1.30*Close[8]) || Close[0]>(1.30*Close[9]) || Close[0]>(1.50*Close[10]) || Close[0]>(1.50*Close[11]) || Close[0]>(1.50*Close[12]) || Close[0]>(1.50*Close[13]) || Close[0]>(1.50*Close[14]) || Close[0]>(1.50*Close[15]) || Close[0]>(1.50*Close[16]) || Close[0]>(1.50*Close[17]) || Close[0]>(1.50*Close[18]) || Close[0]>(1.50*Close[19]) || Close[0]>(1.50*Close[20])) overextend = true;
    else
    overextend = false;
    }
    public bool Overextend
    {
    get { Update(); return overextend; }
    }

    #2
    Hello SmokyTradeR,

    To use an indicator in a MarketAnalyzer, the indicator would need a plot, which is a data series (which is a collection of double values).

    You would need to plot a 0 for false and 1 for true for this to work with the Market Analyzer cell filters and alert filters.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea.

      I'm doing something wrong here and I'm sure it's basic. My indicator will not plot the value. Can you have a look and see what i'm doing wrong please.

      [Description("Finds stocks with extreme upward moves")]
      public class OverExtended : Indicator
      {
      #region Variables
      private double OvrPlot = 0.0;
      private bool overextend = false;
      // Wizard generated variables
      // 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.Orange), PlotStyle.Line, "Plot0"));
      Overlay = false;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Use this method for calculating your indicator values. Assign a value to each
      // plot below by replacing 'Close[0]' with your own formula.

      double OvrPlot = 0;

      if (Close[0]>(1.20*Close[1]) || Close[0]>(1.20*Close[2]) || Close[0]>(1.30*Close[3]) || Close[0]>(1.30*Close[4]) || Close[0]>(1.30*Close[5]) || Close[0]>(1.30*Close[6]) || Close[0]>(1.30*Close[7]) || Close[0]>(1.30*Close[8]) || Close[0]>(1.30*Close[9]) || Close[0]>(1.50*Close[10]) || Close[0]>(1.50*Close[11]) || Close[0]>(1.50*Close[12]) || Close[0]>(1.50*Close[13]) || Close[0]>(1.50*Close[14]) || Close[0]>(1.50*Close[15]) || Close[0]>(1.50*Close[16]) || Close[0]>(1.50*Close[17]) || Close[0]>(1.50*Close[18]) || Close[0]>(1.50*Close[19]) || Close[0]>(1.50*Close[20])) overextend = true;
      else
      overextend = false;

      if (overextend == true) OvrPlot = 1;
      Plot0.Set(OvrPlot);
      }

      Comment


        #4
        Originally posted by SmokyTradeR View Post
        Thanks Chelsea.

        I'm doing something wrong here and I'm sure it's basic. My indicator will not plot the value. Can you have a look and see what i'm doing wrong please.

        [Description("Finds stocks with extreme upward moves")]
        public class OverExtended : Indicator
        {
        #region Variables
        private double OvrPlot = 0.0;
        private bool overextend = false;
        // Wizard generated variables
        // 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.Orange), PlotStyle.Line, "Plot0"));
        Overlay = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        // Use this method for calculating your indicator values. Assign a value to each
        // plot below by replacing 'Close[0]' with your own formula.

        double OvrPlot = 0;

        if (Close[0]>(1.20*Close[1]) || Close[0]>(1.20*Close[2]) || Close[0]>(1.30*Close[3]) || Close[0]>(1.30*Close[4]) || Close[0]>(1.30*Close[5]) || Close[0]>(1.30*Close[6]) || Close[0]>(1.30*Close[7]) || Close[0]>(1.30*Close[8]) || Close[0]>(1.30*Close[9]) || Close[0]>(1.50*Close[10]) || Close[0]>(1.50*Close[11]) || Close[0]>(1.50*Close[12]) || Close[0]>(1.50*Close[13]) || Close[0]>(1.50*Close[14]) || Close[0]>(1.50*Close[15]) || Close[0]>(1.50*Close[16]) || Close[0]>(1.50*Close[17]) || Close[0]>(1.50*Close[18]) || Close[0]>(1.50*Close[19]) || Close[0]>(1.50*Close[20])) overextend = true;
        else
        overextend = false;

        if (overextend == true) OvrPlot = 1;
        Plot0.Set(OvrPlot);
        }
        You are looking 20 bars back. Ensure that you have at least that many bars on the chart before your processing code runs.

        The simplest way is to escape the block if you do not have enough bars. In your particular case:
        Code:
        if (CurrentBar < 20) return;
        at the top of your OnBarUpdate() method, before any code is run, should be able to help you.

        Next time that you meet an unexpected processing snafu, look in your log for any errors, and search for the error text in the forum.

        Comment


          #5
          Hi SmokyTradeR,

          What is the incorrect behavior you are experiencing?

          Are you getting an error message in the Log tab of the Control Center?

          Is the plot not being set at all or being set incorrectly?

          As koganam mentioned, have you tried setting BarsRequired to 0 in Initialize()?
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          12 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          11 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          7 views
          0 likes
          Last Post nandhumca  
          Started by The_Sec, Today, 03:37 PM
          0 responses
          3 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Working...
          X