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:
- Ma average
- Ema moving average
- WMA weighted average
- SMA moving average
- Maximum HHV price in a period
- Minimum price of llv in a period
- 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.