FXSS.CPP
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:4k
- #include <windows.h>
- #include <string.h>
- #include "fx.h"
- FX_DATAS FxDatas;
- extern HINSTANCE ghInstance;
- int DrawFx(HWND hWnd, HDC hDC, LPFX lpFx)
- {
- FARPROC lpFxDraw;
-
- switch(lpFx->type)
- {
- case FX_TYPE_MACD:
- lpFxDraw =MakeProcInstance(DrawMacd, ghInstance);
- break;
- case FX_TYPE_RSI:
- //lpFxDraw =&DrawRsi;
- break;
- case FX_TYPE_DMI:
- //lpFxDraw =&DrawDmi;
- break;
- case FX_TYPE_PSY:
- //lpFxDraw =&DrawPsy;
- break;
- case FX_TYPE_VR:
- //lpFxDraw =&DrawVr;
- break;
- case FX_TYPE_JLT:
- break;
- case FX_TYPE_K:
- break;
- case FX_TYPE_KD:
- break;
- }
- if(lpFxDraw ==NULL)
- return -1;
-
- (*lpFxDraw)(hWnd, hDC, lpFx);
-
- FreeProcInstance(lpFxDraw);
-
- return 0;
- }
- FAR PASCAL DrawMacd(HWND hWnd, HDC hDC, LPFX lpFx)
- {
- int i,k,nrec;
- float maxdif,mindif;
- int ma1, ma2;
- float fce, xs[2];
- HLOCAL hfp1,hfp2,hema1,hema2,hdif,hmacd;
- float *fp1,*fp2,*ema1,*ema2,*dif,*macd;
- float fplus1,fplus2;
- int j,np1,np2;
- char cb[20];
- RECT rc;
- int et;
- HPEN hPen[2];
- GetClientRect(hWnd, &rc);
-
- nrec =FxDatas.recCount;
- if(nrec <2*(lpFx->sets.ma[0]+1)+lpFx->sets.ma[1])
- return 0;
- ma1 =lpFx->sets.ma[0];
- ma2 =lpFx->sets.ma[1];
- xs[0]=2/(ma1+1);
- xs[1]=2/(ma2+1);
- hema1=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
- hema2=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
- hfp1=LocalAlloc(LHND,ma1*sizeof(float));
- hfp2=LocalAlloc(LHND,ma2*sizeof(float));
- ema1=(float*)LocalLock(hema1);
- ema2=(float*)LocalLock(hema2);
- fp1=(float*)LocalLock(hfp1);
- fp2=(float*)LocalLock(hfp2);
- for(i=0;i<ma2;i++)
- {
- if(i>=ma2-ma1)
- fp1[i-(ma2-ma1)]=FxDatas.lpData[i].spjg;
- fp2[i]=FxDatas.lpData[i].spjg;
- }
- fplus1=fplus2=0;
- for(i=0;i<ma1;i++)
- fplus1+=fp1[i];
- for(i=0;i<ma2;i++)
- fplus2+=fp2[i];
- ema1[0]=fplus1/ma1;
- ema2[0]=fplus2/ma2;
- np1=np2=0;
- k=1;
- for(i=ma2;i<nrec;i++)
- {
- fp1[np1]=FxDatas.lpData[i].spjg;
- fp2[np2]=FxDatas.lpData[i].spjg;
- fplus1=fplus2=0;
- for(j=0;j<ma1;j++)
- fplus1+=fp1[j];
- for(j=0;j<ma2;j++)
- fplus2+=fp2[j];
- ema1[k]=fplus1/ma1;
- ema2[k]=fplus2/ma2;
- np1=(np1+1)%ma1;
- np2=(np2+1)%ma2;
- k++;
- }
- LocalUnlock(hfp1);
- LocalUnlock(hfp2);
- LocalFree(hfp1);
- LocalFree(hfp2);
- hdif=LocalAlloc(LHND,(nrec-ma2+1)*sizeof(float));
- hmacd=LocalAlloc(LHND,(nrec-ma2-lpFx->sets.ma[1]+1)*sizeof(float));
- dif=(float*)LocalLock(hdif);
- macd=(float*)LocalLock(hmacd);
- for(i=0;i<nrec-ma2;i++)
- dif[i]=ema1[i]-ema2[i];
- fplus1=0;
- for(i=0;i<lpFx->sets.ma[1];i++)
- fplus1+=dif[i];
- macd[0]=fplus1/lpFx->sets.ma[1];
- k=1;
- for(;i<nrec-ma2;i++)
- {
- fplus1-=dif[i-lpFx->sets.ma[1]];
- fplus1+=dif[i];
- macd[k++]=fplus1/lpFx->sets.ma[1];
- }
- maxdif =mindif =dif[0];
- for(i=1;i<nrec-ma2;i++)
- {
- maxdif =(dif[i]>maxdif)?dif[i]:maxdif;
- mindif =(dif[i]<mindif)?dif[i]:mindif;
- }
- if(maxdif==mindif)
- fce=1;
- else
- fce=32767/(maxdif-mindif);
- SetMapMode(hDC,MM_ANISOTROPIC);
- //et=GetExchTalTime(GetWindowWord(hWnd,0));
- SetWindowExt(hDC,et,32767);
- SetViewportExt(hDC,480,-rc.bottom);
- SetViewportOrg(hDC, rc.left, rc.bottom);
- SetBkMode(hDC,TRANSPARENT);
- SetTextColor(hDC,RGB(0,200,62));
- wsprintf(cb,"%2d%2d%2d MACD",ma1,ma2,lpFx->sets.ma[1]);
- TextOut(hDC,et,32767,cb,strlen(cb));
- SetTextColor(hDC,RGB(255, 255, 0));
- TextOut(hDC,et,32767,cb,4);
- SetTextColor(hDC,RGB(0, 255, 255));
- TextOut(hDC,et,32767,cb,2);
- SetWindowOrg(hDC,-4,0);
- hPen[0]=CreatePen(PS_SOLID,1,RGB(0, 255, 255));
- hPen[1]=CreatePen(PS_DOT,1,RGB(255, 255, 0));
- SelectObject(hDC,hPen[0]);
- MoveTo(hDC,ma2,(int)((dif[0]-mindif)*fce));
- for(i=1;i<lpFx->sets.ma[1];i++)
- LineTo(hDC,i+ma2,(int)((dif[i]-mindif)*fce));
- for(;i<k;i++)
- {
- SelectObject(hDC,hPen[0]);
- MoveTo(hDC,i+ma2-1,(int)((dif[i-1]-mindif)*fce));
- LineTo(hDC,i+ma2,(int)((dif[i]-mindif)*fce));
- SelectObject(hDC,hPen[1]);
- MoveTo(hDC,i+ma2+lpFx->sets.ma[1]-1,
- (int)((macd[i-lpFx->sets.ma[1]-1]-mindif)*fce));
- LineTo(hDC,i+ma2+lpFx->sets.ma[1],
- (int)((macd[i-lpFx->sets.ma[1]]-mindif)*fce));
- }
- SelectObject(hDC,GetStockObject(WHITE_PEN));
- for(i=0;i<nrec-ma2-lpFx->sets.ma[1];i++)
- {
- MoveTo(hDC,i+ma2+lpFx->sets.ma[1],-(int)(mindif*fce));
- LineTo(hDC,i+ma2+lpFx->sets.ma[1],
- (int)((dif[i+lpFx->sets.ma[1]]-mindif)*fce));
- }
- SetBkMode(hDC,TRANSPARENT);
- SetTextAlign(hDC,TA_RIGHT|TA_TOP);
- SetTextColor(hDC,RGB(255, 255, 255));
- SetWindowOrg(hDC,0,0);
- MoveTo(hDC,0,-(int)(mindif*fce));
- LineTo(hDC,et,-(int)(mindif*fce));
- TextOut(hDC,0,-(int)(mindif*fce),"0",1);
- for(i=0;i<2;i++)
- if(hPen[i]!=NULL)
- DeleteObject(hPen[i]);
- LocalUnlock(hdif);
- LocalFree(hdif);
- LocalUnlock(hmacd);
- LocalFree(hmacd);
- return 1;
- }