[Reprint] Tongda letter Plug-in stock (based on the Access letter plug-in programming code simple Analysis)

Source: Internet
Author: User

[Reprint] Tongda letter Plug-in stock (based on the Access letter plug-in programming code simple Analysis) Original Address:Access letter Plug-in stock selection (based on the Access letter plug-in programming code simple Analysis) Harbin Cat Cat

First of all, I am a programmer, not a shareholder. There is little understanding of the concept of stock selection. This paper is only used by programmers for reference. The theory of stock selection is not discussed and explained.

I used to have a client. Access to the letter plug-in selection of small tasks, when the first contact interface-oriented (such "interface") programming, but also the first exposure to the relevant concepts in the stock. Recently, due to take over a task, similar to the last development, so the past, carefully studied. Share the knowledge of individual learning studies with others. Search the relevant information on the Internet, there are few useful and valuable. It is hoped that this article can give a little help to the programmer who will study the plug-in selection of Tongda letter.

Programming Environment: Viusal Studio 2010

Securities Terminal: GF Securities Xeon Version v6.06

First, let's talk about the method of debugging the DLL under VS2010:

1, the debug directory under the DLL (for example: MyPlugin.dll) files copied to the plugin folder under the Access root directory, this step can be manual, but since it is the development program, it is sure to debug n times, will output n DLL files, we can write a post-generation event in VS, for example: copy "C:documents and Settingsadministrator Desktop Choice2Debugchoice2.dll" D: Tongda letter Pluginchoice2.dll. This step is set up as.

2, set the directory where the additional process is located, such as.

With these settings, we can debug our DLL and monitor the value of the variable. After the successful compilation, set breakpoints, start debugging, and then operate the access letter for stock selection, the stock start will jump to the VS debugging interface.

Second, the access letter to provide the official plug-in stock selection example analysis. (can be downloaded online)
interface in the document, has clearly written out the interface function of the relevant instructions. But some of the concepts are still vague, so let me explain what I understand.

1, there are several export functions that must be understood enough:

Registerdatainterface registers a callback function, which is pdataiofunc, which is used to request historical data

Getcopyrightinfo fill in the plugin information function, very easy

InputInfoThenCalc1 Call this function by default, using all local history data

INPUTINFOTHENCALC2 Call this function to select a stock when specifying a date segment

2, the content must be clear enough:

The M_PFN (code,nsetcode,datatype,phisdat,ndatanum,tmptime,tmptime,ntq,0) function in the sample program, where the very important parameter is Datatype,phisdat, Ndatanum. That is, the data type you want to apply, the data storage buffer (memory), the maximum number of data you want to get (which is probably not so much), the return value of this function is the number of data actually fetched.

InputInfoThenCalc1 (char * code,short nsetcode,int value[4],short datatype,short ndatanum,byte ntq,unsigned long Unused) In the following tutorial, take all the local historical data as an example, that is, the stock option calls this function

INPUTINFOTHENCALC2 (char * code,short nsetcode,int value[4],short datatype,ntime time1,ntime time2,byte ntq,unsigned Long unused)

Through the next breakpoint monitoring, get the conclusion: 1. Plug-in selection process, for each stock call once InputInfoThenCalc1 function, if the return value is true, indicating that the stock is selected, and vice versa, is not selected. 2. Plug-in stock selection supports up to four parameters, four parameter values, in the plug-in code with VALUE[4] to store. 3. When I use daily data to obtain data, Ndatanum is assigned a value of 2000, the maximum number of data, basically enough for us to write a simple stock selection program.

Iii. selection of stock examples with higher than specified value

BOOL InputInfoThenCalc1 (char * code,short nsetcode,int value[4],short datatype,short ndatanum,byte ntq,unsigned Long Unused)//based on recent data
{
BOOL nret = FALSE;
Ntime Tmptime;
memset (&tmptime,0,sizeof (ntime)); Time structure set to 0 to get all local historical data

Lpreportdat preport = new Reportdat;
if (M_PFN (code,nsetcode,report_dat,preport,1,tmptime,tmptime,0,0) = = 1)
{
if (Preport->close > 0.001 && (100* (preport->now-preport->close)/preport->close) > Value[0] )
Nret = TRUE;
}
Delete Preport;
return nret;
}

