[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: email / IM signals



PureBytes Links

Trading Reference Links

Pete,

Two years ago I have experimented with the ELS code that follows:

	- $_AutoOrderRobot_Exp (Signal),
	- $_Filename (Function), and
	- $_DateToStr_YYYYMMDD (Function)

Perhaps this can help answer a few questions about trading signal
generation in TS2k and writing them to excel and VB readable *.csv
files.

enjoy
Charles


{ *******************************************************************

	Status			:	EXPERIMENTAL

	Study			: 	Automatic Order Robot Export Signal
						$_AutoOrderRobot_Exp (Signal)

						This signal has to be included in addition to
					 	the entry and exit signals of your strategy.
						The order data is appended with "FileAppend"
						to a *.csv file that can be read by a VB 6.0
						program.
						The latter can be fired as an event by your
						strategy after the order data has been appended
						by this signal.
						The VB 6.0 program posts the order of the last
						line of the *.csv file to the InteractiveBrokers
						TWS API.

 	Created:		:	September 19, 2002

	Modified:		:	September 19, 2002

	Provided By		: 	Ch. Amlinger

 *******************************************************************}

Inputs:
{***************************************************************************
************************}
			{ AutoOrderRobot process input fields:}
			Cond_AutoOrderRobot(1),		{ 1 = active, 0= Not active. Conditional switch
for the AutoOrderRobot process. }
			Cond_ExitOnly(0),			{ 1 = active, 0= Not active. Conditional emergency
switch to exit all trades.  }
			StartingDate(0),			{ Starting Date for the AutoOrderrobot process. }
			StartingTime(0), 			{ Starting Time for the AutoOrderrobot process. }
			Path("C:\orders\"),			{ The path for the file output }
			Account("S12345"),			{ Account this indicator is being used for }
			Exchange("SMART");

{***************************************************************************
************************}


Variables:
{***************************************************************************
************************}
			{Trading Record Fields:}
			OrderEvent(""),				{LE = Long Entry, LX = Long Exit, SE = Short Entry, SX
= Short Exit}
			TradPos(0),					{Long = 1, Flat = 0, Short = -1. Trade Positon in the
market.}
			Series(0),					{ At Market or Open Price of the current bar for executing
the trade }
			Strategy(""),				{ Strategy this indicator is being used for }
			{Account}
			TradeDate(0),				{the date the trade was triggered}
			TradeTime(0),				{the time the trade was triggered}
			{Method: placeOrder Method Description Fields:}
			placeOrderID(0),			{the order id}
			side(""),					{BUY, SELL, SSHORT}
			quantity(0),				{the order quantity}
			symbol(""),					{the symbol of the underlying asset}
			expiry(""),					{the expiration date. Use the format YYYMM}
			secType(""),				{ IB Codes: STK, OPT, FUT, FOP, CASH}
			strikep(0),					{the strike price}
			right(""),					{P, PUT, C, CALL}
			{exchange(""),}				{the order destination, such as BEST}
			curency(""),				{only required when secType = CASH}
			orderType(""),				{MKT, LMT, STP, STP_LMT, REL, VWAP}
			lmtPrice(0),				{the LIMIT price}
			auxPrice(0),				{the STOP price for stop-limit orders}
			{Event: orderStatus Event Fields:}
			orderStatusID(0),			{the order ID that was specified previously in the
call to placeOrder()}
			Status(""),					{the order status,, such as "submitted"}
			Filled(0),					{specifies the number of shares that have been executed}
			Remaining(0),				{specifies the number of shares still outstanding}
			Price(0),					{the average price of the shares that have been executed}

{***************************************************************************
************************}
			{other variable fields}
			AverageEntryPrice(0),		{for performace calculations trade by trade}
			TextDescription("");		{Actual Description of the Symbol}

{
Data Field Definitions for Excel Exports:

	IB Field:,		EasyLanguage Field:		Data Type:	Input Type:		Valid Values are:

	Trading Record Field:
	n/a,			OrderEvent(""),			String, 	Variyble,		LE = Long Entry, LX = Long
Exit, SSE = Short Entry, SX = Short Exit
	n/a,			TradePos											Long = 1, Flat = 0, Short = -1. Trade Positon in
the market.
	n/a,			Series,					float,		Input,			the price the trading strategy
triggered
	n/a,			Strategy,				String,		Input,			the trading strategy used
	account,		Account,				String,		Input,			the IB account used
	n/a,			TradeDate,							Variable,		the date the trade was triggered
	n/a,			TradeTime,							Variable,		the time the trade was triggered

	Method: placeOrder Method Description Fields:
	Id,				placeOrderID,			Long,		Variable,		the order id
	side,			side,					String,		Variable,		BUY, SELL, SSHORT
	quantity,		quantity,				Long,		Variable,		the order quantity
	symbol,			symbol,					String,		Variable,		the symbol of the underlying
asset
	secType,		secType,				String,		Variable,		STK, OPT, FUT, FOP, CASH
	expiry,			expiry,					String,		Variable,		the expiration date. Use the
format YYYMM
	strike,			strikep,				float,		Variable,		the strike price
	right,			right,					String,		Variable,		P, PUT, C, CALL
	exchange,		exchange,				String,		Variable,		the order destination, such as
BEST
	curency,		curency,				String,		Variable,		only required when secType = CASH
	orderType		orderType,				String,		Variable,		MKT, LMT, STP, STP_LMT, REL,
VWAP
	lmtprice,		lmtPrice,				float,		Variable,		the LIMIT price
	auxPrice,		auxPrice,				float,		Variable,		the STOP price for stop-limit
orders

	Event: orderStatus Event Fields:
	Id,				orderStatusID,			long,		Variable,		the order ID that was specified
previously in the call to placeOrder()
	status,			Status,					String,		Variable,		the order status,, such as
"submitted"
	filled,			Filled,					long,		Variable,		specifies the number of shares that
have been executed
	remaining		Remaining,				long,		Variable,		specifies the number of shares
still outstanding
	price,			Price,					float,		Variable,		the average price of the shares that
have been executed

	{other variable fields}
	n/a,			AvgEntryPrice,
	n/a,			Description,
}

{ Get Trading Record Field Variables }
	{OrderEvent}
	TradPos			= MarketPosition;
	Series			= Close;
	Strategy 		= GetStrategyName;
	{Account}
	{Date}
	{Time}
	{ID}
	{side}
	quantity 		= CurrentContracts;
	symbol			= GetSymbolName;

{ Insert header row into output file }
IF	BarNumber = 1 THEN BEGIN
	FileDelete(	$_Filename( Path, Strategy, Account ));
	FileAppend(	$_Filename( Path, Strategy, Account ) ,
				"OrderEvent" + "," +
				"TradePos" + "," +
				"Series" + "," +
				"Strategy" + "," +
				"account" + "," +
				"Date" + "," +
				"Time" + "," +
				"ID" + "," +
				"side" + "," +
				"quantity" + "," +
				"symbol" + "," +
				"secType" + "," +
				"expiry" + "," +
				"strike" + "," +
				"right" + "," +
				"exchange" + "," +
				"curency" + "," +
				"orderType" + "," +
				"lmtPrice" + "," +
				"auxPrice" + "," +
				"OrderStatus" + "," +
				"Filled" + "," +
				"Remaining" + "," +
				"Price" + "," +
				"AvgEntryPrice" + "," +
				"Description" + NewLine);
END;

{ BEGIN: AutoOrderRobot process printing to file. }
IF	Cond_AutoOrderRobot = 1 THEN BEGIN

	{Reserved for use in OptionStation and RadarScreen }
	{ BEGIN: Category Definitions 				 GlobalServer:			 IB:  }
	IF	CATEGORY = 0 THEN secType = "FUT";		{ 0 = future 			 FUT  }
	IF	CATEGORY = 1 THEN secType = "FOP";		{ 1 = future option 	 FOP  }
	IF	CATEGORY = 2 THEN secType = "STK";		{ 2 = stock 			 STK  }
	IF	CATEGORY = 3 THEN secType = "OPT";		{ 3 = stock option 		 OPT  }
	IF	CATEGORY = 4 THEN secType = "n/a";		{ 4 = index 			 n/a  }
	IF	CATEGORY = 5 THEN secType = "OPT";		{ 5 = curency option 	 OPT  }
	IF	CATEGORY = 6 THEN secType = "n/a";		{ 6 = mutual funds 		 n/a  }
	IF	CATEGORY = 7 THEN secType = "n/a";		{ 7 = money market funds n/a  }
	IF	CATEGORY = 8 THEN secType = "OPT";		{ 8 = index options 	 OPT  }
	IF	CATEGORY = 9 THEN secType = "CASH";		{ 9 = cash 				 CASH }
	{ END: Category Definitions }

	strikep		= 0 {strike of option};

	TextDescription =	DESCRIPTION;	{Actual Description of the Symbol}

	{ BEGIN: Entry conditions }
		{ Long Entry LE: From Flat to Long }
		IF 	TradPos[0] =  1 AND TradPos[1] = 0 THEN BEGIN
			OrderEvent = "LE";
			{place}
			side = "BUY";
			orderType = "MKT";
			{0}
			FileAppend( $_Filename( Path, Strategy, Account ),

						{ Trading Record Fiels: }
						  OrderEvent + ","						{LE = Long Entry, LX = Long Exit, SE = Short
Entry, SX = Short Exit}
						+ NumToStr(TradPos, 0) + ","			{Trade Positon in the market. Possible
values: Long = 1, Flat = 0, Short = -1 }
						+ NumToStr(EntryPrice, 4) + ","			{Close of the actual bar }
						+ Strategy + ","						{Strategy this indicator is being used for }
						+ Account + ","							{Account this indicator is being used for }
						+ $_DateToStr_YYYYMMDD(Date) + ","		{the date the trade was triggered
in YYYYMMDD Format}
						{+ NumToStr( Date, 8 ) + "," 			{the date the trade was triggered in
MM/DD/YYYY Format}}
						+ NumToStr(Time, 0) + ","				{the time the trade was triggered}

						{ Method: placeOrder Method Description Fields: }
						+ NumToStr(placeOrderID, 0) + ","		{the order id}
						+ side + ","							{BUY, SELL, SSHORT}
						+ NumToStr(quantity, 0) + ","			{the order quantity}
						+ symbol + ","							{the symbol of the underlying asset}
						+ secType + ","							{STK, OPT, FUT, FOP, CASH}
						+ expiry + ","							{the expiration date. Use the format YYYMM}
						+ NumToStr(strikep, 4) + ","			{the strike price}
						+ right + ","							{P, PUT, C, CALL}
						+ exchange + ","						{the order destination, such as BEST}
						+ curency + ","							{only required when secType = CASH}
						+ orderType + ","						{MKT, LMT, STP, STP_LMT, REL, VWAP}
						+ NumToStr(lmtPrice, 4) + ","			{the LIMIT price}
						+ NumToStr(auxPrice, 4) + ","			{the STOP price for stop-limit orders}

						{Event: orderStatus Event Fields:}
						+ NumToStr(orderStatusID, 0) + ","		{the order ID that was specified
previously in the call to placeOrder()}
						+ Status + ","							{the order status,, such as "submitted"}
						+ NumToStr(Filled, 0) + ","				{specifies the number of shares that
have been executed}
						+ NumToStr(Remaining, 0) + ","			{specifies the number of shares still
outstanding}
						+ NumToStr(Price, 4) + ","				{the average price of the shares that
have been executed}

						{other variable fields}
						+ NumToStr(AverageEntryPrice, 4) + ","	{for performace calculations
trade by trade}
						+ TextDescription + NewLine);			{Actual Description of the Symbol}
						{new indicator}
		END;

		{ Short Entry SE: From Flat to Short }
		IF 	TradPos[0] = -1 AND TradPos[1] = 0 THEN BEGIN
			OrderEvent = "SE";
			{place}
			side = "SELL";
			orderType = "MKT";
			{0}
			FileAppend( $_Filename( Path, Strategy, Account ),

						{ Trading Record Fiels: }
						  OrderEvent + ","						{LE = Long Entry, LX = Long Exit, SE = Short
Entry, SX = Short Exit}
						+ NumToStr(TradPos, 0) + ","			{Trade Positon in the market. Possible
values: Long = 1, Flat = 0, Short = -1 }
						+ NumToStr(EntryPrice, 4) + ","			{Close of the actual bar }
						+ Strategy + ","						{Strategy this indicator is being used for }
						+ Account + ","							{Account this indicator is being used for }
						+ $_DateToStr_YYYYMMDD(Date) + ","		{the date the trade was triggered
in YYYYMMDD Format}
						{+ NumToStr( Date, 8 ) + "," 			{the date the trade was triggered in
MM/DD/YYYY Format} }
						+ NumToStr(Time, 0) + ","				{the time the trade was triggered}

						{ Method: placeOrder Method Description Fields: }
						+ NumToStr(placeOrderID, 0) + ","		{the order id}
						+ side + ","							{BUY, SELL, SSHORT}
						+ NumToStr(quantity, 0) + ","			{the order quantity}
						+ symbol + ","							{the symbol of the underlying asset}
						+ secType + ","							{STK, OPT, FUT, FOP, CASH}
						+ expiry + ","							{the expiration date. Use the format YYYMM}
						+ NumToStr(strikep, 4) + ","			{the strike price}
						+ right + ","							{P, PUT, C, CALL}
						+ exchange + ","						{the order destination, such as BEST}
						+ curency + ","							{only required when secType = CASH}
						+ orderType + ","						{MKT, LMT, STP, STP_LMT, REL, VWAP}
						+ NumToStr(lmtPrice, 4) + ","			{the LIMIT price}
						+ NumToStr(auxPrice, 4) + ","			{the STOP price for stop-limit orders}

						{Event: orderStatus Event Fields:}
						+ NumToStr(orderStatusID, 0) + ","		{the order ID that was specified
previously in the call to placeOrder()}
						+ Status + ","							{the order status,, such as "submitted"}
						+ NumToStr(Filled, 0) + ","				{specifies the number of shares that
have been executed}
						+ NumToStr(Remaining, 0) + ","			{specifies the number of shares still
outstanding}
						+ NumToStr(Price, 4) + ","				{the average price of the shares that
have been executed}

						{other variable fields}
						+ NumToStr(AverageEntryPrice, 4) + ","	{for performace calculations
trade by trade}
						+ TextDescription + NewLine);			{Actual Description of the Symbol}
						{new indicator}
		END;
	{ END: Entry conditions }

	{ BEGIN: Exit conditions }
		{ Long Exit LX: From Long to Flat }
		IF	TradPos[0] = 0 AND TradPos[1] =  1 THEN BEGIN
			OrderEvent = "LX";
			{place}
			side = "SELL";
{*}			quantity = quantity[1];
			orderType = "MKT";
			{0}
			FileAppend( $_Filename( Path, Strategy, Account ),

						{ Trading Record Fiels: }
						  OrderEvent + ","						{LE = Long Entry, LX = Long Exit, SE = Short
Entry, SX = Short Exit}
						+ NumToStr(TradPos, 0) + ","			{Trade Positon in the market. Possible
values: Long = 1, Flat = 0, Short = -1 }
						+ NumToStr(ExitPrice(1), 4) + ","		{ExitPrice of previous long
position }
						+ Strategy + ","						{Strategy this indicator is being used for }
						+ Account + ","							{Account this indicator is being used for }
						+ $_DateToStr_YYYYMMDD(Date) + ","		{the date the trade was triggered
in YYYYMMDD Format}
						{+ NumToStr( Date, 8 ) + "," 			{the date the trade was triggered in
MM/DD/YYYY Format} }
						+ NumToStr(Time, 0) + ","				{the time the trade was triggered}

						{ Method: placeOrder Method Description Fields: }
						+ NumToStr(placeOrderID, 0) + ","		{the order id}
						+ side + ","							{BUY, SELL, SSHORT}
						+ NumToStr(quantity, 0) + ","			{the order quantity}
						+ symbol + ","							{the symbol of the underlying asset}
						+ secType + ","							{STK, OPT, FUT, FOP, CASH}
						+ expiry + ","							{the expiration date. Use the format YYYMM}
						+ NumToStr(strikep, 4) + ","			{the strike price}
						+ right + ","							{P, PUT, C, CALL}
						+ exchange + ","						{the order destination, such as BEST}
						+ curency + ","							{only required when secType = CASH}
						+ orderType + ","						{MKT, LMT, STP, STP_LMT, REL, VWAP}
						+ NumToStr(lmtPrice, 4) + ","			{the LIMIT price}
						+ NumToStr(auxPrice, 4) + ","			{the STOP price for stop-limit orders}

						{Event: orderStatus Event Fields:}
						+ NumToStr(orderStatusID, 0) + ","		{the order ID that was specified
previously in the call to placeOrder()}
						+ Status + ","							{the order status,, such as "submitted"}
						+ NumToStr(Filled, 0) + ","				{specifies the number of shares that
have been executed}
						+ NumToStr(Remaining, 0) + ","			{specifies the number of shares still
outstanding}
						+ NumToStr(Price, 4) + ","				{the average price of the shares that
have been executed}

						{other variable fields}
						+ NumToStr(AverageEntryPrice, 4) + ","	{for performace calculations
trade by trade}
						+ TextDescription + NewLine);			{Actual Description of the Symbol}
						{new indicator}

		END;
		{ Short Exit SX: From Short to Flat }
		IF	TradPos[0] = 0 AND TradPos[1] = -1 THEN BEGIN
			OrderEvent = "SX";
			{place}
			side = "BUY";
{*}			quantity = quantity[1];
			orderType = "MKT";
			{0}
			FileAppend( $_Filename( Path, Strategy, Account ),

						{ Trading Record Fiels: }
						  OrderEvent + ","						{LE = Long Entry, LX = Long Exit, SE = Short
Entry, SX = Short Exit}
						+ NumToStr(TradPos, 0) + ","			{Trade Positon in the market. Possible
values: Long = 1, Flat = 0, Short = -1 }
						+ NumToStr(ExitPrice(1), 4) + ","		{ExitPrice of previous shrt
position }
						+ Strategy + ","						{Strategy this indicator is being used for }
						+ Account + ","							{Account this indicator is being used for }
						+ $_DateToStr_YYYYMMDD(Date) + ","		{the date the trade was triggered
in YYYYMMDD Format}
						{+ NumToStr( Date, 8 ) + "," 			{the date the trade was triggered in
MM/DD/YYYY Format} }
						+ NumToStr(Time, 0) + ","				{the time the trade was triggered}

						{ Method: placeOrder Method Description Fields: }
						+ NumToStr(placeOrderID, 0) + ","		{the order id}
						+ side + ","							{BUY, SELL, SSHORT}
						+ NumToStr(quantity, 0) + ","			{the order quantity}
						+ symbol + ","							{the symbol of the underlying asset}
						+ secType + ","							{STK, OPT, FUT, FOP, CASH}
						+ expiry + ","							{the expiration date. Use the format YYYMM}
						+ NumToStr(strikep, 4) + ","			{the strike price}
						+ right + ","							{P, PUT, C, CALL}
						+ exchange + ","						{the order destination, such as BEST}
						+ curency + ","							{only required when secType = CASH}
						+ orderType + ","						{MKT, LMT, STP, STP_LMT, REL, VWAP}
						+ NumToStr(lmtPrice, 4) + ","			{the LIMIT price}
						+ NumToStr(auxPrice, 4) + ","			{the STOP price for stop-limit orders}

						{Event: orderStatus Event Fields:}
						+ NumToStr(orderStatusID, 0) + ","		{the order ID that was specified
previously in the call to placeOrder()}
						+ Status + ","							{the order status,, such as "submitted"}
						+ NumToStr(Filled, 0) + ","				{specifies the number of shares that
have been executed}
						+ NumToStr(Remaining, 0) + ","			{specifies the number of shares still
outstanding}
						+ NumToStr(Price, 4) + ","				{the average price of the shares that
have been executed}

						{other variable fields}
						+ NumToStr(AverageEntryPrice, 4) + ","	{for performace calculations
trade by trade}
						+ TextDescription + NewLine);			{Actual Description of the Symbol}
						{new indicator}
		END;
	{ END: Exit conditions }

END;
{ END:  AutoOrderRobot process printing to file. }




{ *******************************************************************

	Status: 		: 	FINAL

	Study			: 	Filename Function
						$_Filename (Function)

						Generates file name for printing to
						file and strips some characters

	Created			: 	February 10, 2000

	Last Edit		: 	March 15, 2002

	Provided By		: 	Charles Amlinger

	Credits			:	This code is based on the published FileName
						function of William Brower.

********************************************************************}
{ Return Data Type: String }

Inputs:	Path(String), 			{ Path paramenter (format like "c:\temp\") }
		Strategy(String), 		{ Strategy paramenter }
		Account(String);		{ Account paramenter  }

Vars:	A_Len(0),
		A_Chr(0),		{Look for space in symbol name}
		A_GSN(" ");		{Get symbol name}

Array: StrVal[5](" ");

A_GSN		= GetSymbolName;
StrVal[1]	=	" ";
StrVal[2]	=	"/";
StrVal[3]	=	"*";
StrVal[4]	=	".";
StrVal[5]	=	"_";

For Value1 	= 1 to 5 begin
	A_Len	= StrLen(A_GSN);
	A_Chr	= InStr(A_GSN, StrVal[Value1]);
	If	Value1 < 5 then begin
		If A_Chr <> 0 then A_GSN = LeftStr(A_GSN, A_Chr-1) + RightStr(A_GSN,
A_Len-A_Chr);
  	End;
	If	Value1 = 5 and A_Chr <> 0 then A_GSN = LeftStr(A_GSN, A_Chr-1);
End;

A_GSN = LeftStr(A_GSN, 8);
$_Filename = Path + Strategy + "_" + Account + "_" + A_GSN + ".csv";




{ *******************************************************************

	Status			:	FINAL

	Study			: 	This Function returns an eigth character date
						string with a YYYYMMDD format
						$_DateToStr_YYYYMMDD (Function)

	Created			: 	November 5, 1997

	Last Edit		:	March 15, 2002

	Provided By		: 	Charles Amlinger

********************************************************************}
Inputs: DateSelect(Numeric);
Variables: YearPortion(""), StringMonth(""), StringDay("");

YearPortion = NumToStr(1900 + IntPortion(DateSelect * .0001), 0);
If DateSelect >= 1000000 Then
	StringMonth = MidStr(NumToStr(DateSelect, 0), 4, 2)
else
	StringMonth = MidStr(NumToStr(DateSelect, 0), 3, 2);
	StringDay = RightStr(NumToStr(DateSelect, 0), 2);

$_DateToStr_YYYYMMDD = YearPortion + StringMonth + StringDay;