Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why Can't I Use the '/' Operand?!

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

    Why Can't I Use the '/' Operand?!

    I'm sure there is a really simple solution to this, but I have tried a number of things and simply cannot figure out what's wrong.

    I have built some code and every element of it works fine--it displays on it's own plot and compiles correctly, but when I try to add the last manipulation--dividing one double element by another--even though the indicator still complies completely, nothing get's plotted!

    I have experimented with where I put the '/' operand, and even done some experiments just to see if ANYTHING can be divided, and it turns out it cannot so what am I missing that isn't allowing me to utilize division in my indicator calculations correctly?

    Thanks very much in advance!

    #2
    Hi traderman89,

    Welcome to the NinjaTrader forums! Division should work in indicators, unless you're dividing by zero. Do you get any error messages in log tab of control center? What two values are you trying to divide? Please feel free to post a brief snippet of your code here so we'll have a better idea what may be wrong.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by traderman89 View Post
      I'm sure there is a really simple solution to this, but I have tried a number of things and simply cannot figure out what's wrong.

      I have built some code and every element of it works fine--it displays on it's own plot and compiles correctly, but when I try to add the last manipulation--dividing one double element by another--even though the indicator still complies completely, nothing get's plotted!

      I have experimented with where I put the '/' operand, and even done some experiments just to see if ANYTHING can be divided, and it turns out it cannot so what am I missing that isn't allowing me to utilize division in my indicator calculations correctly?

      Thanks very much in advance!
      As nt ryanm suggest, post some code.

      I did find this via google on how to use / in c# and it MAY apply to your situation..

      http://social.msdn.microsoft.com/for...1-10d39f390024

      Comment


        #4
        Hey guys,

        Really appreciate the input! I checked that link seldge--thank you! I don't think that is my problem, at least as far as I can tell, because everything I have I set to double (I am new to this though so...yeah).

        RyanM--I checked the log files and they say:
        'Error on setting indicator plot for indicator, value outside of valid range'. Not sure what to do with it. SO, here is the code:
        protected override void OnBarUpdate()
        {

        double body = 0;

        if (Close[0] > Open[0])
        {
        body = 0;
        }
        else if (Close[0] == Open[0])
        {
        body = 1;
        }
        else
        {
        body = 2;
        }

        double tailsize = 0;

        if (body == 0)
        {
        tailsize = Math.Abs((High[0] - Close[0]) - (Open[0] - Low[0]));
        }
        else if (body == 1)
        {
        tailsize = Math.Abs((High[0] - Close[0]) - (Open[0] - Low[0]));
        }
        else
        {
        tailsize = Math.Abs((High[0] - Open[0]) - (Close[0] - Low[0]));
        }

        if (tailsize == 0)
        {
        tailsize = 0.10;
        }

        double realbody = Math.Abs(Open[0] - Close[0]);

        RatioSeries.Set(tailsize/realbody);

        Ratio.Set(RatioSeries[0]);
        BigBar.Set(BigBarThreshhold);
        Reversal.Set(ReversalThreshhold);

        If I switch the variables 'tailsize' and 'realbody', everything works just fun, but it's when I try to do it the way it's posted, it gives me that error in the log.

        Ok, thanks again.
        Traderman89

        Comment


          #5
          Originally posted by traderman89 View Post
          I'm sure there is a really simple solution to this, but I have tried a number of things and simply cannot figure out what's wrong.

          I have built some code and every element of it works fine--it displays on it's own plot and compiles correctly, but when I try to add the last manipulation--dividing one double element by another--even though the indicator still complies completely, nothing get's plotted!

          I have experimented with where I put the '/' operand, and even done some experiments just to see if ANYTHING can be divided, and it turns out it cannot so what am I missing that isn't allowing me to utilize division in my indicator calculations correctly?

          Thanks very much in advance!
          You must not have accounted for division by zero, which will cause an exception.

          Comment


            #6
            Originally posted by traderman89 View Post
            Hey guys,

            Really appreciate the input! I checked that link seldge--thank you! I don't think that is my problem, at least as far as I can tell, because everything I have I set to double (I am new to this though so...yeah).

            RyanM--I checked the log files and they say:
            'Error on setting indicator plot for indicator, value outside of valid range'. Not sure what to do with it. SO, here is the code:
            protected override void OnBarUpdate()
            {

            double body = 0;

            if (Close[0] > Open[0])
            {
            body = 0;
            }
            else if (Close[0] == Open[0])
            {
            body = 1;
            }
            else
            {
            body = 2;
            }

            double tailsize = 0;

            if (body == 0)
            {
            tailsize = Math.Abs((High[0] - Close[0]) - (Open[0] - Low[0]));
            }
            else if (body == 1)
            {
            tailsize = Math.Abs((High[0] - Close[0]) - (Open[0] - Low[0]));
            }
            else
            {
            tailsize = Math.Abs((High[0] - Open[0]) - (Close[0] - Low[0]));
            }

            if (tailsize == 0)
            {
            tailsize = 0.10;
            }

            double realbody = Math.Abs(Open[0] - Close[0]);

            RatioSeries.Set(tailsize/realbody);

            Ratio.Set(RatioSeries[0]);
            BigBar.Set(BigBarThreshhold);
            Reversal.Set(ReversalThreshhold);

            If I switch the variables 'tailsize' and 'realbody', everything works just fun, but it's when I try to do it the way it's posted, it gives me that error in the log.

            Ok, thanks again.
            Traderman89
            Code:
            double realbody = Math.Abs(Open[0] - Close[0]);
            means your code will bomb on every doji, as by definition, for a doji, Close = Open, so your value is zero. Ergo, you would be dividing by zero, and getting an exception.

            Comment


              #7
              Koganam--you da man!

              everything works now, thanks for catching that, I knew it was something simple.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jeremytang, 07-14-2018, 06:45 PM
              21 responses
              439 views
              0 likes
              Last Post mav8rick  
              Started by LeonK, Yesterday, 09:26 PM
              1 response
              8 views
              0 likes
              Last Post bltdavid  
              Started by NicholasJoannette, Yesterday, 03:01 PM
              2 responses
              11 views
              0 likes
              Last Post NicholasJoannette  
              Started by rach1994, Yesterday, 12:20 PM
              1 response
              35 views
              0 likes
              Last Post bltdavid  
              Started by litamm89, Yesterday, 11:00 AM
              5 responses
              22 views
              1 like
              Last Post rafael_delima86  
              Working...
              X