- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
Using From and To dates from Auto Analysis in Code.afl
上传用户:shiqiang
上传日期:2009-06-12
资源大小:1289k
文件大小:2k
源码类别:
金融证券系统
开发平台:
Others
- //------------------------------------------------------------------------------
- //
- // Formula Name: Using From and To dates from Auto Analysis in Code
- // Author/Uploader: Bruce M. Moore
- // E-mail: bmoore8702@sbcglobal.net
- // Date/Time Added: 2005-06-06 22:40:53
- // Origin: Author
- // Keywords: Status, FirstBarInRange, LastBarInRange
- // Level: semi-advanced
- // Flags: exploration
- // Formula URL: http://www.amibroker.com/library/formula.php?id=466
- // Details URL: http://www.amibroker.com/library/detail.php?id=466
- //
- //------------------------------------------------------------------------------
- //
- // This code illustrates how to use the "From" and "To" date settings from
- // Automatic Analyzer in AFL code. It is far faster to do it this way than to
- // run your code from "0 to Barcount-1".
- //
- // This method of extracting the dates and converting them to bar counts is
- // rather convoluted, as you will see. I would like to see new keywords added
- // to the AFL that allow the programmer to access the the "From" and "To" bar
- // counts directly. In the meantime, this is the best work-around I've found.
- //
- // The simple example given calculates a moving average, then plots price and
- // the moving average.
- //
- // Feedback is always welcome.
- //
- //------------------------------------------------------------------------------
- Periods=40;
- x=BarIndex();
- xMA=tcnt=tsum=Null;
- xfirst = LastValue(ValueWhen(Status("FirstBarInRange"), x, 1));
- xlast = LastValue(ValueWhen(Status("LastBarInRange" ), x, 1));
- if(xfirst>Periods){
- for (i = xfirst; i < xlast + 1; i++){
- tcnt[i]=0;
- tsum[i]=0;
- for (j=0; j<Periods; j++){
- tcnt[i]++;
- tsum[i]= tsum[i] + Close[i-j];
- }
- xMA[i]=tsum[i]/tcnt[i];
- }
- Title= "xFirst= " + WriteVal(xFirst,1.0) + ", xLast= " + WriteVal(xLast,1.0);
- Plot(Close,"Close",colorBlack,styleLine+styleThick);
- Plot(xMA,"xMA",colorRed,styleLine+styleThick);
- PlotShapes( IIf( xfirst==x, shapeCircle, shapeNone ), colorIndigo );
- PlotShapes( IIf( xlast==x, shapeCircle, shapeNone ), colorIndigo );
- Buy=Cross(C,xMA);
- Sell=Cross(xMA,C);
- Buy = ExRem(Buy, Sell);
- Sell = ExRem(Sell, Buy);
- PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen );
- PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed );
- Filter= C>10;
- AddColumn(Close, "Close" , 1.2);
- AddColumn(Volume, "Volume" , 1.0);
- }