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

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..

      Find it on Q&A — the home for technical questions and answers at Microsoft. New to Q&A? See our get started article below.

      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 cmtjoancolmenero, Yesterday, 03:58 PM
              12 responses
              42 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by FrazMann, Today, 11:21 AM
              0 responses
              5 views
              0 likes
              Last Post FrazMann  
              Started by geddyisodin, Yesterday, 05:20 AM
              8 responses
              52 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by DayTradingDEMON, Today, 09:28 AM
              4 responses
              27 views
              0 likes
              Last Post DayTradingDEMON  
              Started by George21, Today, 10:07 AM
              1 response
              22 views
              0 likes
              Last Post NinjaTrader_ChristopherJ  
              Working...
              X