Development example to http://www.google.com.hk/search? Newwindow = 1 & safe = strict & client = firefox-a & hs = Gzw & am

Source: Internet
Author: User
How to customize a stock trading policy? Our software allows users to customize transaction policies. In this article, we will teach you how to customize a stock trading policy. Download our example directly. Decompress the package to the D: \ Projects \ MACD2 \ directory. Use VS2010 to open D: \ Projects \ MACD2 \ MACD2.sln. We can see that the MACDTractic2.cs file is our MACD transaction policy file. It inherits from AbstractTrade type /// <summary> // all custom transaction policies must inherit from it /// </summary> public abstract class AbstractTrade {// <summary> /// Author /// </summary> public abstract string Author {get ;} /// <summary> /// Policy Description /// </summary> public abstract string Description {get ;} /// <summary> /// Name /// </summary> public abstract string Name {get ;} /// <summary> /// can I buy a specific policy? /// </summary> /// <param name =" Context "> </param> // <returns> </returns> public abstract TradeBuyInfo BuyCheck (TradeContext context ); /// <summary> /// whether the specific policy implementation can be sold /// </summary> /// <param name = "context"> </param> // /<returns> </returns> public abstract TradeSellInfo SellCheck (TradeContext context ); /// <summary> /// obtain the maximum number of purchased items /// </summary> /// <param name = "context"> </param> /// <returns> </returns> protected virtual int GetM AxAmount (TradeContext context, float buyPrice) {int amount = BuyAmount. calculate (context. stockAndFundInfo. fundInfo. availableMoney, buyPrice); return amount ;} /// <summary> /// get the purchased price /// add 1‰ to the current price /// </summary> /// <param name = "context"> </param> // <returns> </returns> protected virtual float GetBuyPrice (TradeContext context) {return context. currentPrice * (1 + 0.001f);} // <summary> // The sold price /// the current price minus 1‰ /// </summary> /// <param name = "context"> </param> /// <returns> </returns> protected virtual float GetSellPrice (TradeContext context) {return context. currentPrice * (1-0.001f );} /// <summary> /// obtain the number of shares that can be sold currently /// </summary> /// <param name = "context"> </param> /// <returns> </returns> protected virtual int GetAvailableAmount (TradeContext context) {ExistStock existStock = co Ntext. StockAndFundInfo. Stocks. FirstOrDefault (it => it. StockCode = context. StockCode); if (existStock! = Null & existStock. availableAmout> 0) {return (int) existStock. availableAmout;} return 0 ;} /// <summary> /// obtain the total quantity /// </summary> /// <param name = "context"> </param> /// <returns> </returns> protected virtual int GetAmount (TradeContext context) {ExistStock existStock = context. stockAndFundInfo. stocks. firstOrDefault (it => it. stockCode = context. stockCode); if (existStock! = Null & existStock. amount> 0) {return (int) existStock. amount;} return 0 ;} /// <summary> /// whether a stock can be sold /// </summary> /// <param name = "context"> </param> // <returns> </returns> protected virtual bool ishavestockto.pdf (TradeContext context) {ExistStock existStock = context. stockAndFundInfo. stocks. firstOrDefault (it => it. stockCode = context. stockCode); if (existStock! = Null & existStock. availableAmout> 0) {return true;} return false;} // <summary> // check whether the stock already exists (quantity is required) /// If yes, true is returned. No false is returned. /// </summary> /// <param name = "context"> </param> /// <returns> </ returns> protected virtual bool IsHaveTheStockAlready (TradeContext context) {return context. stockAndFundInfo. stocks. firstOrDefault (it => it. stockCode = context. stockCode & it. amount> 0 )! = Null;} public transport acttrade Clone () {return this. memberwiseClone () as AbstractTrade;} We need to implement the following methods: Author Description Name, the most important BuyCheck and SellCheck to determine whether to buy and sell. If you need to create a new policy, you just need to remember to add a new class and implement the AbstractTrade class. Note that there are 11th rows [Export (typeof (AbstractTrade)] through which we can tell our program that we have this interface. Only the attribute that is added to the class. Is the final result. In VS2010, where can I press the shortcut key F5 to enter the debugging status? The stock automatic trading software will be automatically opened, and the next breakpoint will go to line 27 of Description. In the auto-stock trading software, select the system setting policy and select "MACD 5-minute transaction DEMO". We can see that the breakpoint is automatically broken at 27 lines. During automatic transaction operation, you can set the breakpoint to the BuyCheck and SellCheck sides, so that you can easily view the incorrect data in your policy operation.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.