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

Percentage of a time period

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

    Percentage of a time period

    Good afternoon.

    I need to express in c # the% rise or fall in a period that is a (Variable)



    For example compare the percentage so close to previous close, but I need to compare last sealing with a period that can be a variable, get percentage rise or fall from a particular time period.
    100 * ((Close [0]-Close [0]) / Close [0]) ;/ / closures Percent

    Greetings.

    #2
    Hello optimuss,

    Could you clarify, are you wanting to compare the current/last close price to the average of the Close price over a period?

    As it looks like now you are getting the difference of two different periods and trying to get the difference percentage from the current/last close which will probably very small.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by optimuss View Post
      Good afternoon.

      I need to express in c # the% rise or fall in a period that is a (Variable)



      For example compare the percentage so close to previous close, but I need to compare last sealing with a period that can be a variable, get percentage rise or fall from a particular time period.
      100 * ((Close [0]-Close [0]) / Close [0]) ;/ / closures Percent

      Greetings.
      Is that not just
      Code:
      Plot0.Set(100 * ((Close [0]-Close [VarPeriod]) / Close [VarPeriod]) ;
      ?
      Last edited by koganam; 07-20-2013, 01:50 PM.

      Comment


        #4
        Hello NinjaTrader_JC koganam and thanks to you for your help and sorry for the late reply.

        Seeking to obtain the percentage change close [variable] to close [0], not the average, if the accumulated.

        I'm trying to do;
        Plot0.Set (100 * ((Close [0] Close [VarPeriod]) / Close [VarPeriod]));
        koganam so it is not possible, the indicator does not take any values ​​so this expression.

        As would have to say to get the cumulative percentage from?
        close [variable] to close [0]?.

        Thank you.

        Comment


          #5
          Originally posted by optimuss View Post
          Hello NinjaTrader_JC koganam and thanks to you for your help and sorry for the late reply.

          Seeking to obtain the percentage change close [variable] to close [0], not the average, if the accumulated.

          I'm trying to do;
          Plot0.Set (100 * ((Close [0] Close [VarPeriod]) / Close [VarPeriod]));
          koganam so it is not possible, the indicator does not take any values ​​so this expression.

          As would have to say to get the cumulative percentage from?
          close [variable] to close [0]?.

          Thank you.
          That may be why I am confused. I certainly am lost with what you intend to do. The percentage change in price from VarPeriod ago to the current bar is identically:
          Code:
          100 * ((Close [0]-Close [VarPeriod]) / Close [VarPeriod])
          What you actually want to do with it is a different kettle of fish. I just assumed that you wanted to plot it, so set it to a Plot(). Incidentally, that IS the correct statement; what you posted is semantically incorrect.

          Comment


            #6
            Koganam Hello, thank you very much for your help.

            Take a sight to see as this as what you say, if you insert well in graphic indicator does not return any value ..

            Garcias.
            Attached Files

            Comment


              #7
              Originally posted by optimuss View Post
              Koganam Hello, thank you very much for your help.

              Take a sight to see as this as what you say, if you insert well in graphic indicator does not return any value ..

              Garcias.
              That is a different issue.

              Look in your log, and you will see the error. Search this forum using the error, and you will find many threads with the solution. It has to do with your not having enough bars when you first try to do the calculation.

              Try putting:
              Code:
              if (CurrentBar < VarPeriod) return;
              at the top of your OnBarUpdate() handler.

              Comment


                #8
                woooo, that's right! sometimes they do not give importance to that instruction.

                Many thanks friend for your great help.


                Best wishes.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                382 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Started by oviejo, Today, 12:28 AM
                0 responses
                1 view
                0 likes
                Last Post oviejo
                by oviejo
                 
                Started by pechtri, 06-22-2023, 02:31 AM
                10 responses
                125 views
                0 likes
                Last Post Leeroy_Jenkins  
                Started by judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                59 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Yesterday, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Working...
                X