C # RSI Algorithm Implementation

Source: Internet
Author: User

ThisAlgorithmUsed in gilstock, A WP7 individual stock trading software

Description of the flush algorithm:

LC: = REF (close, 1 );
RSI $ 1 : SMA (max (CLOSE-LC, 0 ), N1, 1 )/SMA (ABS (CLOSE-LC), N1, 1 )* 100 ;
RSI $ 2 : SMA (max (CLOSE-LC, 0 ), N2, 1 /SMA (ABS (CLOSE-LC), N2, 1 )* 100 ;
RSI $ 3 : SMA (max (CLOSE-LC, 0 ), N3, 1 )/SMA (ABS (CLOSE-LC), N3, 1 )* 100 ;
A: 20 ;
D: 80 ;

 

C # implementation. The data of R1, R2, and R3 listed in the theoretical interval and after N1, N2, and N3 are normal.

 

View code ///   <Summary>
/// RSI algorithm-consistent with huaxiun
///   </Summary>
///   <Param name = "N"> 6 </Param>
///   <Param name = "M1"> 12 </Param>
///   <Param name = "m2"> 24 </Param>
///   <Param name = "klstocklist"> K-line data </Param>
///   <Returns> </returns>
Public Static List <klinfo> computationrsi ( Int N1, Int N2, Int N3, list <klinfo> klstocklist)
{
For ( Int I = 0 ; I <klstocklist. Count; I ++)
{

Double Rsi1 = 0 ;
Double Ri2 = 0 ;
Double Rsi3 = 0 ;
If (Klstocklist [I]. KID = 1 )
{


Klstocklist [I]. rsi1 = 0 ;
Klstocklist [I]. rsi2. 0 ;
Klstocklist [I]. rsi3 = 0 ;
Klstocklist [I]. rsi1absema = 0 ;
Klstocklist [I]. rsi1absema = 0 ;
Klstocklist [I]. rsi2absema = 0 ;
Klstocklist [I]. rsi2absema =0 ;
Klstocklist [I]. rsi3absema = 0 ;
Klstocklist [I]. rsi3absema = 0 ;
}
Else
{
Double Rmax = math. Max ( 0 , Klstocklist [I]. closeprice-klstocklist [I- 1 ]. Closeprice );
Double Rabs = math. Abs (klstocklist [I]. closeprice-klstocklist [I- 1 ]. Closeprice );
Klstocklist [I]. rsi1maxema = (rmax + (N1- 1 ) * Klstocklist [I- 1 ]. Rsi1maxema)/N1;
Klstocklist [I]. rsi1absema = (rabs + (N1- 1 ) * Klstocklist [I- 1 ]. Rsi1absema)/N1;

klstocklist [I]. rsi2maxema = (rmax + (n2- 1 ) * klstocklist [I- 1 ]. rsi2maxema)/N2;
klstocklist [I]. rsi2absema = (rabs + (n2- 1 ) * klstocklist [I- 1 ]. rsi2absema)/N2;

klstocklist [I]. rsi3maxema = (rmax + (N3- 1 ) * klstocklist [I- 1 ]. rsi3maxema)/N3;
klstocklist [I]. rsi3absema = (rabs + (N3- 1 ) * klstocklist [I- 1 ]. rsi3absema)/N3;

If (klstocklist [I]. rsi1absema! = 0 ) rsi1 = (klstocklist [I]. rsi1maxema/klstocklist [I]. rsi1absema) * 100 ;
klstocklist [I]. rsi1 = rsi1;

If (klstocklist [I]. rsi2absema! = 0 ) ri2 = (klstocklist [I]. rsi2maxema/klstocklist [I]. rsi2absema) * 100 ;
klstocklist [I]. rsi2-rsi2;

If (klstocklist [I]. rsi3absema! = 0 ) rsi3 = (klstocklist [I]. rsi3maxema/klstocklist [I]. rsi3absema) * 100 ;
klstocklist [I]. rsi3 = rsi3;

}



}

ReturnKlstocklist;


}

WP7 effect:

Similar effect:

The last data is not correct because there is a time difference during the transaction time.

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.