using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class MyStrategy : WealthScript { private bool dont_trade = false; // here's your "global" private bool SymbolIsActive(string sym) { foreach (Position p in ActivePositions) if( sym == p.Bars.Symbol ) return true; return false; } protected override void Execute() { for(int bar = 20; bar < Bars.Count; bar++) { // Entry logic foreach (string sym in DataSetSymbols) { if( !dont_trade && !SymbolIsActive(sym) ) { SetContext( sym, true ); if (Bars.FirstActualBar > bar) continue; SMA sma = SMA.Series( Close, 20 ); if( CrossOver( bar, Close, sma ) ) BuyAtMarket( bar+1, "SMA CrossOver" ); } } RestoreContext(); // Exit logic int loserCount = 0; for( int p = ActivePositions.Count - 1; p >= 0; p-- ) { Position pos = ActivePositions[p]; if( bar >= pos.EntryBar ) { string sym = pos.Bars.Symbol; SetContext( sym, true ); SMA sma = SMA.Series( Close, 20 ); if( CrossUnder( bar, Close, sma ) ) { SellAtMarket( bar+1, pos, "Time-Based" ); if( pos.NetProfitPercent < 0 ) loserCount++; } } } dont_trade = (loserCount >= 2); } } } }