FXSS.CPP
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:4k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <string.h>
  3. #include "fx.h"
  4. FX_DATAS FxDatas;
  5. extern HINSTANCE ghInstance;
  6. int DrawFx(HWND hWnd, HDC hDC, LPFX lpFx)
  7. {
  8. FARPROC lpFxDraw;
  9. switch(lpFx->type)
  10. {
  11. case FX_TYPE_MACD:
  12. lpFxDraw =MakeProcInstance(DrawMacd, ghInstance);
  13. break;
  14. case FX_TYPE_RSI:
  15. //lpFxDraw =&DrawRsi;
  16. break;
  17. case FX_TYPE_DMI:
  18. //lpFxDraw =&DrawDmi;
  19. break;
  20. case FX_TYPE_PSY:
  21. //lpFxDraw =&DrawPsy;
  22. break;
  23. case FX_TYPE_VR:
  24. //lpFxDraw =&DrawVr;
  25. break;
  26. case FX_TYPE_JLT:
  27. break;
  28. case FX_TYPE_K:
  29. break;
  30. case FX_TYPE_KD:
  31. break;
  32. }
  33. if(lpFxDraw ==NULL)
  34. return -1;
  35. (*lpFxDraw)(hWnd, hDC, lpFx);
  36. FreeProcInstance(lpFxDraw);
  37. return 0;
  38. }
  39. FAR PASCAL DrawMacd(HWND hWnd, HDC hDC, LPFX lpFx)
  40. {
  41. int i,k,nrec;
  42. float maxdif,mindif;
  43. int ma1, ma2;
  44. float fce, xs[2];
  45. HLOCAL hfp1,hfp2,hema1,hema2,hdif,hmacd;
  46. float *fp1,*fp2,*ema1,*ema2,*dif,*macd;
  47. float fplus1,fplus2;
  48. int j,np1,np2;
  49. char cb[20];
  50. RECT rc;
  51. int et;
  52. HPEN hPen[2];
  53. GetClientRect(hWnd, &rc);
  54. nrec =FxDatas.recCount;
  55. if(nrec <2*(lpFx->sets.ma[0]+1)+lpFx->sets.ma[1])
  56. return 0;
  57. ma1 =lpFx->sets.ma[0];
  58. ma2 =lpFx->sets.ma[1];
  59. xs[0]=2/(ma1+1);
  60. xs[1]=2/(ma2+1);
  61. hema1=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
  62. hema2=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
  63. hfp1=LocalAlloc(LHND,ma1*sizeof(float));
  64. hfp2=LocalAlloc(LHND,ma2*sizeof(float));
  65. ema1=(float*)LocalLock(hema1);
  66. ema2=(float*)LocalLock(hema2);
  67. fp1=(float*)LocalLock(hfp1);
  68. fp2=(float*)LocalLock(hfp2);
  69. for(i=0;i<ma2;i++)
  70. {
  71. if(i>=ma2-ma1)
  72. fp1[i-(ma2-ma1)]=FxDatas.lpData[i].spjg;
  73. fp2[i]=FxDatas.lpData[i].spjg;
  74. }
  75. fplus1=fplus2=0;
  76. for(i=0;i<ma1;i++)
  77. fplus1+=fp1[i];
  78. for(i=0;i<ma2;i++)
  79. fplus2+=fp2[i];
  80. ema1[0]=fplus1/ma1;
  81. ema2[0]=fplus2/ma2;
  82. np1=np2=0;
  83. k=1;
  84. for(i=ma2;i<nrec;i++)
  85. {
  86. fp1[np1]=FxDatas.lpData[i].spjg;
  87. fp2[np2]=FxDatas.lpData[i].spjg;
  88. fplus1=fplus2=0;
  89. for(j=0;j<ma1;j++)
  90. fplus1+=fp1[j];
  91. for(j=0;j<ma2;j++)
  92. fplus2+=fp2[j];
  93. ema1[k]=fplus1/ma1;
  94. ema2[k]=fplus2/ma2;
  95. np1=(np1+1)%ma1;
  96. np2=(np2+1)%ma2;
  97. k++;
  98. }
  99. LocalUnlock(hfp1);
  100. LocalUnlock(hfp2);
  101. LocalFree(hfp1);
  102. LocalFree(hfp2);
  103. hdif=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
  104. hmacd=LocalAlloc(LHND,(nrec-ma2-lpFx->sets.ma[1]+1)*sizeof(float));
  105. dif=(float*)LocalLock(hdif);
  106. macd=(float*)LocalLock(hmacd);
  107. for(i=0;i<nrec-ma2;i++)
  108. dif[i]=ema1[i]-ema2[i];
  109. fplus1=0;
  110. for(i=0;i<lpFx->sets.ma[1];i++)
  111. fplus1+=dif[i];
  112. macd[0]=fplus1/lpFx->sets.ma[1];
  113. k=1;
  114. for(;i<nrec-ma2;i++)
  115. {
  116. fplus1-=dif[i-lpFx->sets.ma[1]];
  117. fplus1+=dif[i];
  118. macd[k++]=fplus1/lpFx->sets.ma[1];
  119. }
  120. maxdif =mindif =dif[0];
  121. for(i=1;i<nrec-ma2;i++)
  122. {
  123. maxdif =(dif[i]>maxdif)?dif[i]:maxdif;
  124. mindif =(dif[i]<mindif)?dif[i]:mindif;
  125. }
  126. if(maxdif==mindif)
  127. fce=1;
  128. else
  129. fce=32767/(maxdif-mindif);
  130. SetMapMode(hDC,MM_ANISOTROPIC);
  131. //et=GetExchTalTime(GetWindowWord(hWnd,0));
  132. SetWindowExt(hDC,et,32767);
  133. SetViewportExt(hDC,480,-rc.bottom);
  134. SetViewportOrg(hDC, rc.left, rc.bottom);
  135. SetBkMode(hDC,TRANSPARENT);
  136. SetTextColor(hDC,RGB(0,200,62));
  137. wsprintf(cb,"%2d%2d%2d MACD",ma1,ma2,lpFx->sets.ma[1]);
  138. TextOut(hDC,et,32767,cb,strlen(cb));
  139. SetTextColor(hDC,RGB(255, 255, 0));
  140. TextOut(hDC,et,32767,cb,4);
  141. SetTextColor(hDC,RGB(0, 255, 255));
  142. TextOut(hDC,et,32767,cb,2);
  143. SetWindowOrg(hDC,-4,0);
  144. hPen[0]=CreatePen(PS_SOLID,1,RGB(0, 255, 255));
  145. hPen[1]=CreatePen(PS_DOT,1,RGB(255, 255, 0));
  146. SelectObject(hDC,hPen[0]);
  147. MoveTo(hDC,ma2,(int)((dif[0]-mindif)*fce));
  148. for(i=1;i<lpFx->sets.ma[1];i++)
  149. LineTo(hDC,i+ma2,(int)((dif[i]-mindif)*fce));
  150. for(;i<k;i++)
  151. {
  152. SelectObject(hDC,hPen[0]);
  153. MoveTo(hDC,i+ma2-1,(int)((dif[i-1]-mindif)*fce));
  154. LineTo(hDC,i+ma2,(int)((dif[i]-mindif)*fce));
  155. SelectObject(hDC,hPen[1]);
  156. MoveTo(hDC,i+ma2+lpFx->sets.ma[1]-1,
  157. (int)((macd[i-lpFx->sets.ma[1]-1]-mindif)*fce));
  158. LineTo(hDC,i+ma2+lpFx->sets.ma[1],
  159. (int)((macd[i-lpFx->sets.ma[1]]-mindif)*fce));
  160. }
  161. SelectObject(hDC,GetStockObject(WHITE_PEN));
  162. for(i=0;i<nrec-ma2-lpFx->sets.ma[1];i++)
  163. {
  164. MoveTo(hDC,i+ma2+lpFx->sets.ma[1],-(int)(mindif*fce));
  165. LineTo(hDC,i+ma2+lpFx->sets.ma[1],
  166. (int)((dif[i+lpFx->sets.ma[1]]-mindif)*fce));
  167. }
  168. SetBkMode(hDC,TRANSPARENT);
  169. SetTextAlign(hDC,TA_RIGHT|TA_TOP);
  170. SetTextColor(hDC,RGB(255, 255, 255));
  171. SetWindowOrg(hDC,0,0);
  172. MoveTo(hDC,0,-(int)(mindif*fce));
  173. LineTo(hDC,et,-(int)(mindif*fce));
  174. TextOut(hDC,0,-(int)(mindif*fce),"0",1);
  175. for(i=0;i<2;i++)
  176. if(hPen[i]!=NULL)
  177. DeleteObject(hPen[i]);
  178. LocalUnlock(hdif);
  179. LocalFree(hdif);
  180. LocalUnlock(hmacd);
  181. LocalFree(hmacd);
  182. return 1;
  183. }