Special note: When calculating the gain, to use the market data, so the data type is specified as Report_dat, the maximum number of returned data is specified as 1, because we only use the current data is enough. The calculation formula of the increase, Baidu a bunch of piles. Relatively speaking, this is the simplest. It's easy to understand.

Iv. selection of stocks with a turnover rate within the specified range

BOOL InputInfoThenCalc1 (char * code,short nsetcode,int value[4],short datatype,short ndatanum,byte ntq,unsigned Long Unused)//based on recent data
{
BOOL nret = FALSE;
Ntime Tmptime;
memset (&tmptime,0,sizeof (ntime));
Lpreportdat preport = new Reportdat;
Long Readnum = M_PFN (code,nsetcode,report_dat,preport,1,tmptime,tmptime,0,0);
Lpstockinfo pstockinfo = new Stockinfo;
Long readnum1 = M_PFN (code,nsetcode,stkinfo_dat,pstockinfo,1,tmptime,tmptime,0,0);
float Huanshou = (preport->volume/pstockinfo->activecapital) * 10000;

if (Huanshou > value[0] && Huanshou < value[1])
{
Nret = TRUE;
}
Delete Preportdat;
Delete Pstockinfo;
Delete Preport;
return nret;
}

Turnover rate = Volume /Total number of shares in a certain period of time x100% (in China: volume/circulation Total number of shares x100%) (quoted Baidu Encyclopedia)

Calculate according to the formula above, then calculate the scale of enlargement or reduction according to the decimal position we need. As in the previous example, we must pay attention to the data type that we want to specify. Calculate turnover rate, need volume and total shares of two data, volume using the current value, so we get a current, data type is specified as Report_dat market data; Total shares I don't know what data type it is, and after trying to change the data type again and again, Finally, an exact value is given, at which point the data type is specified as Stkinfo_dat. (sometimes we can try it one at a time, if we don't know it very well, if we want to know what the right result is.) One way is to record the value of the data displayed on the interface of the Tongda letter.

Originally intended to calculate the amount of data in the way, but also specify a range of stock selection. After trying to find the interface of the Tongda letter seems to have problems. To get the volume, you can only use the market data to get the current volume, unable to get historical volume. Check Data: Volume ratio = current deal total hand /〖 (average volume per minute for the past 5 trading days) x Total open time (minutes). (from Baidu Encyclopedia) according to the above formula, we need to get to today for 6 consecutive days of turnover. So get the following code:

Lpreportdat Preportdat = new Reportdat[ndatanum];
Long readnum2 = M_PFN (code,nsetcode,datatype,preportdat,ndatanum,tmptime,tmptime,0,0);
FLOAT * volpoint= New float[readnum2];
for (int i=0;i < readnum2;i++)
{
Volpoint[i]=preportdat[i]. Volume;
}
float Volperday = volpoint[readnum2-2]+volpoint[readnum2-3]+volpoint[readnum2-4]+volpoint[readnum2-5]+volpoint[ READNUM2-6];
float LIANGBI = volpoint[readnum2-1]/(VOLPERDAY/5);

After careful analysis, you may find that the meaning of the code expression is not a reference to the formula given by the data. Yes, if we calculate by the formula, we should get the daily, every minute volume data, in order to calculate the minute average. In this case, we cannot use the daily data. You need to download the time-sharing chart data, calculated according to the standard formula, to ensure that you do not error. But here, I look at the calculation, the above code calculation method obtained by the data and the interface is shown on the ratio of the volume is consistent.

