using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; namespace WealthLab.Strategies { public class MyStrategy : WealthScript { string symbol = ""; protected override void Execute() { Dictionary ActiveOrders = new Dictionary(); foreach(string sym in DataSetSymbols) { ActiveOrders[sym]=0; } Dictionary sharesToTrade=new Dictionary(); sharesToTrade["AMBA"]=50; sharesToTrade["FSLR"]=100; for(int bar = 20; bar < Bars.Count; bar++) { foreach(string s in DataSetSymbols) { symbol=s; SetContext(symbol,true); Position p = null; foreach(var pos in ActivePositions) if (pos.Symbol==symbol){ p=pos; break; } Set if (IsLastPositionActive) { //code your exit rules here DateTime ExitDate=Bars.Date[bar].AddDays(1); if (p!=null) ExitDate=p.EntryDate.AddDays(1) ; int exitBar=DateTimeToBar(ExitDate,false); if(p!=null && Bars.Symbol==symbol && bar>exitBar){ ExitAtMarket(bar+1, p,"Exit A day Later"); ActiveOrders[symbol]--; } } else { //code your entry rules here if(Bars.Symbol==symbol ){ SetShareSize(sharesToTrade[symbol]); BuyAtMarket(bar+1,"Long Entry"); ActiveOrders[symbol]++; } } RestoreContext(); } } } } }