Hi all,
I have the following AFL to plot equity lines and running Exploration/Scan/Backtest based on visible bars.
I can clearly see there are buy & sell signal on the chart with changing equity value. on the chart.
However, Scan and Backtest won't produce any results.
Is it possible to do Scan Backtest based on visible bars? Appreciate any advice on this.
Thanks.
BuyPrice = Close;
SellPrice = Close;
function ParamOptimize( pname, defaultval, minv, maxv, step )
{
return Optimize( pname,
Param( pname, defaultval, minv, maxv, step ),
minv, maxv, step );
}
_SECTION_BEGIN( "FastEMA" );
FastEMA = ParamOptimize( "FastEMA", 1, 1, 200, 5 );
Plot( ema( C, FastEMA ), _DEFAULT_NAME(), colorGreen );
_SECTION_END();
_SECTION_BEGIN( "SlowEMA" );
SlowEMA = ParamOptimize( "SlowEMA", 21, 1, 200, 10 );
Plot( ema( C, SlowEMA ), _DEFAULT_NAME(), colorBlue );
_SECTION_END();
Buy = Cross( ema( C, FastEMA ), ema( C, SlowEMA ) );
//Sell rule: EMA
Sell = Cross( ema( C, SlowEMA ), ema( C, FastEMA ) ) ;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
SetChartOptions( 0, chartShowArrows | chartShowDates );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( Close, "Close", colorDefault, styleCandle );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );
//Compute Equity Curve
_SECTION_BEGIN( "Equity Curve" );
bi = Barindex();
fvb = FirstVisiblevalue( bi );
lvb = LastVisiblevalue( bi );
fromIndex = Nz(fvb);
toIndex = Nz(lvb);
dateNumArray = DateNum();
fromDate = dateNumArray[fromIndex];
toDate = dateNumArray[toIndex];
e = Equity( 1, 3, fromDate, toDate );
Plot( e, "Equity", colorGrey40, styleLeftAxisScale | ParamStyle( "Equity Curve", defaultstyle = styleDashed | styleThick ) );
_SECTION_END();