In your calculation of TradeRisk, how are the variables EntryPrice and ExitPrice calculated?
Regards, GP --- In [email protected], "justinwonono" <[EMAIL PROTECTED]> wrote: > > // ===== > > > Hi GP, > Thanks for your time & interest. > I managed to sort out the date problem, but as the trace results show > , for some reason, I can't pick up the composite risk value even > though data is definitely there. > > Even if i just loop through without the date matching selection, no > data shows in the trace. > > Any ideas? > > Regards > > justinwonono > > ======= > .... > AddToComposite(TradeRisk, "~trisk" + Name(),"C",atcFlagDefaults | > atcFlagEnableInBacktest ); > ..... > > > SetCustomBacktestProc(""); > > > 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 > > for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) > > { > > // risk is calculated as the maximum value we can loose per trade > > > 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]); > > // 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"); > > } > > ======= > [3536] Custom BT Start > [3536] Symbol = BHP : dt[1] = 13/02/2004 : TRisk[1] = {EMPTY} > [3536] Trade.EntryDateTime = 13/02/2004 Risk = {EMPTY} > [3536] Symbol = SGB : dt[3] = 17/02/2004 : TRisk[3] = {EMPTY} > [3536] Trade.EntryDateTime = 17/02/2004 Risk = {EMPTY} > ======= > > > > -- In [email protected], "gp_sydney" <gp.investment@> wrote: > > > > > Risk = ValueWhen((Foreign("~trisk_" + trade.Symbol, dt )== > > > Trade.EntryDateTime), Foreign("~trisk_" + trade.Symbol,"C")) ; > > > > In this statement, the: > > > > Foreign("~trisk_" + trade.Symbol, dt) > > > > part is incorrect. The second parameter to Foreign is supposed to be > > the array type ("C", "O", etc) but you have the DateTime array. > > > > Regards, > > GP > > > > >
