// -------------------------------------------------------------------------------------
Free auto trading link:
http://tradingsw.blogspot.in/p/software.html
/* Global Options */
SetFormulaName("RLCO v011"); /*Name of script in backtest report */
SetOption("UseCustomBacktestProc", True ); // Use custom backtester for tiered position sizing
SetBarsRequired(100000,100000); /* ensures that the charts include all bars AND NOT just those on screen */
SetTradeDelays( 1, 0, 1, 0 ); /* DELAY one bar on entry, but not exits */
SetOption( "InitialEquity", 100000 ); /* starting capital */
//SetPositionSize( 350, spsPercentOfEquity ); // Not currently used
PositionSize = -100; /* trade size is set in the custom backtest section below. Leave at 100% (-100) here */
SetOption( "AccountMargin", 25); /* Day trading margin; 25% */
SetOption( "MaxOpenPositions", 1 ); /* Span on control = # of open positions allowed */
SetOption( "PriceBoundChecking", 1 ); /* trade only within the chart bar's price range */
SetOption( "CommissionMode", 2 ); /* set commissions AND costs as $ per trade */
SetOption( "CommissionAmount", 0.00 ); /* commissions AND cost */
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bar's equity for trade size*/
SetOption( "ActivateStopsImmediately", True); /* Allow immedate exit */
PositionScore = 100/C; /*Set priority order for trades when mulitple signals trigger on one bar */
// -----------------------------------------------------------------------------------------------------
/* Custom Backtest Code */
// -----------------------------------------------------------------------------------------------------
/* First we enable custom backtest procedure */
SetCustomBacktestProc("");
PctRiskPerTrade = 01; // Risk 1% of total equity per trade
/* Here's the custom backtest procedure */
if( Status("action") == actionPortfolio )
{
bo = GetBacktesterObject();
// --------------------------------------------------------------------
// Testing tiered position sizing starts here
// --------------------------------------------------------------------
bo.PreProcess();
for ( bar = 0; bar < BarCount; bar++ )
{
CurrentPortfolioEquity = bo.Equity;
for ( sig = bo.GetFirstSignal( bar ); sig; sig = bo.GetNextSignal( bar ) )
{
if ( CurrentPortfolioEquity > 125000 )
sig.PosSize = -300; //1st Tier
if ( CurrentPortfolioEquity <= 125000 AND CurrentPortfolioEquity > 100000 )
sig.PosSize = -200; // 2nd Tier
if ( CurrentPortfolioEquity <= 100000 AND CurrentPortfolioEquity > 75000 )
sig.PosSize = -100; // 3rd Tier
if ( CurrentPortfolioEquity <= 75000 )
sig.PosSize = -50; // 4th Tier
}
bo.ProcessTradeSignals( bar );
}
// --------------------------------------------------------------------
// End Test tiered position sizing
// --------------------------------------------------------------------
bo.Backtest(1); // run default backtest procedure
// Initialize a few variables used later.
SumProfitPerRisk =0;
NumTrades =0;
CumulativeR =0;
TotalR =0;
// Iterate through closed trades.
for( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{
// Risk is the maximum value we expect to lose on a trade
Risk = ( PctRiskPerTrade / 100 ) * trade.GetEntryValue();
RMultiple = trade.GetProfit()/Risk;
CumulativeR = RMultiple + CumulativeR;
// Show the initial risk and results in R on the backtest summary / trade log
trade.AddCustomMetric("Initial Risk $", Risk );
trade.AddCustomMetric("R-Multiple", RMultiple );
trade.AddCustomMetric("Cumulative R", CumulativeR );
SumProfitPerRisk = SumProfitPerRisk + RMultiple;
NumTrades++;
}
// expectancy = SumProfitPerRisk / NumTrades;
AverageR = CumulativeR / NumTrades;
// bo.AddCustomMetric( "Expectancy Per $ Risked", expectancy );
bo.AddCustomMetric( "Total R", CumulativeR );
bo.AddCustomMetric( "Average R", AverageR );
bo.ListTrades();
}