• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ranking

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

    Ranking

    Code:
    		 if (SystemPerformance.AllTrades.Count >1)
    		 {
    			 nzd_PL		=0;
    			 aud_PL		=0;
    			 audnzd_PL	=0;
    			 eur_PL		=0;
    			 cad_PL		=0;
    			 
    		      foreach (Trade myTrade in SystemPerformance.AllTrades)
    		      {
    				  if(myTrade.Entry.Instrument.MasterInstrument.Name.Equals("NZDUSD"))
    				   nzd_PL+=myTrade.ProfitCurrency;			  
    				  if(myTrade.Entry.Instrument.MasterInstrument.Name.Equals("AUDUSD"))
    				 	 aud_PL+=myTrade.ProfitCurrency;	
    				  if(myTrade.Entry.Instrument.MasterInstrument.Name.Equals("AUDNZD"))
    				 	 audnzd_PL+=myTrade.ProfitCurrency;				  
    				  if(myTrade.Entry.Instrument.MasterInstrument.Name.Equals("EURUSD"))
    				 	 eur_PL+=myTrade.ProfitCurrency;
    				  if(myTrade.Entry.Instrument.MasterInstrument.Name.Equals("USDCAD"))
    				 	 cad_PL+=myTrade.ProfitCurrency;				  
    			  }
    			  
    			  cum_tickerPL = nzd_PL+aud_PL+audnzd_PL+eur_PL+cad_PL;
    			}
    How can I rank nzd_pl,aud_pl etc. In other words, if nzd_PL is the highest value in comparison to others, I'd like to give it rank 1 and if aud_PL is the lowest value, I'd like to give it rank of 5. This way, I can allocate funds to the best performing strategy and allocate the least amount to the underperforming strategy.

    #2
    Hello calhawk01,

    Thanks for your post.

    This is not a Ninjascript question but more of a processing question.

    One idea would be to put the values in an array and then sort the array to provide the ranking. You can find array sorting info on the internet. Here is one reference: https://www.dotnetperls.com/array-sort

    Another idea may be to use the totaled values as 100% and then take each input as x% and apply your funds in that manner. So if nzd_PL is 27.5% of cum_tickerPL then you could allocate 27.5% to nzd.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello calhawk01,

      Thanks for your post.

      This is not a Ninjascript question but more of a processing question.

      One idea would be to put the values in an array and then sort the array to provide the ranking. You can find array sorting info on the internet. Here is one reference: https://www.dotnetperls.com/array-sort

      Another idea may be to use the totaled values as 100% and then take each input as x% and apply your funds in that manner. So if nzd_PL is 27.5% of cum_tickerPL then you could allocate 27.5% to nzd.
      Percentage allocation is a good idea but not practical. I'm going to be doing daily or weekly allocation. So for example, if nzd_PL for a given day had zero trades, and aud_PL had 10 trades and most of the PL (even if it was 1 cent) came from aud_PL, then aud_PL would get, for example, 90% of the allocation.. which isn't practical. I'm really concerned about the 1st and last rank and based on those I can do the following allocations:

      rank1= 30%
      rank2=20%
      rank3=20%
      rank4=20%
      rank5=10%

      So If i can specify rank1 and rank5, I can do their appropriate allocations, everything else can get 20%.

      Code:
      			  if((nzd_PL> aud_PL
      				  &nzd_PL> audnzd_PL 
      				  &nzd_PL> eur_PL 
      				  &nzd_PL> cad_PL)
      				  (&aud_PL < audnzd_PL
      				  & aud_PL< eur_PL 
      				  & aud_PL< cad_PL))
      				 {
      					 //nzd_pl rank =1
      					 //aud_pl rank =5
      				 }
      				 
      			  if((aud_PL> nzd_PL
      				  &aud_PL> audnzd_PL 
      				  &aud_PL> eur_PL 
      				  &aud_PL> cad_PL)
      				  (&nzd_PL < audnzd_PL
      				  & nzd_PL< eur_PL 
      				  & nzd_PL< cad_PL))
      				 {
      					 //aud_pl rank =1
      					 //nzd_pl rank =5
      				 }
      maybe I have to do something like above, but the problem with that is that there are so many combinations that i'd have to include in the code and that would cause the length of the code to get big. I have no idea how to do arrays etc.

      Comment


        #4
        Hello calhawk01,

        Thanks for your post.

        I would suggest following the internet link previously provided to start reviewing array processing.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by calhawk01 View Post
          Percentage allocation is a good idea but not practical. I'm going to be doing daily or weekly allocation. So for example, if nzd_PL for a given day had zero trades, and aud_PL had 10 trades and most of the PL (even if it was 1 cent) came from aud_PL, then aud_PL would get, for example, 90% of the allocation.. which isn't practical. I'm really concerned about the 1st and last rank and based on those I can do the following allocations:

          rank1= 30%
          rank2=20%
          rank3=20%
          rank4=20%
          rank5=10%

          So If i can specify rank1 and rank5, I can do their appropriate allocations, everything else can get 20%.

          Code:
          			  if((nzd_PL> aud_PL
          				  &nzd_PL> audnzd_PL 
          				  &nzd_PL> eur_PL 
          				  &nzd_PL> cad_PL)
          				  (&aud_PL < audnzd_PL
          				  & aud_PL< eur_PL 
          				  & aud_PL< cad_PL))
          				 {
          					 //nzd_pl rank =1
          					 //aud_pl rank =5
          				 }
          				 
          			  if((aud_PL> nzd_PL
          				  &aud_PL> audnzd_PL 
          				  &aud_PL> eur_PL 
          				  &aud_PL> cad_PL)
          				  (&nzd_PL < audnzd_PL
          				  & nzd_PL< eur_PL 
          				  & nzd_PL< cad_PL))
          				 {
          					 //aud_pl rank =1
          					 //nzd_pl rank =5
          				 }
          maybe I have to do something like above, but the problem with that is that there are so many combinations that i'd have to include in the code and that would cause the length of the code to get big. I have no idea how to do arrays etc.
          The most inefficient code ever written

          Code:
          			#region nzdrank1			  
          			  if((nzd_PL> aud_PL
          				  &nzd_PL> audnzd_PL 
          				  &nzd_PL> eur_PL 
          				  &nzd_PL> cad_PL)
          				  (&aud_PL < audnzd_PL
          				  & aud_PL< eur_PL 
          				  & aud_PL< cad_PL))
          				 {
          					 //nzd_pl rank =1
          					 //aud_pl rank =5
          				 }
          			  if((nzd_PL> aud_PL
          				  &nzd_PL> audnzd_PL 
          				  &nzd_PL> eur_PL 
          				  &nzd_PL> cad_PL)
          				  (&audnzd_PL < aud_PL
          				  & audnzd_PL< eur_PL 
          				  & audnzd_PL< cad_PL))
          				 {
          					 //nzd_pl rank =1
          					 //audnzd_pl rank =5
          				 }
          			  if((nzd_PL> aud_PL
          				  &nzd_PL> audnzd_PL 
          				  &nzd_PL> eur_PL 
          				  &nzd_PL> cad_PL)
          				  (&eur_PL < aud_PL
          				  & eur_PL< audnzd_PL 
          				  & eur_PL< cad_PL))
          				 {
          					 //nzd_pl rank =1
          					 //eur_pl rank =5
          				 }
          			  if((nzd_PL> aud_PL
          				  &nzd_PL> audnzd_PL 
          				  &nzd_PL> eur_PL 
          				  &nzd_PL> cad_PL)
          				  (&cad_PL < audnzd_PL
          				  & cad_PL< eur_PL 
          				  & cad_PL< aud_PL))
          				 {
          					 //nzd_pl rank =1
          					 //cad_pl rank =5
          				 }
          			#endregion
          			#region audrank1			  
          			  if((aud_PL> nzd_PL
          				  &aud_PL> audnzd_PL 
          				  &aud_PL> eur_PL 
          				  &aud_PL> cad_PL)
          				  (&nzd_PL < audnzd_PL
          				  & nzd_PL < eur_PL 
          				  & nzd_PL < cad_PL))
          				 {
          					 //aud_pl rank =1
          					 //nzd_pl rank =5
          				 }
          			  if((aud_PL> nzd_PL
          				  &aud_PL> audnzd_PL 
          				  &aud_PL> eur_PL 
          				  &aud_PL> cad_PL)
          				  (&audnzd_PL < nzd_PL
          				  & audnzd_PL< eur_PL 
          				  & audnzd_PL< cad_PL))
          				 {
          					 //aud_pl rank =1
          					 //audnzd_pl rank =5
          				 }
          			  if((aud_PL> nzd_PL
          				  &aud_PL> audnzd_PL 
          				  &aud_PL> eur_PL 
          				  &aud_PL> cad_PL)
          				  (&eur_PL < nzd_PL
          				  & eur_PL< audnzd_PL 
          				  & eur_PL< cad_PL))
          				 {
          					 //aud_pl rank =1
          					 //eur_pl rank =5
          				 }
          			  if((aud_PL> nzd_PL
          				  &aud_PL> audnzd_PL 
          				  &aud_PL> eur_PL 
          				  &aud_PL> cad_PL)
          				  (&cad_PL < audnzd_PL
          				  & cad_PL< eur_PL 
          				  & cad_PL< nzd_PL))
          				 {
          					 //aud_pl rank =1
          					 //cad_pl rank =5
          				 }
          			#endregion
          			#region audnzdrank1			  
          			  if((audnzd_PL> aud_PL
          				  &audnzd_PL> audnzd_PL 
          				  &audnzd_PL> eur_PL 
          				  &audnzd_PL> cad_PL)
          				  (&aud_PL < nzd_PL
          				  & aud_PL< eur_PL 
          				  & aud_PL< cad_PL))
          				 {
          					 //audnzd_pl rank =1
          					 //aud_pl rank =5
          				 }
          			  if((audnzd_PL> aud_PL
          				  &audnzd_PL> audnzd_PL 
          				  &audnzd_PL> eur_PL 
          				  &audnzd_PL> cad_PL)
          				  (&nzd_PL < aud_PL
          				  & nzd_PL< eur_PL 
          				  & nzd_PL< cad_PL))
          				 {
          					 //audnzd_pl rank =1
          					 //audnzd_pl rank =5
          				 }
          			  if((audnzd_PL> aud_PL
          				  &audnzd_PL> audnzd_PL 
          				  &audnzd_PL> eur_PL 
          				  &audnzd_PL> cad_PL)
          				  (&eur_PL< aud_PL
          				  & eur_PL< nzd_PL 
          				  & eur_PL< cad_PL))
          				 {
          					 //audnzd_pl rank =1
          					 //eur_pl rank =5
          				 }
          			  if((audnzd_PL> aud_PL
          				  &audnzd_PL> audnzd_PL 
          				  &audnzd_PL> eur_PL 
          				  &audnzd_PL> cad_PL)
          				  (&cad_PL < nzd_PL
          				  & cad_PL< eur_PL 
          				  & cad_PL< aud_PL))
          				 {
          					 //nzd_pl rank =1
          					 //cad_pl rank =5
          				 }
          			#endregion
          			#region eurrank1			  
          			  if((eur_PL> aud_PL
          				  &eur_PL> audnzd_PL 
          				  &eur_PL> nzd_PL 
          				  &eur_PL> cad_PL)
          				  (&aud_PL < audnzd_PL
          				  & aud_PL< nzd_PL 
          				  & aud_PL< cad_PL))
          				 {
          					 //eur_pl rank =1
          					 //aud_pl rank =5
          				 }
          			  if((eur_PL> aud_PL
          				  &eur_PL> audnzd_PL 
          				  &eur_PL> nzd_PL 
          				  &eur_PL> cad_PL)
          				  (&audnzd_PL < aud_PL
          				  & audnzd_PL< nzd_PL 
          				  & audnzd_PL< cad_PL))
          				 {
          					 //eur_pl rank =1
          					 //audnzd_pl rank =5
          				 }
          			  if((eur_PL> aud_PL
          				  &eur_PL> audnzd_PL 
          				  &eur_PL> nzd_PL 
          				  &eur_PL> cad_PL)
          				  (&nzd_PL < aud_PL
          				  & nzd_PL< audnzd_PL 
          				  & nzd_PL< cad_PL))
          				 {
          					 //eur_pl rank =1
          					 //nzd_pl rank =5
          				 }
          			  if((eur_PL> aud_PL
          				  &eur_PL> audnzd_PL 
          				  &eur_PL> nzd_PL 
          				  &eur_PL> cad_PL)
          				  (&cad_PL < audnzd_PL
          				  & cad_PL< nzd_PL 
          				  & cad_PL< aud_PL))
          				 {
          					 //eur_pl rank =1
          					 //cad_pl rank =5
          				 }
          			#endregion
          			#region cadrank1			  
          			  if((cad_PL> aud_PL
          				  &cad_PL> audnzd_PL 
          				  &cad_PL> eur_PL 
          				  &cad_PL> cad_PL)
          				  (&aud_PL < audnzd_PL
          				  & aud_PL< eur_PL 
          				  & aud_PL< nzd_PL))
          				 {
          					 //cad_pl rank =1
          					 //aud_pl rank =5
          				 }
          			  if((cad_PL> aud_PL
          				  &cad_PL> audnzd_PL 
          				  &cad_PL> eur_PL 
          				  &cad_PL> cad_PL)
          				  (&audnzd_PL < aud_PL
          				  & audnzd_PL< eur_PL 
          				  & audnzd_PL< nzd_PL))
          				 {
          					 //cad_pl rank =1
          					 //audnzd_pl rank =5
          				 }
          			  if((cad_PL> aud_PL
          				  &cad_PL> audnzd_PL 
          				  &cad_PL> eur_PL 
          				  &cad_PL> cad_PL)
          				  (&eur_PL < aud_PL
          				  & eur_PL< audnzd_PL 
          				  & eur_PL< nzd_PL))
          				 {
          					 //cad_pl rank =1
          					 //eur_pl rank =5
          				 }
          			  if((cad_PL> aud_PL
          				  &cad_PL> audnzd_PL 
          				  &cad_PL> eur_PL 
          				  &cad_PL> cad_PL)
          				  (&nzd_PL < audnzd_PL
          				  & nzd_PL< eur_PL 
          				  & nzd_PL< aud_PL))
          				 {
          					 //cad_pl rank =1
          					 //nzd_pl rank =5
          				 }
          			#endregion
          Basically I made ranking for the 1st and last stop for each one of the instruments. Just posting it, in the case someone else needs to use it. Besides, hoping someone feels bad for me and posts a more efficient code

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Captain_Qwark, Today, 10:55 AM
          3 responses
          18 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by kmpc1, Today, 11:03 AM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_PatrickG  
          Started by jransom, Today, 09:08 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Kate  
          Started by mtamaku, Today, 09:19 AM
          0 responses
          23 views
          0 likes
          Last Post mtamaku
          by mtamaku
           
          Started by traderMNQ, Today, 09:00 AM
          4 responses
          20 views
          0 likes
          Last Post traderMNQ  
          Working...
          X