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

indicators only showing last price

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

    #16
    Originally posted by 1reason View Post
    Thanks, That appears to be the problem. Where can I find out what is needed and not? I have been reading the manual and examples but having a hard time "getting my head around it". At least in terms of KNOWING what I need to put in to get what I want in to work?

    thanks again!!!
    I am still having trouble getting a zero if the statement is false. here is my code for the next one I have been trying to get to work (This is one of several attempts that have taken me through the whole day)

    I believe I have made the needed adjustments but it still shows the last price where it should show a zero. Thanks again for all your help


    #region Using declarations
    using System;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.ComponentModel;
    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>
    /// Enter the description of your new custom indicator here
    /// </summary>
    [Description("Enter the description of your new custom indicator here")]
    public class test2 : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // 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"));
    CalculateOnBarClose = false;
    Overlay = false;
    PriceTypeSupported = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    { if (CurrentBar < 1)
    Plot0.Set(0);
    return;
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    if (High[0] > ((High[1]+ .55) + (Open[0]*.01)))
    {
    Plot0.Set(Close[0]);
    }
    else
    Plot0.Set(0);
    }

    #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 Plot0
    {
    get { return Values[0]; }
    }

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

    Comment


      #17
      These 3 lines of code here will not work as you intend:
      Code:
      if (CurrentBar < 1)
           Plot0.Set(0);
           return;
      If you want an if statement to execute code that is more than one line you need to use brackets.
      Code:
      if (CurrentBar < 1)
      {
           Plot0.Set(0);
           return;
      }
      Josh P.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by Josh View Post
        These 3 lines of code here will not work as you intend:
        Code:
        if (CurrentBar < 1)
             Plot0.Set(0);
             return;
        If you want an if statement to execute code that is more than one line you need to use brackets.
        Code:
        if (CurrentBar < 1)
        {
             Plot0.Set(0);
             return;
        }
        Here is my code and it shows the LAST price not the high as it "should". Also please note that it "started" correctly but when I added more criteria it changed to showing the last price and not the high anymore. I have tried removing it and reloading with F5 several times. I also tried taking the code and putting it in a brand new indicator.

        Lastly I am getting false positives. for example the symbol DHR is giving me the last price instead of 0 but that doesnt meet the criteria below
        ?????

        thanks for your help

        protected override void OnBarUpdate()
        { if (CurrentBar < 1)
        {
        Plot0.Set(0);
        return;
        }
        // Use this method for calculating your indicator values. Assign a value to each
        // plot below by replacing 'Close[0]' with your own formula.
        if (
        High[0] > ((High[1]+ .55) + (High[1]*.01))
        && High[0] > ((High[2]+ .55))
        && High[0] > ((High[3]+ .55))
        && High[0] > ((High[4]+ .55))
        && High[0] > ((High[5]+ .55))
        && High[0] > ((High[6]+ .55))

        )
        {
        Plot0.Set(High[0]);
        }
        else
        Plot0.Set(0);
        }
        Last edited by 1reason; 12-28-2007, 11:39 AM.

        Comment


          #19
          I think I may have found a bug.

          This works(mostly but not completely) -->

          (High[0])>((High[1] + .55)+(Open[0]*.01)) && (2>1)
          //(High[0] > ((High[1]+ .55)+(Open[0]*.01))) && ( High[0] > ((High[2]+ .55)))
          //&& High[0] > ((High[3]+ .55))
          //&& High[0] > ((High[4]+ .55))
          //&& High[0] > ((High[5]+ .55))
          //&& High[0] > ((High[6]+ .55))

          )
          {
          Plot0.Set(99);
          }
          else
          {
          Plot0.Set(High[2]);

          This does NOT work AND shows the LAST price not the if then else output that should be generated if positive (should show the high) -- >

          protected override void OnBarUpdate()
          { if (CurrentBar < 1)
          {
          Plot0.Set(0);
          return;
          }
          // Use this method for calculating your indicator values. Assign a value to each
          // plot below by replacing 'Close[0]' with your own formula.
          if (//(1==1*1) && (2==2*1)
          (High[0])>((High[1] + .55)+(Open[0]*.01)) && (High[0] > ((High[1]+ .55)+(Open[0]*.01))) && ( High[0] > ((High[2]+ .55)))
          //&& High[0] > ((High[3]+ .55))
          //&& High[0] > ((High[4]+ .55))
          //&& High[0] > ((High[5]+ .55))
          //&& High[0] > ((High[6]+ .55))

          )
          {
          Plot0.Set(High[0]);
          }
          else
          {
          Plot0.Set(0);
          }
          }

          Comment


            #20
            I suspect there is no bug..

            You are accessing High[2] when your indicicator is processing the 2nd bar on the chart ---> Two bars ago does not exist and thus will throw an exception that you will see in the Log tab.

            Please take another look at Post #10.

            Thanks
            RayNinjaTrader Customer Service

            Comment


              #21
              Originally posted by NinjaTrader_Ray View Post
              I suspect there is no bug..

              You are accessing High[2] when your indicicator is processing the 2nd bar on the chart ---> Two bars ago does not exist and thus will throw an exception that you will see in the Log tab.

              Please take another look at Post #10.

              Thanks
              Ahhhh, Thanks. I raised the number of the bar for the check and now I know about the log. if I set the number to high will that be a problem? for example I want to check back 9 bars. I am guessing any number above 10 will work but if the number is higher than 10 will the math be off?

              thanks again for your help !!!

              Comment


                #22
                I can't say anything about your math but if you need to get a value 9 bars ago...then you need to make sure you don't check until you have 9 bars.
                RayNinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by NinjaTrader_Ray View Post
                  I can't say anything about your math but if you need to get a value 9 bars ago...then you need to make sure you don't check until you have 9 bars.
                  Thanks again for your help!! To clarify what I mean by "my math" is that if I need to look at a one bar ago and i program it to return if less than TWO bars ago will it be able to do the math on one bar ago?

                  Again, thanks for your help

                  Comment


                    #24
                    Unfortunately I don't understand what you mean.
                    RayNinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by 1reason View Post
                      if I need to look at a one bar ago and i program it to return if less than TWO bars ago will it be able to do the math on one bar ago?
                      The question would be better phrased as follows:

                      if I need to look at a one bar ago and i program it to return if less than TWO bars have been received will it be able to do the math on one bar ago?
                      At which point the answer might become obvious, but in case it isn't, the answer is:

                      Yes, you will be able to do math on the prior bar ("one bar ago") but only after at least two bars have been received.

                      For example,

                      Code:
                      if (CurrentBar<2)
                      {
                           Plot0.Set(0);
                           return;
                      }
                      
                      // The following won't be done until at least 2 bars have been received:
                      if (Close[0] > High[1])
                      {
                           Plot0.Set(High[0]);
                      }

                      Comment


                        #26
                        Originally posted by NinjaTrader_Ray View Post
                        ... will throw an exception that you will see in the Log tab.
                        I suspect that NinjaTrader support would see a lot less of this type of question if the NinjaTrader were changed to display the Control Panel's Log tab whenever an exception was encountered in a Strategy or Indicator.

                        It might be desirable to only do this when running in simulation mode or backtesting and/or to provide an option to suppress this behavior during live trading.

                        Comment


                          #27
                          Originally posted by KBJ View Post
                          The question would be better phrased as follows:

                          At which point the answer might become obvious, but in case it isn't, the answer is:

                          Yes, you will be able to do math on the prior bar ("one bar ago") but only after at least two bars have been received.

                          For example,

                          Code:
                          if (CurrentBar<2)
                          {
                               Plot0.Set(0);
                               return;
                          }
                          
                          // The following won't be done until at least 2 bars have been received:
                          if (Close[0] > High[1])
                          {
                               Plot0.Set(High[0]);
                          }
                          KBJ, Yes you are fully correct. I could have done a much better job of asking that question. Thanks for clarifying as well as answering it.

                          I still don't quite understand why waiting until there is enough bars to calculate the formula is not automatic but I am a newbe at both NT and C#??

                          This is my first step in the hopes of automating my trading. Having to learn C# is going to be a little bit of a challenge for me I feel. : o )

                          Comment


                            #28
                            Originally posted by 1reason View Post
                            I still don't quite understand why waiting until there is enough bars to calculate the formula is not automatic but I am a newbe at both NT and C#??
                            And that is exactly the reason why... because NinjaScript is an actual compiled programming language (not an interpreted pseudo-language like Trade Station's Easy Language), so you have to follow the rules of the language which is based on C#.
                            Last edited by KBJ; 12-29-2007, 04:26 PM. Reason: fixed typo

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Gerik, Today, 09:40 AM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by RookieTrader, Today, 09:37 AM
                            1 response
                            10 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by alifarahani, Today, 09:40 AM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by KennyK, 05-29-2017, 02:02 AM
                            3 responses
                            1,285 views
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by AttiM, 02-14-2024, 05:20 PM
                            11 responses
                            186 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Working...
                            X