logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Patrick  
#1 Posted : Wednesday, November 30, 2005 3:58:31 PM(UTC)
Patrick

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:
StorkBite  
#2 Posted : Wednesday, November 30, 2005 5:57:14 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Thanks P!
Users browsing this topic
Guest (Hidden)
Similar Topics
Custom Index Function - Take 2 (cont) ... (MetaStock Developer's Kit (MDK) Assistance)
by hayseed 9/14/2005 3:01:45 AM(UTC)
Custom Index Function (MetaStock Developer's Kit (MDK) Assistance)
by Patrick 9/8/2005 2:20:58 AM(UTC)
Continued interest in custom index function [RESOLVED] (Formula Assistance)
by cancerman 8/26/2005 2:43:26 AM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.