PureBytes Links
Trading Reference Links
|
Not to interfere with you correspondence with GP, but I see in your
code that before the CBT-part you've defined
AddToComposite(TradeRisk, "~trisk" + Name(),"C",atcFlagDefaults
|atcFlagEnableInBacktest );
. . . but then you call it as:
TRisk = Foreign("~trisk_" + trade.Symbol,"C");// NOTE: with
underscore!, so that doesn't work
Personally, and FWIW, as I do not always want to clutter my Db with
numerous ATC's, I often prefer to use VarSet.
PS
--- In amibroker@xxxxxxxxxxxxxxx, "justinwonono" <justinwonono@xxx>
wrote:
>
> GP...Here's the simple BO test system i'm using, nothing flash, &
> backtest entry/exit prices work as expected.
>
> Regards
>
> =========
> SetTradeDelays( 0, 0, 0, 0 );
>
> SetOption("InitialEquity", 50000 );
> SetOption("MaxOpenPositions", 10 );
> SetOption("AllowPositionShrinking", False );
> SetOption("PriceBoundChecking", True );
> SetOption("UsePrevBarEquityForPosSizing", False );
> SetOption("AllowSameBarExit", True );
> SetOption("ActivateStopsImmediately", True );
> SetOption("CommissionMode", 2 ); // $ Amt
> SetOption("CommissionAmount", 20 ); //
> SetChartOptions(0,chartShowArrows|chartShowDates);
>
> CapitalRisk = 0.01;
>
> PlotStyle=Param( "PlotStyle", 3 , 1, 3, 1 );
> Pstyle = IIf(PlotStyle==1,1,IIf(PlotStyle==2,64,128) );
>
> Tick = IIf( L <= 0.10, 0.001, IIf(L > 0.50 , 0.01, 0.005));
>
> TriggerTicks = 1;
> BOTicks = TriggerTicks * tick;
>
> // Entry Trigger
>
> UpperChannel= HHV( High , 20 ) ;
>
> LowerChannel = LLV( Low , 20 ) ;
> ExitTriggerPrice = Ref(LowerChannel,-1) - BOTicks ;
>
> Buy = Cross( Ref(Close,-1) , Ref(UpperChannel, -2) ) ;
> Sell = Cross( Ref(LowerChannel,-2) , Ref(Close,-1) ) ;
>
>
> // Remove Consecutive Triggers
> Buy = ExRem(Buy, Sell);
> Sell = ExRem(Sell, Buy);
>
>
> TradeRisk = IIf(Buy, BuyPrice - ExitTriggerPrice ,0); // ie
exitprice
> = init stop
> TradeRiskPcnt = IIf(Buy, TradeRisk / BuyPrice ,0) ;
> Buy=IIf(Buy==1 AND TradeRiskPcnt > 0.10 , 0 , Buy); // ignore > 10%
> trade risk
>
>
> PositionSize = -(CapitalRisk *100) * BuyPrice/TradeRisk;
> Buy=IIf(Buy==1 AND PositionSize < -33 , 0 , Buy);
>
> AddToComposite(TradeRisk, "~trisk" + Name(),"C",atcFlagDefaults |
> atcFlagEnableInBacktest );
>
> Equity( 1 ); // evaluates trades and stops
>
>
> // Exploration Layout
> Filter = 1;
>
> AddColumn(O, "O", 1.4);
> AddColumn(H, "H", 1.4);
> AddColumn(L, "L", 1.4);
> AddColumn(C, "C", 1.4);
> AddColumn(V, "V", 1.0);
>
>
> // Std Tittle
> Title = WriteVal( DateTime(), formatDateTime ) + " " + Name() +
> "\n" + "O = " + WriteVal(O, 1.4) + " ; H = " + WriteVal(H, 1.4)
+ " ;
> L = " + WriteVal(L, 1.4) + " ; C = " + WriteVal(C, 1.4)
>
> ;
>
> Plot( C, "Close", colorBlack , Pstyle + styleThick );
>
> Plot( UpperChannel, "UpperChannel", colorBlue , styleLine );
> Plot( LowerChannel , "LowerChannel ", colorBlue , styleLine );
>
> PlotShapes(Buy*shapeUpArrow,colorGreen,0,Low);
> PlotShapes(Sell*shapeDownArrow,colorRed,0,High);
>
>
> // =====
>
>
> SetCustomBacktestProc("");
>
>
> /* ustom-backtest procedure follows */
>
> if( Status("action") == actionPortfolio )
> {
> _TRACE("Custom BT Start");
> bo = GetBacktesterObject();
> bo.Backtest(1); // run default backtest procedure
> SumProfitPerRisk = 0;
> NumTrades = 0;
>
> // iterate through closed trades first
>
> for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade
() )
> {
>
> //
>
> dt = DateTime();
> TradeRisk = 0;
> TradeDate = DateTime();
> Risk = 0;
> TRisk = Foreign("~trisk_" + trade.Symbol,"C");
>
> for( i = 1; i < BarCount; i++ )
> {
> if ( Trade.EntryDateTime == dt[i] )
> {
> // if (TRisk[i] > 0)
> // {
> TradeDate = dt[i];
> Risk = TRisk[i];
> _TRACE( "Symbol = " + trade.Symbol + " : dt[" + i + "] = " +
> NumToStr( TradeDate , formatDateTime ) + " : TRisk[" + i + "] = " +
> TRisk[i]);
> _TRACE( "Symbol = " + trade.Symbol + " : EntryPrice = " +
> trade.EntryPrice + " : ExitPrice = " + trade.ExitPrice );
>
> // break;
> // }
> }
> }
>
> _TRACE(" Trade.EntryDateTime = " + NumToStr( Trade.EntryDateTime,
> formatDateTime ) + " Risk = " + Risk );
>
> RMultiple = trade.GetProfit()/Risk ;
> trade.AddCustomMetric("Initial risk $", Risk);
> trade.AddCustomMetric("R-Multiple", RMultiple );
> SumProfitPerRisk = SumProfitPerRisk + RMultiple;
> NumTrades++;
> }
>
> expectancy3 = SumProfitPerRisk / NumTrades;
> bo.AddCustomMetric( "Expectancy (per risk)", expectancy3 );
> bo.ListTrades();
>
> _TRACE("Custom BT End");
> }
>
> ====
> [2668] Custom BT Start
> [2668] Symbol = BHP : dt[84] = 15/06/2000 : TRisk[84] = {EMPTY}
> [2668] Symbol = BHP : EntryPrice = 7.96475 : ExitPrice = 7.93425
> [2668] Trade.EntryDateTime = 15/06/2000 Risk = {EMPTY}
> [2668] Symbol = BHP : dt[132] = 22/08/2000 : TRisk[132] = {EMPTY}
> [2668] Symbol = BHP : EntryPrice = 8.44485 : ExitPrice = 8.04767
> =====
>
> ===========
>
> --- In amibroker@xxxxxxxxxxxxxxx, "gp_sydney" <gp.investment@>
wrote:
> >
> > In your calculation of TradeRisk, how are the variables
EntryPrice and
> > ExitPrice calculated?
> >
> > Regards,
> > GP
> >
>
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|