Search Framework:
IHost
Namespace: WealthLab.Core
Parent:

The IHost interface is used to communicate various aspects of the WL8 environment to Strategies and WL8 Extensions. You can always get the singleton instance of the IHost interface by accessing WLHost.Instance.

Members
AddLogItem
void AddLogItem(string senderName, string msg, WLColor color, Exception ex = null, object sender = null)

This method is called from WL8 and various extensions to report status updates or exceptions. The senderName parameter should be the name of the extension or component issuing the call. The specified message (msg) is displayed in the WL8 status bar with an indicator of the specified color. The item is also available for examination in the WL8 log viewer tool, along with the accompanying Exception instance (ex) if provided.

If you are an extension developer, you can pass the instance of your extension's class (your class derived from DataProviderBase, StreamingProviderBase, etc.), in the sender parameter. Currently, WL8 uses this value only if the sender is a StreamingProviderBase. In this case, the color is used to update the indicator light on any windows that use that provider for streaming.


AddLogItemOrders
void AddLogItemOrders(string senderName, string msg, WLColor color, Exception ex = null)

Call this method to display a broker-related message, which will appear in the Order Manager messages pane as well as the WL8 log viewer.


AppFolder
string AppFolder

Returns the folder where WL8 is installed.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			WriteToDebugLog("Wealth-Lab 8 is installed in: " + WLHost.Instance.AppFolder);
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

ConfigureItem
bool ConfigureItem(Configurable c)

Call this method to show a configuration dialog window for the specified object c that is a descendant of the Configurable class. If the user changes the configuration, the method returns true.


ConfigureParameters
bool ConfigureParameters(ParameterList pl, string title)

Call this method to show a configuration dialog window for the specified parameters in the ParameterList instance pl. If the user changes the parameters, the method returns true.


CopyFileToDataFolder
void CopyFileToDataFolder(string sourceSubDir, string destSubDir, string fileName, bool alwaysOverwrite)

Copies the file with the specified fileName to a location in the WL8 User Data Folder, and is primarily intended to be used by WL8 Extensions. The sourceSubDir specifies the name of a subdirectory under the primary WL8 installation folder. The destSubDir specifies the name of a subdirectory under the WL8 Data Folder. If alwaysOverwrite is true, will overwrite a file if it already exists in the destination folder.


DataFolder
string AppFolder

Returns the WL8 user data folder.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace WealthScript55
{
	public class MyStrategy : UserStrategyBase
	{
		public override void BacktestBegin()
		{
			//create a file with the names of the DataSets in the DataFolder
			string filepath = Path.Combine(WLHost.Instance.DataFolder, "MyDataSetsExample.txt");

			List<string> datasetnames = new List<String>();
			foreach (DataSet ds in WLHost.Instance.DataSets)
			{
				datasetnames.Add(ds.Name);
			}

			//save it to the file
			File.WriteAllLines(filepath, datasetnames);

			//Launch File Explorer: for this to work, open Tools > Assembly References and put checkmarks
			//next to 1. System.ComponentModel.Primitives, and, 2. System.Diagnostics.Process
			//System.Diagnostics.Process.Start("explorer.exe", WLHost.Instance.DataFolder);
		}

		//execute the strategy rules here, this is executed once for each bar in the backtest history
		public override void Execute(BarHistory bars, int idx)
		{
		}
	}
}

DataSets
List<DataSet> DataSets

