using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class Multisystem : WealthScript { protected override void Execute() { System1.Run(this); System2.Run(this); } } class System1 { public static void Run(WealthScript obj) { for(int bar = 20; bar < obj.Bars.Count; bar++) { if (obj.IsLastPositionActive) { obj.SellAtStop( bar+1, obj.LastPosition, Lowest.Series( obj.Low,10 )[bar] ); } else { obj.BuyAtStop( bar+1, Highest.Series( obj.High,20 )[bar], "System1" ); } // Workaround to prevent open positions from one system to be available for the next system to close if( bar == obj.Bars.Count-1 ) obj.SellAtClose( bar, Position.AllPositions, "Close All" ); } } } class System2 { public static void Run(WealthScript obj) { for(int bar = 20; bar < obj.Bars.Count; bar++) { if (obj.IsLastPositionActive) { obj.SellAtMarket( bar+1, obj.LastPosition ); } else { obj.BuyAtLimit( bar+1, obj.Low[bar]*0.95, "System2" ); } // Workaround to prevent open positions from one system to be available for the next system to close if( bar == obj.Bars.Count-1 ) obj.SellAtClose( bar, Position.AllPositions, "Close All" ); } } } }
... using System.Threading.Tasks; // <- run the subsystems in multiple threads via Task public class Multisystem : WealthScript { protected override void Execute() { Task.Run(() => System1.Run(this, ref sharedObj1, sharedObj2)); Task.Run(() => System2.Run(this, sharedObj1, ref sharedObj2)); } } ...