Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
Here is the code ...
[code:1:3c0a328cb5]BOOL __stdcall CustomIndex (const MSXDataRec *a_psDataRec, const MSXDataInfoRecArgsArray *a_psDataInfoArgs, const MSXNumericArgsArray *a_psNumericArgs, const MSXStringArgsArray *a_psStringArgs, const MSXCustomArgsArray *a_psCustomArgs, MSXResultRec *a_psResultRec) { BOOL l_bRtrn = MSX_SUCCESS; //Standard Declarations int iErr = 0; int MsflStatus = 0; // 300 was Already Started, 900 was not Started and we initialized it. int MaxRecords = a_psDataRec->sClose.iLastValid; int LastSec = 0; int SecCount = 0; int PickedArray = a_psCustomArgs->iCustomIDs[0]; int PickedMethod = a_psCustomArgs->iCustomIDs[1]; //Let's check the status of the MSFL. //This will become handy when quickly testing the dll in MetaStcok and MSXTest. //There is no more need to adjust the code. iErr = MSFL1_GetMSFLState(); if (iErr == MSFL_STATE_INITIALIZED){MsflStatus = 300;} else if (iErr == MSFL_STATE_UNINITIALIZED){MsflStatus = 900; iErr = MSFL1_Initialize( "ForumDll", "Patrick Nouvion", MSFL_DLL_INTERFACE_VERSION );} //Declare MSFL related crap after the initialisation or checking that the MSFL library was running HSECURITY hSecurity = 0; char cDirNumber = 0; WORD wRecNum = 0; WORD wRecCount = 0; MSFLSecurityInfo_struct SecInfo; SecInfo.dwTotalSize = sizeof (MSFLSecurityInfo_struct); MSFLPriceRecord_struct PriceRec; memset(&PriceRec, 0, sizeof(MSFLPriceRecord_struct) ); DateTime_struct psRecordDate; psRecordDate.lDate = a_psDataRec->psDate[1].lDate; //Lets set the data array iErr = MSFL1_OpenDirectory(a_psStringArgs->pszStrings[0], &cDirNumber, MSFL_DIR_NO_FLAGS); iErr = MSFL1_GetFirstSecurityInfo(cDirNumber, &SecInfo); if(iErr == MSFL_MSG_LAST_SECURITY_IN_DIR){ int i = 1; iErr = MSFL1_LockSecurity(SecInfo.hSecurity ,MSFL_LOCK_PREV_WRITE_LOCK); iErr = MSFL1_FindDataDate(SecInfo.hSecurity,&psRecordDate,&wRecNum,MSFL_FIND_CLOSEST_PREV); for(i = 1; i <= MaxRecords; i++) { iErr = MSFL1_ReadDataRec(SecInfo.hSecurity, &PriceRec); float IndexArray = 0; if(PickedArray == 0){IndexArray = PriceRec.fOpen;} else if(PickedArray == 1){IndexArray = PriceRec.fHigh;} else if(PickedArray == 2){IndexArray = PriceRec.fLow;} else if(PickedArray == 3){IndexArray = PriceRec.fClose;} else if(PickedArray == 4){IndexArray = PriceRec.fVolume;} a_psResultRec->psResultArray->pfValue[i] = IndexArray; } iErr = MSFL1_UnlockSecurity(SecInfo.hSecurity); }
else if(iErr == MSFL_NO_ERR){ int i = 1; iErr = MSFL1_LockSecurity(SecInfo.hSecurity ,MSFL_LOCK_PREV_WRITE_LOCK); iErr = MSFL1_FindDataDate(SecInfo.hSecurity,&psRecordDate,&wRecNum,MSFL_FIND_CLOSEST_PREV); for(i = 1; i <= MaxRecords; i++) { iErr = MSFL1_ReadDataRec(SecInfo.hSecurity, &PriceRec); float IndexArray = 0; if(PickedArray == 0){IndexArray = PriceRec.fOpen;} else if(PickedArray == 1){IndexArray = PriceRec.fHigh;} else if(PickedArray == 2){IndexArray = PriceRec.fLow;} else if(PickedArray == 3){IndexArray = PriceRec.fClose;} else if(PickedArray == 4){IndexArray = PriceRec.fVolume;} a_psResultRec->psResultArray->pfValue[i] = IndexArray; } iErr = MSFL1_UnlockSecurity(SecInfo.hSecurity); SecCount = 1; //Let's Start the WHILE loop while(LastSec == 0) { iErr = MSFL1_GetNextSecurityInfo(SecInfo.hSecurity , &SecInfo); if(iErr == MSFL_MSG_LAST_SECURITY_IN_DIR){LastSec = 1;} SecCount += 1; iErr = MSFL1_LockSecurity(SecInfo.hSecurity ,MSFL_LOCK_PREV_WRITE_LOCK); iErr = MSFL1_FindDataDate(SecInfo.hSecurity,&psRecordDate,&wRecNum,MSFL_FIND_CLOSEST_PREV); //Let's Start the FOR Loop :D int i = 1; for(i = 1; i <= MaxRecords; i++) { iErr = MSFL1_ReadDataRec(SecInfo.hSecurity, &PriceRec); float IndexArray = 0; if(PickedArray == 0){IndexArray = PriceRec.fOpen;} else if(PickedArray == 1){IndexArray = PriceRec.fHigh;} else if(PickedArray == 2){IndexArray = PriceRec.fLow;} else if(PickedArray == 3){IndexArray = PriceRec.fClose;} else if(PickedArray == 4){IndexArray = PriceRec.fVolume;} if(LastSec == 0){a_psResultRec->psResultArray->pfValue[i] += IndexArray;} else if(LastSec == 1){ if(PickedMethod == 0){a_psResultRec->psResultArray->pfValue[i] += IndexArray;} else if(PickedMethod == 1){a_psResultRec->psResultArray->pfValue[i] += IndexArray; a_psResultRec->psResultArray->pfValue[i] = (a_psResultRec->psResultArray->pfValue[i]/SecCount);} } } iErr = MSFL1_UnlockSecurity(SecInfo.hSecurity); } } iErr = MSFL1_CloseDirectory(cDirNumber); //Let's finish our MSFL status check here if(MsflStatus == 900){iErr = MSFL1_Shutdown();} return l_bRtrn; }[/code:1:3c0a328cb5]
Patrick :mrgreen:
|