Hi Howard,
In regards to your code below (thank you for sharing this). Do I run my normal system to produce the equity curve, then run your code below?
OR do I add normal Buy and Sell signals to your code below and then backtest the lot?
I think maybe the first one as you wrote "This code shows one example of applying trading system logic to the equity curve created by another trading system. If this is the case then I guess walk forward wouldn't be able to be done with this idea as it wouldn't work during the walk forward optimisations?
In regards to your code below (thank you for sharing this). Do I run my normal system to produce the equity curve, then run your code below?
OR do I add normal Buy and Sell signals to your code below and then backtest the lot?
I think maybe the first one as you wrote "This code shows one example of applying trading system logic to the equity curve created by another trading system. If this is the case then I guess walk forward wouldn't be able to be done with this idea as it wouldn't work during the walk forward optimisations?
Code:
///////////////////////////////////////////
// EquityCurveFeedback.afl
//
// There are many ways to use the equity
// in the trading account, and its variation,
// to act as a filter to allow or block trades.
//
// This code shows one example of applying
// trading system logic to the equity curve
// created by another trading system.
//
// The first system is a simple moving
// average crossover -- it could be any system.
//
MALength1 = 14; //Optimize("MALength1",14,2,50,2);
MALength2 = 13; //Optimize("MALength2",13,1,51,2);
Buy = Cross(MA(C,MALength1),MA(C,MALength2));
Sell = BarsSince(Buy)>=5;
Buy = ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
e = Equity();
Plot(C,"C",colorBlack,styleCandle);
PlotShapes(Buy*shapeUpArrow+Sell*shapeDownArrow,
IIf(Buy,colorGreen,colorRed));
Plot(e,"equity",colorGreen,styleLine|styleLeftAxisScale,15000,18000);
// The equity curve is choppy.
// If there are positive serial correlations
// between daily equity values, then we expect
// up days to be followed generally by more up days,
// and down days by more down days.
// So we might try applying a trend following system
// to the equity curve.
// When the equity curve is above its moving average,
// the system is working, and we should take trades.
// When the equity curve is below its moving average,
// the system is out-of-sync, and we should block trades.
// EquityMALength is the lookback period for the equity
// curve moving average.
// We will set Pass to either 0 or 1.
// Pass==0 blocks trades, Pass==1 allows trades.
EquityMALength = Optimize("EquityMALength",12,1,20,1);
EquityMA = DEMA(e,EquityMALength);
Plot(EquityMA,"equityMA",colorBrightGreen,styleLine|styleLeftAxisScale,15000,18000);
Pass = IIf(e>=EquityMA,1,0);
Buy = Buy AND Pass;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
e1 = Equity();
Plot(e1,"FilteredEquity",colorBlue,styleLine|styleLeftAxisScale,15000,18000);
/////////////////////////
When using the equity curve as a filter, you are applying a trading system to a series. If the series has a tendency to trend, then a trend-following equity curve system will work. If the series has a tendency to be mean reverting, then a mean reversion equity curve system will work.
The equity curve technique can be applied to either the daily marked-to-market equity, as in this example, or to the curve resulting from treating each closed trade as a "bar."
The equity curve filter is usually set up to act as a filter to prevent entry when the system has not been performing well lately. That is, it allows or prohibits entry, as in this example.
If the equity curve is monitored daily (or even intra-day), it can act as an exit signal, causing an exit based on equity performance before the other exit signals in the code. Or, as in this example, it can just wait for the exit logic in the base code to cause the exit.
So --- there are several options to try. When you find something useful, please post it back to this forum.
Thanks,
Howard
www.quantitativetradingsystems.com