General | Choosing optimal trading tool: Strategy Monitor or Strategy window

Modified on 2017/02/08 11:05 by Administrator — Categorized as: Knowledge Base

If you're asking yourself, what is optimal for my trading, Strategy Monitor or Strategy window, this article will help you pick the appropriate trading tool.

If you trade more than 12-15 symbols, consider using the Strategy Monitor. The Strategy Monitor is recommended for pair trading Strategies. For Fidelity customers, WLP version 6.4 and higher, brings big performance improvement to the Strategy Monitor by virtue of new "Streaming bars" feature.

As processing power varies by machine, strategy, etc., be careful not to run too many symbols in the Strategy Monitor if using high-frequency data, though. If you notice that the loading of 1-minute data gets pretty slow, taking many minutes, we recommend you truncate your DataSet (hundreds of 1-minute symbols is the main bottleneck), or split up the task with another PC, or get a faster PC, or think about trading your strategy on a higher timeframe.

If you trade less than a dozen symbols, we suggest using Streaming strategies. Streaming Strategy windows execute immediately at the end of the bar w/o delay, unlike Strategy Monitor. Note: for optimal performance of Streaming Strategies, disable all Performance Visualizers (perhaps except the Trades tab). Processing them consumes resources (CPU, RAM) while adding nothing when you're not backtesting.

Because the secondary symbol is not streamed, Streaming Strategies are not recommended for intraday pairs trading without employing workarounds as follows:

Workaround #1: add a delay before setting context):

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);
	//...
}

Workaround #2: Fidelity customers can employ the Strategy Monitor which uses "Streaming bars". Generally, if the primary symbol bars are updated, secondary symbol bars in the same or lower timeframe will also be ready. To be sure, add a small delay (1000 msec) as in the solution above.

Workaround #3: stream the secondary symbol in another Strategy Window that writes its last bar's data (or Bars object) to global memory, where the pairs strategy will pick it up. Example:

/* 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); } } }

In the pairs trading script, access the secondary symbol's Bar object from global memory. The routine makes sure that the secondary data is available before continuing, waiting at most 5 seconds if there is no secondary symbol update.
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 = Date[Bars.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.Date[xBars.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... } } }