NF Swing Trading using Fractal AFL

vijkris

Learner and Follower
hi oldtrader ji,
in ur free time can u pls backtest this vwap strategy.
tf = 2min/5min/15min. I request u to decide the appropriate tf.
scrip = your wish
trading type = intraday/swing,

Code:
_SECTION_BEGIN("VWAP");

//#### Modified by Kelvinhnad ####
Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));

/* This statement don't make the VWap start at 09:00:00
    Fixed startBar = ValueWhen(TimeNum() == 090000, BarIndex()); */
StartBar = TimeNum()>=090000;

TodayVolume = Sum(V,Bars_so_far_today);

//-- Fixed the Divide-by-0  at array[0]
TodayVolume = IIf(TodayVolume==0, Null, TodayVolume);

//-- From Trash: Correction to better programming style
VWAP = Sum (C * V, Bars_so_far_today)/TodayVolume;


//-- Draw VWAP based on Start Time
Plot (IIf(startbar, VWAP, Null),"VWAP",colorLime, styleThick);

//-- Created a dashed line from 00:00 to 09:00
Plot (IIf(NOT startbar, VWAP, Null),"",colorGreen, styleDashed);

_SECTION_END();  


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( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

 _SECTION_BEGIN("ATP");

DayChange = Day() != Ref(Day(), -1);
AvgTradePrice = Null;
CurDayBars = 0;
CurDayCloseSum = 0;
 
for (i = 0; i < BarCount; i++)
{
if (DayChange[i])
{
CurDayCloseSum = C[i];
CurDayBars = 1;
}
else
{
CurDayCloseSum = CurDayCloseSum + C[i];
CurDayBars++;
}
AvgTradePrice[i] = CurDayCloseSum / CurDayBars;
}
Plot(AvgTradePrice, "AvgTradePrice",colorRed,styleThick);
ATP=AvgTradePrice;
 
_SECTION_END();

Buy  =Cover=Ref(L,-1)>Ref(VWAP,-1) AND Ref(L,-1)>Ref(AvgTradePrice,-1)AND H>Ref(H,-1);
Short=Sell=Ref(AvgTradePrice,-1)>Ref(H,-1) AND Ref(VWAP,-1)>Ref(H,-1)AND L<Ref(L,-1);


Buy=ExRem(Buy,Short) OR ExRem(Buy,Sell) ;
Short=ExRem(Short,Buy) OR ExRem(Short,Cover);
Sell=ExRem(Sell,Buy);
Cover=ExRem(Cover,Short);


PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-45);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-55); 
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-50); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=55);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=65); 
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-60);

_SECTION_BEGIN("ema");
Lk = EMA(Close,22);



GfxSetOverlayMode(0); 
GfxSelectFont("Tahoma", Status("pxheight")/36); 
GfxSetTextAlign( 6 );// center alignment 
GfxSetTextColor( colorLightGrey ); 
GfxSetBkMode(0); // transparent 
GfxTextOut( Name(), Status("pxwidth")/2, Status("pxheight")/15 );

cx=Param("cxposn",785,0,500,1);
cy=Param("cyposn",39,0,500,1);
GfxSetBkColor(ColorRGB(200,50,100));
GfxSelectFont( "tohomabold",24,30, False);
GfxSetTextColor( colorYellow);
GfxSetTextColor( ColorHSB( 100, 10, 400) );
GfxTextOut("LTP. "+C+" ", cx, cy );

_SECTION_END();
SetPositionSize(75,spsShares);
I got this result on my 1.5yr sample data , 7min tf.


PS: I m not good in backtesting. :p
thanks
 

oldtrader

Well-Known Member
hi oldtrader ji,
in ur free time can u pls backtest this vwap strategy.
tf = 2min/5min/15min. I request u to decide the appropriate tf.
scrip = your wish
trading type = intraday/swing,

PS: I m not good in backtesting. :p
thanks
I have started the optimization for the AFL , It will take around 2 hours for the results to come out. I am optimizing on 1 year data , if the results are satisfactory , then we will go for bigger data.
 

vijkris

Learner and Follower
I have started the optimization for the AFL , It will take around 2 hours for the results to come out. I am optimizing on 1 year data , if the results are satisfactory , then we will go for bigger data.
optimization is the least understood topic .:eek:
still are there any parameters in the afl which can be optimized? :confused:
 

vijkris

Learner and Follower
There are 2 parameters in the AFL
cx=Param ("cxposn",785,0,500,1);
cy=Param ("cyposn",39,0,500,1);
oh.. dear . those are graphic things. no need to work hard to optimize those.
it has no effect on buy/sell signals.
 

oldtrader

Well-Known Member
oh.. dear . those are graphic things. no need to work hard to optimize those.
it has no effect on buy/sell signals.
Bactest Period 2006 to 2014
TF = 7 min
4385 NF points in 3379 trades

Sorry to say but results are not favourable. 3379 trades are 3 times more than the normal . The trades are reducing by increasing the TF , but the profit is reducing to 2000+ points.
 

vijkris

Learner and Follower
Bactest Period 2006 to 2014
TF = 7 min
4385 NF points in 3379 trades

Sorry to say but results are not favourable. 3379 trades are 3 times more than the normal . The trades are reducing by increasing the TF , but the profit is reducing to 2000+ points.
thanks for the effort. :thumb:
now it clears the way to include pivots. if I find it worth then will trouble u again. :)
 

Similar threads