|
本帖最後由 joshsmi 於 12-11-3 01:37 編輯
Could someone please translate forbbs last reply into English, please! Google translator is not the best. :-)
Besides that here I provide a more advanced code example to show backtest results in Exploration
- // --- code by joshsmi ---
- // dummy system
- Buy = Cross( MA( Close, 12 ) , MA( Close, 24 ) );
- Sell = Cross( MA( Close, 24 ) , MA( Close, 12 ) );
- Short = 0;
- Cover = 0;
- BuyPrice = SellPrice = O; // entry at next bar's open, see settradedelays below
- //ShortPrice = CoverPrice = O;
- // dummy system
- SetBacktestMode( backtestRegular );
- SetOption( "FuturesMode", True );
- SetOption( "InitialEquity", 100000 );
- SetPositionSize( 20, spsPercentOfEquity );
- SetTradeDelays( 1, 1, 1, 1 ); // check Equity( ... ) below
- if ( Status( "action" ) == actionExplore )
- {
- dt = DateTime();
- eq = Equity( 2 ); // Use "1" if SetTradeDelays( 0, 0, 0, 0 ). Use flag "2" if SetTradeDelays != 0. But flag 2 setting should be used carefully
- SellCov = Sell || Cover;
- entrydate = IIf( Sell, ValueWhen( Buy, dt ), IIf( Cover, ValueWhen( Short, dt ), Null ) );
- profit = IIf( Sell, ValueWhen( Sell, eq ) - ValueWhen( Buy, eq ), /*Short*/IIf( Cover, ValueWhen( Cover, eq ) - ValueWhen( Short, eq ), 0 ) );
- cumprof = Cum( profit );
- Diffsell = ( ValueWhen( Sell, SellPrice ) - ValueWhen( Buy, BuyPrice ) ) / TickSize;
- Diffcov = ( ValueWhen( Cover, CoverPrice ) - ValueWhen( Short, ShortPrice ) ) / TickSize;
- format = 1.4; // decimal places of Ticker
- width = 70; // column width
- Filter = SellCov;
- SetOption( "NoDefaultColumns", True );
- AddTextColumn( Name(),"Ticker", 1.0, 47, 23, width );
- AddColumn( IIf( Sell, 76, IIf( Cover, 83, 32) ), "Trade", formatChar, 47, IIf( Sell, 19, IIf( Cover, 24, 23 ) ) );
- AddColumn( entrydate, "Entry Date/Time", formatDateTime, 47, 23, 115 );
- AddColumn( dt, "Exit Date/Time", formatDateTime, 47, 23, 115 );
- AddColumn( IIf( Sell, ValueWhen( Buy, BuyPrice ), Null), "Buy@", format, 47, 19, width );
- AddColumn( IIf( Sell, SellPrice, Null ), "Sell@", format, 23, 25, width );
- AddColumn( IIf( Sell, Diffsell, Null ), "abs. Diff", 1.2, IIf( diffsell >= 0, 43, 32 ), 23, width );
- /*AddColumn( IIf( Cover, ValueWhen( Short, ShortPrice ), Null ), "Short@", format, 47, 24, width );
- AddColumn( IIf( Cover, CoverPrice, Null ), "Cover@", format, 23, 36, width );
- AddColumn( IIf( Cover, Diffcov, Null ), "abs. Diff", 1.2, IIf( diffcov >= 0, 43, 32 ), 23, width );*/
- AddColumn( IIf( SellCov, profit, Null ), "Profit", 1.2, IIf( profit >= 0, 43, 32 ), 23, width );
- AddColumn( IIf( SellCov, cumprof, Null ), "Cum. Profit", 1.2, IIf( cumprof >= 0, 43, 32 ), 23, width );
- AddColumn( IIf( SellCov, Eq, Null ), "Equity", 1.2, 47, 23, width );
- }
複製代碼 |
|