Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars Array Instrument Ranking

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

    Bars Array Instrument Ranking

    Hi guys. I am interested to find out how to rank the output from barsarray for 10 instruments. For example if I add 4 separate instruments like so:

    //AddRenko(instrument1, 10, MarketDataType.Last);
    //AddRenko(instrument1, 10, MarketDataType.Last);
    //AddRenko(instrument1, 10, MarketDataType.Last);
    //AddRenko(instrument1, 10, MarketDataType.Last);

    then create doubles of these:

    double instrument1EMA = EMA(BarsArray[1], 13)[0]
    double instrument2EMA = EMA(BarsArray[2], 13)[0]
    double instrument3EMA = EMA(BarsArray[3], 13)[0]
    double instrument4EMA = EMA(BarsArray[4], 13)[0]


    Now what I would like to do is rank each of these instruments based on their EMA and assign a string. I know how to go if instrument1EMA > (instrument2EMA && instrument2EMA && instrument3EMA) etc but this is very cumbersome and time consuming. So is there an easier way to rank things and say something like:

    If out of the above list give me the one with the highest EMA then give me the one with second highest EMA etc. I checked the manual but couldn't find anything relevant and my programming skills are "evolving".

    Thanks
    DJ

    #2
    DJ, I think for your use you can try nesting Math.Max statements like :

    Code:
    double val1 = 1;
    double val2 = 2;
    double val3 = 3;
    double val4 = 4;
    			
    double max = Math.Max(Math.Max(val1, val2), Math.Max(val3, val4));

    Comment


      #3
      Math Command

      Hi Bertrand , many thanks for posting that. I haven't seen that math command anywhere but sure does the trick. So anyway I am getting quite close now but need a little more help on it (please see attached code). Firstly what is the significance of placing them as two separate items like you had (I'm not really sure what this does is the problem):

      double max = Math.Max(Math.Max(TF, ES), Math.Max(euro, GC));

      instead of:

      double max = Math.Max(Math.Max(TF, ES, euro, GC));

      Second issue is I have a chart to illustrate and have put the EMA values in the top left to see where I am at (I am just using EMA to get the logic correct). The main thing is it correctly puts the highest one using your math command which is great. The issue is how do I rank the others and show them?.

      So to illustrate what I'm trying to go is in the other chart. So what happens is this code will run on all 4 charts and then the instrument which ranks the highest based on specific criteria will have "Rank 1" then the next one "Rank2" then "Rank 3" and then "Rank 4". There are actually 8 charts and instruments to rank. Now the question with your code and the math command is how do I use that code to rank the second highest and the third highest etc? Is it something like double max2 then exclude max from the double max2 ?

      Thanks
      DJ
      Attached Files
      Last edited by djkiwi; 04-07-2011, 01:18 AM. Reason: code added

      Comment


        #4
        DJ, the Math command allows for a comparison of two values, so you would need to nest them for making this work. For the ranking of your instruments you could consider using a SortedList in C# for example - http://msdn.microsoft.com/en-us/libr...(v=VS.90).aspx

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        580 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        335 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        102 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X