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

Data box data script

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

    #31
    Now with:

    int bar = Math.Abs(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex);
    double volume = Volume.GetValueAt(bar);
    double close = Close.GetValueAt(ChartBars.GetBarIdxByX(chartContr ol, cursorPointX));

    close give me the right number but only for the specific bar i click on.

    How do i sum the close of the numbers of barsago i click on.
    In the chart i provided there was 5 barsago and i want to sum each close for the 5 barsago so if the 5 bars ago have a close price of 2873, 2873.5, 2873.75, 2873, 2773.25 the sum = 14266.5
    i want close to reflect that result.

    Is there a method or whatever for that?
    Thanks for your patience.

    Comment


      #32
      Hello frankduc,

      The reason this is for the bar you click on is that this thread was started based on that being the requirement, you are using the cursor position in the syntax here so that is going to produce the result of where the cursor is.

      You now have other requirements of spanning more than one bar so you would need to make logic to do that. This thread contains the syntax needed to get BarsAgo, Indexes or specific price/volume values from the cursor position, you can use the information these various calculations provide to do other logic if needed.

      You would likely need to use a for loop if you wanted to gather more prices than the one you had clicked on over a span of bars. To learn more about for loops, please use a search engine to look up C# educational resources or use MSDN. To create a sum of data which is not in Series<T> form, you would need to look at C# ways of doing that such as using a List<T> or an array and their Sum() method. This is not a NinjaScript item so you can research this in C# educational resources such as MSDN. Here is one public link showing how to sum values in C#: https://www.dotnetperls.com/sum

      Please let me know if I may be of additional assistance.


      JesseNinjaTrader Customer Service

      Comment


        #33
        Hello,

        Is it possible instead to use SUM indicator script to gather the sum of all prices between (ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex)?

        The line is Value[0] = Input[0] + (CurrentBar > 0 ? Value[1] : 0) - (CurrentBar >= Period ? Input[Period] : 0); and the result is the summation of all close for a specific period.

        What if i replace Period =
        Value[0] = Input[0] + (CurrentBar > 0 ? Value[1] : 0) - (CurrentBar >= (ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex) ? Input[(ChartBars.GetBarIdxByX(chartControl, cursorPointX) - ChartBars.ToIndex)] : 0);


        Ok its probably a nonsense but there must be a way to recycle the result of the sum script indicator to use it in my case. So that close = all the sum of closes between cursorpointx and chartbars.toindex.
        Last edited by frankduc; 05-08-2019, 06:50 AM.

        Comment


          #34
          Hello frankduc,

          In this context no that would not be possible, The SUM works on a Series of data, you are instead looking at a segment of a series which is not what the SUM indicator is asking for its input.

          You could recreate what the sum is doing to do a mathematical SUM in a loop, an easier approach is to use an array or list in C# and use the built in SUM function. Unless you are supplying a Series of data to the SUM it would not be of use here.

          Please let me know if I may be of additional assistance.
          JesseNinjaTrader Customer Service

          Comment


            #35
            for (double i = ChartBars.GetBarIdxByX(chartControl, cursorPointX ); i >= ChartBars.ToIndex; i--);
            double[] doubleArray = {close};
            double sum1 = doubleArray.Sum();


            but i still get the close for cursorpointx not the sum of all closes. use doubleArray or List sum doubleArray.sum or list1.sum return the same.
            i dont get how to list all closes.

            Close is a double, but how can i use it in.
            Anyone has made an exemple how to manipulate close, high, low using array, for, etc? Something i can copy and manipulate?

            ty
            Last edited by frankduc; 05-14-2019, 06:32 AM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by dustydbayer, Today, 01:59 AM
            0 responses
            1 view
            0 likes
            Last Post dustydbayer  
            Started by inanazsocial, Today, 01:15 AM
            0 responses
            2 views
            0 likes
            Last Post inanazsocial  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            22 views
            0 likes
            Last Post trilliantrader  
            Started by Davidtowleii, Today, 12:15 AM
            0 responses
            3 views
            0 likes
            Last Post Davidtowleii  
            Started by guillembm, Yesterday, 11:25 AM
            2 responses
            10 views
            0 likes
            Last Post guillembm  
            Working...
            X