The emphasis points out: The above calculated amount of code, and does not work properly. Because the historical volume is not available, I have tried various data types. When I get historical volume, the value of the volume field is an inexplicable number. But more strangely, the values of the other fields are normal. Pondering a long time, went to the Tongda Letter website forum, found a post and I encountered the same problem. Post address http://tdx.com.cn/dispbbs.asp?boardid=15&Id=173264 After you have tried various combinations of structs and data types. I think there should be no problem with the above-calculated code. The results are as follows:


In this case, reluctantly use the market data to get the current volume, only to calculate the turnover rate.

V. Calculation of close EMA for stock selection

Select the stock function, referring to the official example program + Baidu EMA algorithm to obtain the following code

BOOL InputInfoThenCalc1 (char * code,short nsetcode,int value[4],short datatype,short ndatanum,byte ntq,unsigned Long Unused)//based on recent data
{
BOOL nret = FALSE;
Ntime tmptime={0};

Lphisdat Phisdat = new Hisdat[ndatanum]; Data buffers
Long Readnum = M_PFN (code,nsetcode,datatype,phisdat,ndatanum,tmptime,tmptime,ntq,0); Use the callback function to request data and return the resulting number of data

if (Readnum > Max (value[0],value[1]))
{
float *pma1 = new Float[readnum];
float *pma2 = new Float[readnum];
for (int i=0;i < readnum;i++)
{
Pma1[i] = Phisdat[i]. Close;
Pma2[i] = Phisdat[i]. Close;
}
float *emapoint1 = new float[readnum-value[0]+1];
float *emapoint2 = new float[readnum-value[1]+1];
memset (EmaPoint1, 0, readnum-value[0]+1);
memset (EmaPoint2, 0, readnum-value[1]+1);
Afxcalcema (PMA1, Readnum, value[0], EmaPoint1);
Afxcalcema (PMA2, Readnum, value[1], EmaPoint2);
if (Afxcross (EmaPoint1, readnum-value[0]+1, EmaPoint2, Readnum-value[1]+1, value[2]) = = 1)
{
Nret = TRUE;
}
delete []emapoint1; Emapoint1=null;
delete []emapoint2; Emapoint2=null;
delete []pma1;pma1=null;
delete []pma2;pma2=null;
}
delete []phisdat;phisdat=null;
return nret;
}
The EMA function that calculates close is implemented as follows

void Afxcalcema (float *pdata, int ndatanum, int ndays, float *emapoint)
{
int nsumofdays = 0;
int flag = 0;
int iCount = 0;
for (icount=ndays;icount>0;icount--)
{
Nsumofdays+=icount;
}
for (icount=ndays;icount>0;icount--)
{
float temp = (icount/(float) nsumofdays) *pdata[icount-1];
EMAPOINT[0] + = temp;
}
for (ICount = 1, flag = ndays; icount<ndatanum-ndays+1; icount++, flag++)
{
Emapoint[icount] = (2*pdata[flag]+ (nDays-1) *emapoint[icount-1])/(ndays+1);
}
}

Calculates whether the short line crosses the line from below within the range specified

int Afxcross (float *pmapoint1, int DataNum1, float *pmapoint2, int DataNum2, int ndaysnum)
{
int flag1 = datanum1-1;
int flag2 = datanum2-1;
if (Pmapoint1[flag1] > Pmapoint2[flag2])
{
flag1--;
flag2--;
for (int iCount = ndaysnum; icount>0; icount--)
{
if (Pmapoint1[flag1] < PMAPOINT2[FLAG2])
{
return 1;
Break
}
Else
{
flag1--;
flag2--;
}
}
}
Else
{
return 0;
}
}

This example is relatively complex, but the complexity of the area is the algorithm part, not the program technology, mainly in the knowledge of mathematics. You have a good stock selection concept, in some cases, you can use the Access letter plug-in method to achieve the choice of shares.

Concluding remarks: With this article, I dedicate to my friends who intend to study, are studying and have studied the selection of the Access letter plugin. This is just the tip of the iceberg in programming. Hopefully we can all be a good developer and write high-quality programs. As a debut, we have a lot of criticism.

[Reprint] Tongda letter Plug-in stock (based on the Access letter plug-in programming code simple Analysis)

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.