1 #region Using statements 2 using System; 3 using System.Drawing; 4 using System.Collections.Generic; 5 using RightEdge.Common; 6 using RightEdge.Common.ChartObjects; 7 using RightEdge.Indicators; 8 using System.Linq; 9 #endregion 10 11 public class MySystem : MySystemBase 12 { 13 public override void Startup() 14 { 15 // Perform initialization or set system wide options here 16 17 } 18 19 public override void NewBar() 20 { 21 // Call NewBar in the SymbolScripts so they can calculate their RankValue 22 base.NewBar(); 23 24 // Order the symbol scripts so the ones with a higher RankValue come first 25 List<MySymbolScript> orderedSymbolScripts = 26 SymbolScripts.OrderByDescending(ss => ss.RankValue).ToList(); 27 28 // Update rankings 29 for (int i=0; i < orderedSymbolScripts.Count; i++) 30 { 31 // Add one to i so the first symbol has a rank of 1, not 0 32 orderedSymbolScripts[i].Rank = i + 1; 33 } 34 35 // Call Trade method 36 foreach (MySymbolScript ss in orderedSymbolScripts) 37 { 38 ss.Trade(); 39 } 40 } 41 } 42 43 public class MySymbolScript : MySymbolScriptBase 44 { 45 public double RankValue { get; private set; } 46 public int Rank { get; set; } 47 48 RelativeStrength _rsi; 49 50 public override void Startup() 51 { 52 // Perform initialization here. 53 _rsi = new RelativeStrength((int)SystemParameters["RSIPeriods"], Close); 54 } 55 56 // In the NewBar method, calculate and set the RankValue property 57 public override void NewBar() 58 { 59 if (double.IsNaN(_rsi.Current)) 60 { 61 RankValue = 0; 62 } 63 else 64 { 65 RankValue = Math.Abs(_rsi.Current); 66 } 67 } 68 69 // In the Trade method, make trading decisions based on the Rank property 70 // (and whatever other criteria you need) 71 public void Trade() 72 { 73 // Don't trade symbol if there isn't enough data to calculate an RSI 74 if (SystemData.InLeadBars || double.IsNaN(_rsi.Current)) 75 { 76 return; 77 } 78 79 if (Rank <= 5) 80 { 81 if (OpenPositions.Count == 0) 82 { 83 OpenPosition(PositionType.Long, OrderType.Market); 84 } 85 } 86 else 87 { 88 PositionManager.CloseAllPositions(Symbol); 89 } 90 91 } 92 93 public override void OrderFilled(Position position, Trade trade) 94 { 95 // This method is called when an order is filled 96 97 } 98 99 public override void OrderCancelled(Position position, Order order, string information) 100 { 101 // This method is called when an order is cancelled or rejected 102 103 } 104 } 105