Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sorting in Ninja script

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

    #16
    Thank you, I wasn't familiar with the "Clear" instruction.
    You're right, in this case I don't have to print the members by index, but I also aim to learn a bit more every day, since I might need to call the first or last list entry for some future occurrence. Therefore, with which variable do I access them ?
    And by the way, why do you write "myList<> has only one member" if it is meant to contain 20 strings at any bar update (or even thousands, before your Clear help....)

    Comment


      #17
      Originally posted by Mauripasto View Post
      Thank you, I wasn't familiar with the "Clear" instruction.
      You're right, in this case I don't have to print the members by index, but I also aim to learn a bit more every day, since I might need to call the first or last list entry for some future occurrence. Therefore, with which variable do I access them ?
      And by the way, why do you write "myList<> has only one member" if it is meant to contain 20 strings at any bar update (or even thousands, before your Clear help....)
      That is not what I wrote. Please read in context. I wrote: "For the exact code that you have written, your myList<> has only one member". I even put the key phrase in bold text, (then and now) so that you would not miss it."

      Comment


        #18
        For not native English speakers, language nuances and subtleties are not easy to understand. I also don't know what else my exact code involves than the expected 20 strings from my instrument list for each bar update.

        In any case: if the foreach loop previously returned thousands of strings, now it prints just one, wherever I place myList.Clear();. Is there no way to get my 20 strings as desired ?

        And again: with which indexed variable may I also access them ?

        Comment


          #19
          Hello Mauripasto,

          Thank you for your response.

          You should be able to add 20 objects to a list and call them. The index would be from 0 to the Count of the List - 1. So 20 objects would be 0 through 19.

          Are you trying to up up to 20 objects and no more to the list? Do you only need the last 20 Math.Round(ADX(14)[0])?

          I believe if we understand the full scope we may be able to assist you in a more efficient manner.

          Comment


            #20
            Correct.
            I use to follow a small number (20) of preferred symbols, the ones selected through my instrument manager. Of these 20 symbols, I'd like to check the single ADX values at the desired timeframe, therefore I'm creating such strings:
            Math.Round(ADX(14)[0]) +" "+Instrument.FullName
            for each of them, adding them to "myList" at any bar update of the strategy's timeframe, and sorting them in order to easily identify the symbols with the highest ADX values (the first strings of the sorted "myList" will also appear in the Output and in the Alert windows).
            Then "myList" is voided and the process is repeated for the next bar and always for the same 20 symbols.
            However, in my present code "Sort", the list keeps track of only one string (the last called instrument), although I'm supposed to clear it not during but AFTER the bar update.
            Am I wrong?
            Attached Files

            Comment


              #21
              Originally posted by Mauripasto View Post
              Correct.
              I use to follow a small number (20) of preferred symbols, the ones selected through my instrument manager. Of these 20 symbols, I'd like to check the single ADX values at the desired timeframe, therefore I'm creating such strings:
              Math.Round(ADX(14)[0]) +" "+Instrument.FullName
              for each of them, adding them to "myList" at any bar update of the strategy's timeframe, and sorting them in order to easily identify the symbols with the highest ADX values (the first strings of the sorted "myList" will also appear in the Output and in the Alert windows).
              Then "myList" is voided and the process is repeated for the next bar and always for the same 20 symbols.
              However, in my present code "Sort", the list keeps track of only one string (the last called instrument), although I'm supposed to clear it not during but AFTER the bar update.
              Am I wrong?
              Here is your code logic, with notes about what you have written and how it will process.
              if (BarsInProgress != 0) //this says that you want to process ONLY on ONE BarSeries, the primary. All others are to be bypassed
              return;

              if(CurrentBar <= BarsRequired)
              return;

              myList.Add(Math.Round(ADX(14)[0]) +" "+Instrument.FullName); //this adds ONE item to myList<> every time that it is run.
              Ergo, your code asks for exactly one tick, on one (the primary), instrument to be processed per bar, so you are going to have only one entry in your myList<>.

              Correct your logic. You might want to remove or correct the BarsInProgress check as a first step. Why is it there in the first place?
              Last edited by koganam; 05-13-2015, 09:02 AM.

              Comment


                #22
                I totally removed
                if (BarsInProgress != 0) return
                from the code, but as you say,
                myList.Add(Math.Round(ADX(14)[0]) +" "+Instrument.FullName);
                keeps on adding just one item to myList at each bar update, then there is only a myList[0], no myList[1] and of course no sorting: what must I do to have all my instruments into "myList" ?

                Comment


                  #23
                  Hello Mauripasto,

                  Your script is not a multiple instrument script, are you running the indicator on multiple charts and looking for one central list to pull from?

                  For information on multiple instrument scripts please visit the following link: http://www.ninjatrader.com/support/h...nstruments.htm

                  Comment


                    #24
                    Originally posted by Mauripasto View Post
                    I totally removed
                    if (BarsInProgress != 0) return
                    from the code, but as you say,
                    myList.Add(Math.Round(ADX(14)[0]) +" "+Instrument.FullName);
                    keeps on adding just one item to myList at each bar update, then there is only a myList[0], no myList[1] and of course no sorting: what must I do to have all my instruments into "myList" ?
                    I asked, what is BarsInProgress doing in the script? Why is it there?

                    Comment


                      #25
                      I enabled my script as a new Strategy (not an indicator) in the "Control Center -> Strategies" tab for my default instrument list.
                      BarsInProgress was meant for other parts of my strategy, but here I'm extrapolating just the sort routine, where actually it has no relevance at all, so it is now removed from the code we are talking about.

                      Comment


                        #26
                        Hello Mauripasto,

                        Thank you for your response.

                        I attached a version of your Sort strategy that only adds 20 strings. Please review and let me know if you have any questions. Once you have reviewed let's take a look at how you want to set up the conditions for your Alerts.

                        I look forward to assisting you further.
                        Attached Files

                        Comment


                          #27
                          Originally posted by NinjaTrader_PatrickH View Post
                          Hello Mauripasto,

                          Thank you for your response.

                          I attached a version of your Sort strategy that only adds 20 strings. Please review and let me know if you have any questions. Once you have reviewed let's take a look at how you want to set up the conditions for your Alerts.

                          I look forward to assisting you further.
                          You misunderstand his apparent intent, methinks.

                          He wants to compare/massage the ADX values for a list of stocks against each other, not get the last 20 values for one stock.

                          He will almost certainly need to use a multi-instrument script, if that is what he wants to do. Unfortunately he does not seem to be able to quite explain what he really wants to do, and some of these sparse descriptions and related questions are muddying the waters.

                          Comment


                            #28
                            Thanks koganam.


                            Mauripasto, can you clarify on this for us here?

                            Comment


                              #29
                              Actually, it's a pretty simple thing.
                              Let's figure out that I trade just THREE stocks: Apple, Google and Ibm. My Instrument Manager, my Default Instrument List and all my Strategies combine to track them as well as their values at any bar update.
                              At 9:38 a.m. their ADX values are 15 (for Apple), 11 (for Google) and 20 (for Ibm).
                              Ninja is to create a "myList" with the following strings:
                              "15 AAPL"
                              "11 GOOG"
                              "20 IBM"
                              and to sort them for me properly:
                              1. "20 IBM"
                              2. "15 AAPL"
                              3. "11 GOOG"

                              telling me that at present Ibm has the highest ADX, and that Google is rather flat.

                              At the next bar, my ADX values may be 23 for Apple, 39 for Google and 21 for IBM.

                              MyList will first be emptied, then populated with 3 new strings:
                              "23 AAPL"
                              "39 GOOG"
                              "21 IBM"
                              then sorted this way:
                              1. "39 GOOG"
                              2. "23 AAPL"
                              3. "21 IBM"

                              telling me that Google's ADX is now the highest (and also, that it's climbing very fast right now, if I look at the previous record).
                              Similarly for the next bars.
                              That's all.
                              I need no multiframe functions, since I always use current ADX values. I need no comparison with previous values either, since I'm recording them all (sorted) in the Output and in the Alert Windows: what is enough to me. Eventually, I'm able to add multiframe data too, but all I really need are just 3 strings for my 3 selected symbols during each update. My problem is that so far I got either one or 10,000.
                              Hope I was clear, it's surely not complicate.
                              Last edited by Mauripasto; 05-15-2015, 07:54 PM.

                              Comment


                                #30
                                Originally posted by Mauripasto View Post
                                Actually, it's a pretty simple thing.
                                Let's figure out that I trade just THREE stocks: Apple, Google and Ibm. My Instrument Manager, my Default Instrument List and all my Strategies combine to track them as well as their values at any bar update.
                                At 9:38 a.m. their ADX values are 15 (for Apple), 11 (for Google) and 20 (for Ibm).
                                Ninja is to create a "myList" with the following strings:
                                "15 AAPL"
                                "11 GOOG"
                                "20 IBM"
                                and to sort them for me properly:
                                1. "20 IBM"
                                2. "15 AAPL"
                                3. "11 GOOG"

                                telling me that at present Ibm has the highest ADX, and that Google is rather flat.

                                At the next bar, my ADX values may be 23 for Apple, 39 for Google and 21 for IBM.

                                MyList will first be emptied, then populated with 3 new strings:
                                "23 AAPL"
                                "39 GOOG"
                                "21 IBM"
                                then sorted this way:
                                1. "39 GOOG"
                                2. "23 AAPL"
                                3. "21 IBM"

                                telling me that Google's ADX is now the highest (and also, that it's climbing very fast right now, if I look at the previous record).
                                Similarly for the next bars.
                                That's all.
                                I need no multiframe functions, since I always use current ADX values. I need no comparison with previous values either, since I'm recording them all (sorted) in the Output and in the Alert Windows: what is enough to me. Eventually, I'm able to add multiframe data too, but all I really need are just 3 strings for my 3 selected symbols during each update. My problem is that so far I got either one or 10,000.
                                Hope I was clear, it's surely not complicate.
                                If you want to process multiple instruments from the same script, which is what you describe here, then you need a multi-instrument script.

                                Add() all the necessary instruments (that you want to process) at the correct place.

                                ref: http://www.ninjatrader.com/support/h...s/nt7/add3.htm

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by ageeholdings, Today, 07:43 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post ageeholdings  
                                Started by pibrew, Today, 06:37 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post pibrew
                                by pibrew
                                 
                                Started by rbeckmann05, Yesterday, 06:48 PM
                                1 response
                                14 views
                                0 likes
                                Last Post bltdavid  
                                Started by llanqui, Today, 03:53 AM
                                0 responses
                                6 views
                                0 likes
                                Last Post llanqui
                                by llanqui
                                 
                                Started by burtoninlondon, Today, 12:38 AM
                                0 responses
                                12 views
                                0 likes
                                Last Post burtoninlondon  
                                Working...
                                X