Returns a list of DataSets (instances of the DataSet class) that are available.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void BacktestBegin()
		{
			//list the DataSets
			foreach (DataSet ds in WLHost.Instance.DataSets)
			{
				WriteToDebugLog(ds.Name);
			}
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

DisplayMessage
void DisplayMessage(string msg)

Call this method to display a message box to the user.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			string expertOrnovice = WLHost.Instance.ExpertMode ? "n expert" : " novice";
			WLHost.Instance.DisplayMessage("I am a" + expertOrnovice);
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

EventsSelected
List<string> EventsSelected

Returns a List of strings containing the names of the Event Data Items that were selected to be plotted.

Remarks

  • The Event Provider must be checked to actually enable plotting the selected event items.
Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace WealthScript55
{
	public class MyStrategy : UserStrategyBase
	{
		public override void BacktestBegin()
		{
			List<string> selectedEvents = new List<String>();
			foreach (string evnte in WLHost.Instance.EventsSelected)
			{
				WriteToDebugLog(evnte);
			}

		}

		//execute the strategy rules here, this is executed once for each bar in the backtest history
		public override void Execute(BarHistory bars, int idx)
		{
		}


	}
}

ExecutePlatformMethod
object ExecutePlatformMethod(string callerName, string methodName, object parameter)

Since the WealthLab.Core library is cross-platform, whenever possible, WL8 Extensions are delivered in two assemblies. The first assembly is platform-neutral and contains the core logic of the Extension. The second assembly is targeted to Windows/WPF, and contains user interface support. Core logic assemblies can call ExecutePlatformMethod to cause a platform-specific method to be executed, presumably one contained in the Windows/WPF companion assembly.

WL8 WPF supports this call by using a base class called ObjectEditorBase defined in the WealthLab.WPF library. You can derive a class from ObjectEditorBase and include it in your Windows/WPF assembly. Your derived class should be given a Name property matching the callerName parameter in the signature above. Override the ExecutePlatformMethod in ObjectEditorBase and match method by methodName, performing any processing required by the method and returning a result, which is passed to ExecutePlatformMethod as the return value.

With this architecture WL8's core logic assemblies can work with platform-specific companion assemblies for multiple environments.


ExpertMode
public bool ExpertMode

Returns true if WL8 has been configured to run in "Expert Mode" by the user.

Remarks

  • Toggle Expert Mode in the File Menu > Expert Mode
  • In Expert Mode, WL8 hides explanatory texts throughout the UI.
Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			string expertOrnovice = WLHost.Instance.ExpertMode ? "n expert" : " novice";
			WLHost.Instance.DisplayMessage("I am a" + expertOrnovice);
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

FindDataSet
DataSet FindDataSet(string name)

Searches for a DataSet with the specified name. Returns the DataSet instance, or null if not found.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript55
{
	public class MyStrategy : UserStrategyBase
	{
		public override void BacktestBegin()
		{
			DataSet ds = WLHost.Instance.FindDataSet("Nasdaq 100");
			foreach (string sym in ds.Symbols)
			{
				WriteToDebugLog(sym);
			}
		}

		//execute the strategy rules here, this is executed once for each bar in the backtest history
		public override void Execute(BarHistory bars, int idx)
		{
		}


	}
}

FindMarket
MarketDetails FindMarket(string symbol)

Returns a MarketDetails object representing the market that the specified symbol trades on.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			//get the market by symbol
			MarketDetails md = WLHost.Instance.FindMarket(bars.Symbol);
			WriteToDebugLog(string.Format("FindMarket for {0} is {1}.", bars.Symbol, md.Name));

			//get the market using bars (should be the same)
			WriteToDebugLog(string.Format("FindMarket for bars is {0}.", bars.Market.Name));
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

GetHistories
List<BarHistory> GetHistories(List<string> symbols, HistoryScale scale, DateTime start, DateTime end, int maxBars, DataRequestOptions hcb)

Returns historical data for the specified symbols and scale, using either the date range specified in startDate/endDate, or the maximum number of bars specified in maxBars. The cb parameter is a DataRequestOptions instance, which can be null. If passed, it contains additional settings pertaining to the request, such as a preferred DataSet to use, and whether to filter for pre/post market data.


GetHistory
BarHistory GetHistory(string symbol, HistoryScale **scale**, DateTime startDate, DateTime endDate, int maxBars, DataRequestOptions cb)

Returns historical data for the specified symbol and scale, using either the date range specified in startDate/endDate, or the maximum number of bars specified in maxBars. The cb parameter is a DataRequestOptions instance, which can be null. If passed, it contains additional settings pertaining to the request, such as a preferred DataSet to use, and whether to filter for pre/post market data.


GetPartialBar
BarData GetPartialBar(string symbol, HistoryScale scale, DataSet ds)

Returns a partial bar of data for the specified symbol and scale. If the ds parameter is non-null, the method will attempt to obtain the data using the specified DataSet first.


InjectSourceCodeCompilerReferences
void InjectSourceCodeCompilerReferences(UniqueList<string> asmRef)

The asmRef list should contain the assembly location names that will be injected into WL8's list of assembly references for purposes of dynamic source code compilation. Primarily intended for Extensions, so that WL8's compiler might reference any custom assemblies the Extension uses.


LocalUserName
string LocalUserName

Returns the name of the current user.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			WriteToDebugLog("Hello " + WLHost.Instance.LocalUserName + "!");
		}

		public override void Execute(BarHistory bars, int idx)
		{

		}

	}
}

OfflineMode
bool OfflineMode

Returns true if WL8 was configured to run in offline mode by the user.


Settings
SettingsManager Settings

Returns an instance of the SettingsManager class, which can read and write settings to the WL8 settings file.


ShowWaitStatus
void ShowWaitStatus(bool wait)

If wait is true, causes an hourglass cursor to appear, otherwise causes the normal arrow cursor to appear.


WLBuildNumber
int WLBuildNumber

Returns the WL8 build number currently running.

Example Code
using WealthLab.Backtest;
using System;
using WealthLab.Core;
using WealthLab.Indicators;
using System.Drawing;
using System.Collections.Generic;

namespace WealthScript123
{
	public class MyStrategy : UserStrategyBase
	{
		public override void Initialize(BarHistory bars)
		{
			WLHost.Instance.DisplayMessage("Running Build " + WLHost.Instance.WLBuildNumber);
		}

		public override void Execute(BarHistory bars, int idx)
		{
		}
	}
}