////////////////////////////////////////////////////
// Plugin.cpp
// Standard implementation file for all AmiBroker plug-ins
//
// Copyright (C)2001-2002 Tomasz Janeczko, amibroker.com
// All rights reserved.
//
// Last modified: 2002-03-11 TJ
//
// You may use this code in your own projects provided that:
//
// 1. You are registered user of AmiBroker
// 2. The software you write using it is for personal, noncommercial use only
//
// For commercial use you have to obtain a separate license from Amibroker.com
//
////////////////////////////////////////////////////
#include "stdafx.h"
#include "ASCIIWin32.h"
#include "Plugin.h"
#include "stdlib.h"
#include "stdio.h"
// These are the only two lines you need to change
#define PLUGIN_NAME "ASCII sample data Plug-in"
#define VENDOR_NAME "Amibroker.com"
#define PLUGIN_VERSION 10000
#define PLUGIN_ID PIDCODE( 'A', 'S', 'C', 'I' )
#define THIS_PLUGIN_TYPE PLUGIN_TYPE_DATA
////////////////////////////////////////
// Data section
////////////////////////////////////////
static struct PluginInfo oPluginInfo =
{
sizeof( struct PluginInfo ),
THIS_PLUGIN_TYPE,
PLUGIN_VERSION,
PLUGIN_ID,
PLUGIN_NAME,
VENDOR_NAME,
0,
387000
};
///////////////////////////////////////////////////////////
// Basic plug-in interface functions exported by DLL
///////////////////////////////////////////////////////////
PLUGINAPI int GetPluginInfo( struct PluginInfo *pInfo )
{
*pInfo = oPluginInfo;
return TRUE;
}
PLUGINAPI int Init(void)
{
return 1;
}
PLUGINAPI int Release(void)
{
return 1; // default implementation does nothing
}
PLUGINAPI int Notify(struct PluginNotification *pn)
{
// default implementation does nothing
return 1;
}
PLUGINAPI int GetQuotes( LPCTSTR pszTicker, int nPeriodicity, int nLastValid, int nSize, struct Quotation *pQuotes )
{
// needed because we will use MFC inside this function
//AFX_MANAGE_STATE( AfxGetStaticModuleState() );
// we assume that intraday data files are stored in ASCII subfolder
// of AmiBroker directory and they have name of <SYMBOL>.AQI
// and the format of Date(YYMMDD),Time(HHMM),Open,High,Low,Close,Volume
// and quotes are sorted in ascending order - oldest quote is on the top
char filename[ 256 ];
FILE *fh;
int iLines = 0;
// format path to the file (we are using relative path)
sprintf_s( filename, "ASCII\\%s.AQI", pszTicker );
// open file for reading
fh = fopen( filename, "r" );
// if file is successfully opened read it and fill quotation array
if( fh )
{
char line[ 256 ];
// read the line of text until the end of text
// but not more than array size provided by AmiBroker
while( fgets( line, sizeof( line ), fh ) && iLines < nSize )
{
// get array entry
struct Quotation *qt = &pQuotes[ iLines ];
// parse line contents: divide tokens separated by comma (strtok) and interpret values
// date and time first
int datenum = atoi( strtok( line, "," ) ); // YYMMDD
int timenum = atoi( strtok( NULL, "," ) ); // HHMM
qt->DateTime.PackDate.Tick = 0;
qt->DateTime.PackDate.Minute = timenum % 100;
qt->DateTime.PackDate.Hour = timenum / 100;
qt->DateTime.PackDate.Year = 100 + datenum / 10000;
qt->DateTime.PackDate.Month = ( datenum / 100 ) % 100;
qt->DateTime.PackDate.Day = datenum % 100;
// now OHLC price fields
qt->Open = (float) atof( strtok( NULL, "," ) );
qt->High = (float) atof( strtok( NULL, "," ) );
qt->Low = (float) atof( strtok( NULL, "," ) );
qt->Price = (float) atof( strtok( NULL, "," ) ); // close price
// ... and Volume
qt->Volume = atoi( strtok( NULL, ",\n" ) );
iLines++;
}
// close the file once we are done
fclose( fh );
}
// return number of lines read which is equal to
// number of quotes
return iLines;
}
PLUGINAPI int Configure( LPCTSTR pszPath, struct InfoSite *pSite )
{
// AFX_MANAGE_STATE is needed because dialog boxes call MFC and use resources
// similar line should be added to any other function exported by the plugin
// if only the function calls MFC or uses DLL resources
//AFX_MANAGE_STATE( AfxGetStaticModuleState() );
/*
** Here a config dialog may be called
CConfigDlg oDlg;
oDlg.DoModal();
**
*/
//AfxMessageBox("Configure button clicked");
return 1;
}
PLUGINAPI AmiVar GetExtraData( LPCTSTR pszTicker, LPCTSTR pszName, int nArraySize, int nPeriodicity, void* (*pfAlloc)(unsigned int nSize) )
{
// default implementation does nothing
AmiVar var;
var.type = VAR_NONE;
var.val = 0;
return var;
}
PLUGINAPI int SetTimeBase( int nTimeBase )
{
// only intraday intervals are supported
return ( nTimeBase < ( 24 * 60 * 60 ) ) ? 1 : 0;
}
Partager