How can I transplant the market software indicators to the qianfa stock automatic trading software?

Source: Internet
Author: User

Can I move the indicators of traditional market software?
Yes, and moving here is also very easy. Our stock Auto Trading software already provides some basic functions.

So far, the functions provided by our stock Auto Trading software include:

  1. Ma average
  2. Ema moving average
  3. WMA weighted average
  4. SMA moving average
  5. Maximum HHV price in a period
  6. Minimum price of llv in a period
  7. Cross traversal.

Like EMA, it is defined as Y = [2 * x + (N-1) * y']/(n + 1) y' is the calculated value of the previous cycle. Such a function is a recursive function that constantly calls the values of the previous cycle for calculation. We did not use recursion to speed up the computation.
The EMA implemented by our software is like this.
Public static list <float> EMA (This list <float> input, int N)
{
Float [] list = new float [input. Count];
List [0] = input [0];

Float X;
Float y;
Float ylast;
For (INT I = 1; I <input. Count; I ++)
{
Ylast = list [I-1];
X = input [I];

Y = (x * 2 + (n-1) * ylast)/(n + 1 );
List [I] = y;
}
Return list. tolist ();
}

We directly return a return value with the same number of digits based on the original value. In this way, the software can be easily judged. The final value does not meet the conditions.

Now let's take a look at how to writeMacd Functions

DIFF: EMA (close, short)-EMA (close, long); DEA: EMA (diff, M );
Macd: 2 * (DIFF-DEA), colorstick; above is a function of macd in great wisdom. Let's take a look at the code in our software. I first defined a macdinfo class.

Public class macdinfo
{
Public list <float> diff
{Get; set;} public list <float> DEA
{Get; set;} public list <float> macd
{Get; set ;}
}
We have defined the three above diff DEA macd. Let's take a look at the implementation of the computing class.

Public class macd
{
/// <Summary>
/// DIFF: EMA (close, short)-EMA (close, long );
/// DEA: EMA (diff, M );
/// Macd: 2 * (DIFF-DEA), colorstick;
/// </Summary>
/// <Param name = "list"> </param>
/// <Param name = "? "> </Param>
/// <Returns> </returns>
Public macdinfo calculate (list <stocklog> list, int S, int L, int m)
{
VaR closelist = List. Select (IT => it. Close). tolist (); // obtain all close values first.
VaR shortlist = closelist. ema (s); // calculates the short-term moving average.
VaR longlist = closelist. ema (l); // calculates the long moving average list <float> diff = new list <float> ();
For (INT I = 0; I <shortlist. Count; I ++) // calculate the diff of each cycle using the cyclic method
{
Diff. Add (shortlist [I]-longlist [I]);
} Var DEA = diff. ema (m); // calculate the DEA Based on Diff
List <float> macd = new list <float> ();
For (INT I = 0; I <diff. Count; I ++) // calculate the macd
{
Macd. Add (2 * (diff [I]-DEA [I]);
}
Macdinfo info = new macdinfo ();
Info. DEA = DEA;
Info. Diff = diff;
Info. macd = macd; return Info;
}
} /// Stocklog is our stock K-line record class
Public class stocklog
{
Public String stockcode
{Get; set;} public datetime date
{Get; set;} public float open
{Get; set;} public float low
{Get; set;} public float close
{Get; set;} public float high
{Get; set;} // not supported by Sina
// Public decimal amount
// {Get; set;} public float volume
{Get; set;} public stocklog clone ()
{
Return this. memberwiseclone () as stocklog;
} Public String tocharttip ()
{
Return string. format ("high: {0} \ r \ n low: {1} \ r \ n open: {2} \ r \ n accept: {3} \ r \ n Date: {4} ", high. tostring ("F3"), low. tostring ("F3"), open. tostring ("F3"), close. tostring ("F3"), date. toshortdatestring ());
}
} Then we have completedMacd metricsIf you turn this indicator into a tradable strategy. We will continue to introduce this feature in the future.

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.