MovingAverage
Just a retail hack
- Joined
- 23 January 2010
- Posts
- 1,315
- Reactions
- 2,565
@Trav. Thank you for the reply. Yes, I have downloaded the pdf document and reading it now.
@MovingAverage Thank you for your reply too. you were referring to "backtesting with a statistically relevant number of trades", i suppose you mean that it depends on the type of system and the rules. In that case, if the number of trades less than the relevant number or expected number then the sample period may not be sufficient. Am i interpretating it correctly?
That’s good. Also pay close attention to the section on out of sample testing@MovingAverage Thanks heaps. Found the book on amazon and downloaded in my kindle. This will be my reading for the next few weeks.
Something that I have been meaning to share was a tip about the Walk-Forward optimize process.
I didn't really understand this feature fully ( probably still don't ) except that it did a In Sample and Out Of Sample run to verify the system in a variety of market conditions....
the thing that I wanted to share ( this may have been obvious to you - but when learning to use AmiBroker it takes me a while to understand all the features mentioned in the first pass of reading something)......sorry back to reason for the post
How to tie the Walk-Forward process in with the Custom Back Test file.
Example below..
@Willzy provide some CBT code here https://www.aussiestockforums.com/posts/1076414/ in which he created a new metric for testing system performance against.
View attachment 106001
So when you go into the Analysis Settings you can select the optimization target which defaults to CAR/MDD as per below, but when you are being a little trickier and want to use some u beaut custom metric as @Willzy has put together then you can use it instead of the default.
View attachment 106000
Sounds pretty simple but when you use the drop down box your CBT target doesn't appear.....you have to type it in as per your program description..
so as per below we type in OBFN and when you run the Walk-Forward optimization it will use this target now.
View attachment 105999
View attachment 106002
Well that's it from me, maybe you will run a few tests against the standard CAR/MDD and the pearsonsR2 metric as per above ?? yes the fun never ends.
Enjoy
Trav
How do you deal with them??
Outlier Trades
Do you do the same or something different??
LookBackPeriod = Optimize("Look Back Period", 10, 5, 20, 1);
StochLevel = Optimize("Stoch Level", 50, 20, 80, 1);
SetForeign("$XAO.au");
StochIndex = StochD(LookBackPeriod);
IndexFilter = StochIndex >= StochLevel;
RestorePriceArrays();
BuyCond1 = IndexFilter;
Hi @Trav. I tried this code, and it got me trawling through the trade list to see what days the trades were executed on. Here is a couple of screenshotss.Just a quick test run below.
Same code used in the body of each system tested but I have included the following lines in the test system that we are trying to be a weekly system run on the analysis settings of Daily Periodicity
TimeFrameSet(inWeekly);
//*******CODE
TimeFrameRestore ();
TimeFrameExpand( C, inWeekly );
Results with trade delays set to 1
My assumption is that we want the buy trades to all be on a Monday - whereas exits can be on various days because our stops can be triggered midweek.
So I'm not sure I'm any closer, just thought I'd share findings.
SetOption("InitialEquity", 50000);
SetOption("MaxOpenPositions", 10);
SetTradeDelays(0, 0, 0, 0);
PositionSize = 10000;
DailyPeriod = 20; // number of averaging periods
DailyMA = MA(Close, DailyPeriod ); // simple moving average
SellDaily = Cross( DailyMA, Close );
WeeklyPeriod = 20; // number of averaging periods
WeeklyClose = TimeFrameCompress( Close, inWeekly );
WeeklyMA = MA( WeeklyClose, WeeklyPeriod ); // simple moving average
SellWeekly = Cross( WeeklyMA, Close );
BuyCond1 = dayofweek() == 1; // buy on Monday
BuyCond2 = Cross( Close, TimeFrameExpand(WeeklyMA, inWeekly) ); // buy when close crosses ABOVE WEEKLY moving average
Buy = BuyCond1 AND BuyCond2;
Sell = SellDaily; // sell when closes crosses BELOW DAILY moving average
buy = ExRem( buy, sell );
sell = ExRem( sell, buy );
// ****** CHARTING ****** //
Plot(Close, "Close", colorDefault, styleBar );
SetChartOptions(1, chartShowDates, chartGridMiddle, 0, 0, 0);
SetChartBkColor(colorBlack);
SetChartBkGradientFill((colorBlack),(colorBlack));
Plot( DailyMA, "Daily MA(20)", colorAqua, styleLine);
Plot(TimeFrameExpand(WeeklyMA, inWeekly), "Weekly MA(20)", colorOrange, styleLine);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeupArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, L, Offset=-60);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,L, Offset=-70);
PlotShapes(IIf(Sell, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-65);
// ****** EXPLORE ****** //
if( Status( "Action" ) == actionExplore );
Filter = Buy OR Sell ;
AddColumn(Buy, "Buy", 1, colorDefault, colorDefault, 50);
AddColumn(Sell, "Sell", 1, colorDefault, colorDefault, 50);
AddColumn(Close, "Close", 1.2, colorDefault, colorDefault, 50);
AddColumn(ROC( C, 1 ), "%", 1.2, colorDefault, colorDefault, 50);
AddColumn(DayOfWeek(), "Day 1 to 5", 1);
//=================================================================================
//6. Add a two-stage trailing stop ==> amend to looping stop
//=================================================================================
StopLevel = 1 -(ts/100);
trailARRAY = Null;
trailstop = 0;
TrailStopSell = 0; // added from @Trav code
for( i = 1; i < BarCount; i++ )
{
if( trailstop == 0 AND Buy[ i ] )
{
trailstop = High[ i ] * stoplevel [i]; // was "* stoplevel;"
}
else Buy[ i ] = 0; // remove excess buy signals
if( trailstop > 0 AND Close[ i ] < trailstop ) //was "Low"
{
TrailStopSell[ i ] = 1; // was "Sell[ i ] = 1;"
SellPrice[ i ] = trailstop;
trailstop = 0;
}
if( trailstop > 0 AND TrailStopSell [i] == 0) //was " if( trailstop > 0 )"
{
trailstop = Max( High[ i ] * stoplevel [i], trailstop );
trailARRAY[ i ] = trailstop;
}
}
Sell = TrailStopSell OR C < MA( C, 50 ) AND NoStrength AND NoUpTrend; // Sell when the close is less than the moving average of the last 50 Days with the closing price is less than the Simple Moving Average of the last 12 Days or Sell when uptrend ended or RSI cross
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?