function MyCBTColumns() {
/// example to user question being asked here
/// @link How can I write my own "Cum profit" in CBT?
global bo;
sumprofit = 0; // initialize cum. profit
// Iterating through closed trades
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) {
profit = trade.GetProfit(); // get P/L of closed trade
sumprofit += profit; // sum up P/L
}
// Iterating through open trades
for (trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos()) {
profit = trade.GetProfit(); // get P/L of open trade
sumprofit += profit; // sum up P/L
}
return sumprofit;
}
if ( Status( “action” ) == actionPortfolio ) {
bo = GetBacktesterObject(); // Retrieving the interface to portfolio backtester
bo.Backtest( 1 ); // Set to 1 to turn off automatic calling of trade list so per-trade variables can be added
MyCBTColumns();// My column(s) output function
bo.ListTrades(); // calling the trade list procedure after adding the variables wanted
}
RiskPorContrato = 2 * ATR(20);
PositionRiskEquity = Optimize (“PositionRiskEquity”, 0.012, 1, 100, 1);
PositionRiskLucro = Optimize (“PositionRiskLucro”, 0.008, 1, 100, 1);
PctSize = (PositionRiskEquity100000 + (PositionRiskLucrosumprofit))/( RiskPorContrato * PointValue);
SetPositionSize( PctSize, spsShares );
I need to use the variable sumprofit to determine o PctSize.
Any suggestion? Very grateful…