I want to add a custom column "StopLoss" in report. Some how I did not see it there. What was I doing wrong here? Here is my script:
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
// run default backtest procedure without generating the trade list
bo.Backtest( True );
// iterate through closed trades
for ( trade = bo.GetFirstTrade( ); trade; trade = bo.GetNextTrade( ) )
{
// read StopLine values and display as custom metric
symbolStopLine = StaticVarGet( trade.Symbol + "StopLine" );
trade.AddCustomMetric( "StopLoss", Lookup( symbolStopLine, trade.EntryDateTime ) );
}
// iterate through open positions
for ( trade = bo.GetFirstOpenPos( ); trade; trade = bo.GetNextOpenPos( ) )
{
// read StopLine values and display as custom metric
symbolStopLine = StaticVarGet( trade.Symbol + "StopLine" );
trade.AddCustomMetric( "StopLoss", Lookup( symbolStopLine, trade.EntryDateTime ) );
}
// generate trade list
bo.ListTrades( );
}
_SECTION_BEGIN("8/10MA Trending R10");
Filter =1; // show all bars//
Setoption("MaxOpenPositions",10000); // Set at 10000 for initial testing so all trades are included in performance report.
MovAvg1=MA(C,8);
MovAvg2=MA(C,10);
Buy = (C>MovAvg1 AND Ref(C,-1)>MovAvg1 AND Ref(C,-2)>MovAvg1) AND (C>MovAvg2 AND Ref(C,-1)>MovAvg2 AND Ref(C,-2)>MovAvg2) ;
Sell = (c<MovAvg1 AND Ref(C,-1)<MovAvg1 AND Ref(C,-2)<MovAvg1)AND (C<MovAvg2 AND Ref(C,-1)<MovAvg2 AND Ref(C,-2)<MovAvg2) AND Ref(cross(MA(C,10),MA(C,8)),-1)AND O<Ref(MA(C,10),-1);
AboveMA8=(C>MovAvg1 AND Ref(C,-1)>MovAvg1 AND Ref(C,-2)>MovAvg1);
AboveMA10=(C>MovAvg2 AND Ref(C,-1)>MovAvg2 AND Ref(C,-2)>MovAvg2);
DayCross=cross(MA(C,8),MA(C,10));
StopLength = 1*ATR(20);//make sure same ATR in RiskPerShare
ProfitLength = 3* ATR(20);
ApplyStop(stopTypeLoss, stopModePoint, stopLength, 1, False ); //initialstop loss fixed at trade entry date
Equity( 1, 0 ); // evaluate stops, all quotes
InTrade = Flip( Buy, Sell );//true when buy and false when sell
SetOption("EveryBarNullCheck", True );
StopLine = IIf( InTrade, Buy -StopLength, Null );//stopLoss
ProfitLine = IIf (InTrade, Buy+ProfitLength, Null);//Profit target
Buy = ExRem(Buy,Sell);
Sell = ExRem (Sell,Buy);
PlotShapes( shapeUpArrow*Buy, colorGreen,0, L, -20);
PlotShapes( shapeDownArrow*Sell, colorRed,0,H, -20) ;
_SECTION_END();```