The following is a macd formula.
DIFF: EMA (close, short)-EMA (close, long );
DEA: EMA (diff, M );
Macd: 2 * (DIFF-DEA), colorstick;
Its variables can be directly added and subtracted * division, but we need to know that the close in it is actually an array type. We can see from the summary analysis. In C #, we can use Operator Overloading to add and subtract arrays or perform operations. But the array is the built-in type of the system. We cannot reload it with operators, so we need to construct a type ourselves.
In the qianfa stock automatic trading software, I created a floatlist type,
Public class floatlist: List <float>
{
Public floatlist ()
{}
Public floatlist (INT length): Base (length)
{}
Public floatlist (ienumerable <float> input)
: Base (input)
{}
Public static floatlist operator + (floatlist input, float m)
{
Floatlist list = new floatlist ();
For (INT I = 0; I <input. Count; I ++)
{
List. Add (input [I] + M );
}
Return list;
}
... Other omissions
}
Because the data in the stock is actually float type.
In this way, you can reload operators on it.
Next, you need to implement a global function, which is implemented through the parent class. Other methods can be used for scripting.
In this way, you only need to let your class inherit the basefunctions class.
Let's look at an example.
Public class macdhelper: basefunctions
{
/// <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 L, int S, int m)
{
This. stocklogs = List;
VaR diff = EMA (close, S)-EMA (close, L );
VaR DEA = EMA (diff, M );
VaR macd = (diff-DEA) * 2;
Macdinfo info = new macdinfo ();
Info. DEA = DEA;
Info. Diff = diff;
Info. macd = macd;
Return Info;
}
}
If this is something that inspires you to charge your http://lanhaifeng.taobao.com/