protected override void Execute() { System.Threading.Thread.Sleep(5000); //5 seconds minimum, but the longer the interval, the more time required Bars b = GetExternalSymbol("AA", true); //... }
/* This script simply loads the Bars of a secondary symbol in global memory for this example, run on MSFT in a Streaming Window in the same interval as the primary symbol */ using System; using System.Collections.Generic; using WealthLab;namespace WealthLab.Strategies { public class PairsBarsLoader : WealthScript { protected override void Execute() { string s2Bars = Bars.Symbol + "(Bars)"; SetGlobal(s2Bars, Bars); } } }
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class PairsScript : WealthScript { protected override void Execute() { string stock1 = Bars.Symbol; // the 'clicked' symbol string stock2 = "MSFT"; // pairs symbol string s2Bars = stock2 + "(Bars)"; // global memory key DateTime lastDate = DateBars.Count - 1; Bars xBars; // retrieved from global memory in loop below DateTime s2date; int watchdog = 0; do { System.Threading.Thread.Sleep(500); // 0.5 sec delay xBars = (Bars)GetGlobal(s2Bars); // these bars are unsynched s2date = xBars.DatexBars.Count - 1; if (++watchdog > 10) // don't do this for more than 5 secs break; } while (s2date != lastDate); // synch the xBars xBars = Synchronize(xBars); /* Use xBars, xBars.Close, etc. for any indicators required for the secondary symbol */ // Pairs logic here... } } }