1. 首页
  2. 易语言 - EasyLanguage
  3. 根据日期限定分析技术的运行 Restricting access by date

根据日期限定分析技术的运行 Restricting access by date

本文描述如何实现让您的分析技术只针对某一特定时间段运行。 This page describes how to restrict studies so that they will only run for a particular period of time. To restrict your code fully you need to add this functionality and then see the Protecting EasyLanguage Code page.

Restricting your studies by date allows you to have trial periods, or to lease a system for a particular period of time.

The following code uses the bar date to decide if it will run or not. Even after expiry, this code will run on historic bars up to the expiry date. After this it won’t do anything.

Vars:	ExpiryDate(1071231);

If date <= ExpiryDate then Begin
           {all your code here}
end;

This code uses the last trade date to decide whether to run. TradeDate is a quote field that holds the date of the last trade for a particular symbol. If the symbol traded past the Expiry Date then the code will not run at all.

Vars:	ExpiryDate(1071231);

If ExpiryDate >= TradeDate then Begin
           {all your code here}
end;


This is another, more comprehensive example, that combines Customer Number (see Restricting access to a Customer Number, an expiry date, and an ‘x days before expiry’ warning.

The Customer Number is checked first, and if it isn’t valid a message is sent to the Print Log and a message displayed on screen. At that point, no more code is run.
If the Customer Number is valid, then the date is checked for expiry. If the product is expired then a message is sent to the Print Log and a message displayed on screen. And no more code is run.
If both the Customer Number and date are valid then a final check is made to see if we are within ‘WarningDays’ of the expiry. If this is the case then a message is send to the Print Log and a messaage displayed on screen. After this the main indicator/strategy code is run.

If the CustomerNumber variable is left at 0 then the customer number criteria is not checked (good for testing). It is OK to have a list of customer numbers because when you ‘protect’ the ELD (see Protecting EasyLanguage Code) all comments are stripped out.

Vars:	CustomerNumber(0),
	//CustomerNumber(562732),		// TradeStation Testing Number
	//CustomerNumber(123456),		// Joe Jacobs, 10 April 2006
	//CustomerNumber(987654),		// Steve Smith, 17 June 2006
	//CustomerNumber(456321),		// Terry Thomas, 1 January 2007
	ExpiryDate(1071231),
	WarningDays(5),

	TXID_InvalidCust(-1),
	TXID_NearExpiry(-1),
	TXID_Expired(-1),

	LBOC(False);



LBOC = LastBarOnChart;

//Check here to make sure we have a valid CustomerID
If ( CustomerID = CustomerNumber or CustomerNumber = 0 ) then Begin

	//Check to make sure the data hasn't expired
	If Date <= ExpiryDate then Begin


		//If we are within WarningDays of the expiry then display a message
		If LBOC and DateToJulian(ExpiryDate) - DateToJulian(date) <= WarningDays then Begin

			value1 = Text_Float(TXID_NearExpiry, 30, 50);

			Text_SetString(TXID_NearExpiry, "This product expires in " + NumToStr(DateToJulian(ExpiryDate) - DateToJulian(Date), 0) + " Days");

			Text_SetStyle(TXID_NearExpiry, 0, 0);

			Once Begin
				print ("This product expires in ", DateToJulian(ExpiryDate) - DateToJulian(date):0:0, " Days");
			end;
		end;

		{}
		{your complete indicator or strategy code here}
		{}

	end
	//past expiry date
	else Begin
		If LBOC then Begin
			Once Begin
				Print ("This product has now expired");
			end;

			value2 = Text_Float(TXID_Expired, 1, 50);

			Text_SetStyle(TXID_Expired, 1, 0);
		end;
	end;
end
//wrong customer number
else Begin
	If CurrentBar = 1 then Begin
		TXID_InvalidCust = Text_New(date, time, 0, "Invalid Customer Number");
	end;


	If LBOC then Begin
		Once Begin
			Print ("Invalid Customer Number");
		end;

		value2 = Text_Float(TXID_InvalidCust, 1, 50);

		Text_SetStyle(TXID_InvalidCust, 0, 0);
	end;
end;
更新于 2020年5月15日

这篇文章对您有帮助吗?

相关的话题

留言评论