IHost
Namespace: WealthLab.Core
Parent:

The IHost interface is used to communicate various aspects of the WL7 environment to WL7 itself, the WL.com web site, and to extensions. You can always get the current instance of the IHost interface by accessing WLHost.Instance.

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

This method is called from WL7 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 WL7 status bar with an indicator of the specified color. The item is also available for examination in the WL7 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, WL7 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, Color 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 WL7 log viewer.


AppFolder
string AppFolder

Returns the folder where WL7 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 7 is installed in: " + WLHost.Instance.AppFolder);
		}

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

		}

	}
}

ConfigureParameters
string ConfigureParameters(ref ParameterList pl, string title)

Call this method to show a configuration dialog window the user can use to configure the specified parameters. If the user changed the parameters, the method returns a string that represents the persisted value of the ParameterList passed in the pl parameter, and additionally changes the value in the pl parameter itself to update the ParameterList in-place. If the user does not change the parameters, the method returns null.


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

Copies the specified file from the specified source folder to the specified destination folder. If alwaysOverwrite is true, will overwrite a file if it already exists in the destination folder.


DataFolder
string AppFolder

Returns the WL7 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)
		{
		}


	}
}

ExpertMode
public bool ExpertMode

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

Remarks

  • Toggle Expert Mode in the File Menu > Expert Mode
  • In Expert Mode, WL7 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, GetHistoryControlBlock 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 GetHistoryControlBlock instance, which can be null. If passed, it contains additional parameter for 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, GetHistoryControlBlock 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 GetHistoryControlBlock instance, which can be null. If passed, it contains additional parameter for 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, bool filterPrePost)

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. If you want to filter intraday requests so pre/post market partial bars are not returned, pass true in the filterPrePost parameter.


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)
		{

		}

	}
}

Settings
SettingsManager Settings

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


WLBuildNumber
int WLBuildNumber

Returns the WL7 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)
		{

		}

	}
}