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

Trying to get a Percentage

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

    Trying to get a Percentage

    Hi, im trying to get a percentage between 2 counts but isn't working, the indicator just disappears at F5

    so, this is what im doing:

    if ( XXX > XXX)
    {
    signalOne++;
    }

    if (XXXX XXX)
    {
    signalTwo++;
    }

    int signalSum=( signalOne + signalTwo);

    int percentage= ( (signalSum* 100 ) / signalTwo);

    DrawTextFixed( XXXXXXX, percentage.ToString() , XXXXXXX)

    the sum works fine, the percentage doesn't, what im doing wrong?

    ill appreciate any help
    Last edited by kabott; 09-08-2014, 08:41 PM.

    #2
    Originally posted by kabott View Post
    Hi, im trying to get a percentage between 2 counts but isn't working, the indicator just disappears at F5

    so, this is what im doing:

    if ( XXX > XXX)
    {
    signalOne++;
    }

    if (XXXX XXX)
    {
    signalTwo++;
    }

    int signalSum=( signalOne + signalTwo);

    int percentage= ( (signalSum* 100 ) / signalTwo);

    DrawTextFixed( XXXXXXX, percentage.ToString() , XXXXXXX)

    the sum works fine, the percentage doesn't, what im doing wrong?

    ill appreciate any help
    • What is the error in your log?
    • You have not taken care of a possible division by zero.

    Comment


      #3
      Hi koganam, yes thats what the Log says:
      "Attempted to divide by zero."

      but how do i solve it?
      Last edited by kabott; 09-08-2014, 10:12 PM.

      Comment


        #4
        Originally posted by kabott View Post
        Hi koganam, yes thats what the Log says:
        "Attempted to divide by zero."

        but how do i solve it?
        You have to decide what you want to do if signalTwo is zero, then code that action. What do you want to do if signalTwo is zero?
        Last edited by koganam; 09-09-2014, 09:15 AM.

        Comment


          #5
          return!! XD thanks man! im so dumb!!

          Comment


            #6
            Originally posted by kabott View Post
            return!! XD thanks man! im so dumb!!
            Not so dumb. You will not believe how many times that I still make the mistake.
            Code:
            double percentage= 0.0;
            if (signalTwo != 0) percentage= ( (signalSum* 100 ) / signalTwo);
            else return;
            You probably do not want to evaluate percentage as an integer. Which may also mean that you have to cast your counts to doubles before doing the division.

            That code is based entirely on what you said that you want to do. As I do not know your bigger purpose, I cannot comment about the viability of your approach.
            Last edited by koganam; 09-09-2014, 10:11 AM.

            Comment


              #7
              Hi Kabott

              Firstly, always listen to Koganam - his expertise is out of the top drawer!

              Secondly, and please correct me if I'm wrong, I think you might have missed something at the very beginning.

              In your first post, you put:

              Code:
              int signalSum=( signalOne + signalTwo);
              
              int percentage= ( (signalSum* 100 ) / signalTwo);
              Ignoring the multiplier (= 100), your percentage equation is effectively:

              (signalOne + signalTwo)
              -----------------------------------
              signalTwo

              As these three numbers are positive, this will give you a fraction greater than 1 - or a percentage greater than 100.

              I think you should have made this your equation:

              signalTwo
              ---------------------------------
              (signalOne + signalTwo)

              so your percentage variable would be:

              Code:
              if(signalOne + signalTwo != 0)[B]
              double [/B]percentage= ( (signalTwo* 100 ) / signalSum)
              Hope this helps.

              Comment


                #8
                That code is based entirely on what you said that you want to do. As I do not know your bigger purpose, I cannot comment about the viability of your approach
                Hi koganam, yes, but i realize i it was wrong when i wrote the post, i guess i was tired, it was late in the night.. but anyways your reply helped me fix the problem!

                the intention for this percentage was to create some sort of Market Analyzer that would help me decide which markets are best for Renko trading, meaninge less choppy, you can see in the image below two examples, on the EURAUD you have the double amount of bars than the EURCAD and yet is more advisable to trade



                basically what im doing is multiplying the amount of bars by 100, and then diving it by the amount of fractals or "trend change", the result would be the "Smoothness factor"

                Then to calculate the size of movement, "swing range" i take Highest Highs from the last 200 periods and subtract the Lowest Lows of the same periods, the same with 100 and 50 periods, add em all up, divide by 3 and multiply by ATR, this should gave me an idea of the total movement the currency did during this period.

                finally multiply the swing range by the smoothness factor, i divide the result by 10 to get a small number i can easily comprehend


                I wanted to create a tool that would help me decide each day what currency to trade, the highest the number the better conditions, i know past performance isn't indicative of future performance, but it helps, some currencies are by nature more choppy than others.

                I did the same thing with a supertrend and daily charts, to see which markets where more predictable than others, by "predictable" i mean, which ones respect the super trend levels more times before braking it and changing trend..it helps.

                any ways, "maths force isn't strong in me" im a graphic designer, don't even know C# well, just copy & paste work, im learning in the process, here's the indi, i intended to create a Ninja Market Analyzer Chart but dunno why doesn't work there. numbers are not the same shown in the bar chart windows.

                Last edited by kabott; 09-13-2014, 04:57 PM.

                Comment


                  #9
                  Hi arbuthnot, yes you r right, it was late at night and i wasn't thinking clearly, i just wanted to post the question and head for bed lol, anyways this is how the equation ended up:

                  double t3totalCount= (risingSig + fallingSig); // Fractal count


                  if ( t3totalCount==0 ) return;
                  {
                  t3AverageSmoothness=( ((CurrentBar * 100) / t3totalCount) /100 ); // the last division by 100 is just to get a smaller number.
                  }

                  feel free to download the indicator & play with it, my math skills r very limited, im an "arts" guy .. lol

                  Comment


                    #10
                    Thanks, Kabott!

                    I'm glad to see you've got that sorted out.

                    It's getting late here (I'm on the other side of the Pond if you're in the US) so I won't have a detailed look tonight. If you knew the mistakes I have made by working on Ninja into the early hours...

                    In fact, Ninja now won't let me work on code if it's later than 10pm... lol...

                    It's good to see an 'arts' person playing with math and code. Keep up the good work ... you've got some neat ideas.

                    Comment


                      #11
                      In fact, Ninja now won't let me work on code if it's later than 10pm... lol...
                      .. LOL

                      i guess is the only way to learn

                      It's good to see an 'arts' person playing with math and code. Keep up the good work ... you've got some neat ideas
                      Thanks arbuthnot, my creative side has always been my strongest side, but over these fields i feel like the old proverbial Penguin in the Desert, lol

                      Comment


                        #12
                        Originally posted by kabott View Post
                        Hi koganam, yes, but i realize i it was wrong when i wrote the post, i guess i was tired, it was late in the night.. but anyways your reply helped me fix the problem!

                        the intention for this percentage was to create some sort of Market Analizer that would help me decide which markets are best for Renko trading, meaninge less chopy, you can see in the image below two examples, on the EURAUD you have the double amount of bars than the EURCAD and yet is more advisable to trade

                        [ATTACH]29994[/ATTACH]

                        basically what im doing is multiplying the amount of bars by 100, and then diving it by the amount of fractals or "trend change", the result would be the "Smoothness factor"

                        Then to calculate the size of movement, "swing range" i take Highest Highs from the last 200 periods and subtract the Lowest Lows of the same periods, the same with 100 and 50 periods, add em all up, divide by 3 and multiply by ATR, this should gave me an idea of the total movement the currency did during this period.

                        finally multiply the swing range by the smoothness factor, i divide the result by 10 to get a small number i can easily comprehend


                        I wanted to create a tool that would help me decide each day what currency to trade, the highest the number the better conditions, i know past performance isn't indicative of future performance, but it helps, some currencies are by nature more choppy than others.

                        I did the same thing with a supertrend and daily charts, to see which markets where more predictable than others, by "predictable" i mean, which ones respect the super trend levels more times before braking it and changing trend..it helps.

                        any ways, "maths force isnt strong in me" im a graphic designer, dont even know C# well, just copy & paste work, im learning in the process, here's the indi, i intended to create a Ninja Market Sentiment Chart but dunno why does't work there. numbers are not the same shown in the bar chart windows.


                        [ATTACH]29995[/ATTACH]
                        For some reason, your attachments are invalid?

                        I get the idea of your code. Have you found it useful, truly? It might be worth looking into, just to get the coding right.

                        Comment


                          #13
                          Hey koganam, just re-uploaded the attachments, dunno what went wrong, anyways there you go, check em up

                          Comment


                            #14
                            Originally posted by kabott View Post
                            Hey koganam, just re-uploaded the attachments, dunno what went wrong, anyways there you go, check em up
                            Pretty good and clear coding there! Well commented. Cannot see how to improve that one. Very nice. You are a coder: do not let anyone tell you otherwise.

                            Comment


                              #15
                              Originally posted by koganam View Post
                              Pretty good and clear coding there! Well commented. Cannot see how to improve that one. Very nice. You are a coder: do not let anyone tell you otherwise.
                              LOL..get outta of here

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              168 views
                              0 likes
                              Last Post jeronymite  
                              Started by cre8able, Today, 04:22 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X