NF Swing Trading using Fractal AFL

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.
If you are using VWAP for filtering Long/Short trades, and using Pivots for trigger
in that case you can also try different types of Moving averages, long back I had posted a AFL with all in one MA,
you can modify it to try which one suits best as a filter for your type of trading.


http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-52.html#post909149



Happy :)
 

vijkris

Learner and Follower
Ohh nice,then you can share the full version in your thread(if possible and this is the right time to share).Rest your wish.
Bhai, previously u used to stay @ 14th floor, now u r in TJ 24x7. :lol: :D

if an afl contains buy/sell arrows then it must be backtested properly b4 sharing.
recently cracked the visual pivots afl of pratapsir. now it can also be backtested . that's y suspended trading until I find out strengths and weakness of the method.
now happy ji has provided a combo ma afl which prima facie looks good and can be included.
will update here later . :thumb:
 

Mungus

Well-Known Member
Bhai, previously u used to stay @ 14th floor, now u r in TJ 24x7. :lol: :D

if an afl contains buy/sell arrows then it must be backtested properly b4 sharing.
recently cracked the visual pivots afl of pratapsir. now it can also be backtested . that's y suspended trading until I find out strengths and weakness of the method.
now happy ji has provided a combo ma afl which prima facie looks good and can be included.
will update here later . :thumb:
If you invite at your place then location update ho jaayega- "@ Viju's Kingdom" :D
Rather than suspending,You should trade small quantity.
 
now happy ji has provided a combo ma afl which prima facie looks good and can be included.
will update here later . :thumb:
Not now its here on TJ since last 2 years :D

maybe you are not looking hard enough, anyway . . .


Instead of starting with some code and testing it, its always better to start with some premise or concept . . .

In your case lets say you want to use pivots for entry/exit trigger and some kind of filter for trade direction


Now this filter could be any kind of curve/MA/regression line maybe oscillator or momentum or even open interest / change of OI

To start with lets say you have decided to go with some MA or combination of it.
So what is the criteria in selecting it, running tests maybe a small part of it
but first of all understanding these diff types of averages is important

Any MA curve should be judged based on its Smoothness, Responsiveness, Lag and Overshoot.

The more Smoothness you try to introduce more is the Lag you get and
if we introduce more of Responsiveness we usually get overshot i.e the MA starts moving ahead of price . . .

on the other hand some Lag is not always bad, Lag is v useful to filter out whipsaws

Different types of MAs behave differently for eg TEMA, HMA & LinReg have good responsiveness but they tend to overshoot,
MA, WMA have great smoothness but also a big lag. Wilder also has a big lag

The combination MA was coded to try and get a super MA :lol:

Here super does not mean max profit, but getting a balance or say desired behavior.

Wish you Happy Testing, and hope you guys settle in to some stable code that you can use for your type of trading.

Thanks

Happy :)




The old code with some modification for back testing i.e.
this thread's most favorite command - - - "Optimize" :)
Code:
_SECTION_BEGIN("Price");
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_END();


// Using Ratio 0-10 will make optimize loops impossiblly huge :)
// Range 0 to 1 makes it the type of -  OFF / ON For every MA
// i.e 0 = Exclude & 1 = Include that type of MA
_SECTION_BEGIN("SUPER_MA");
R1 = Optimize("EMA  RATIO",Param("EMA  RATIO",1,0,10,1),0,1,1);
R2 = Optimize("DEMA RATIO",Param("DEMA RATIO",1,0,10,1),0,1,1);
R3 = Optimize("TEMA RATIO",Param("TEMA RATIO",1,0,10,1),0,1,1);
R4 = Optimize("WMA  RATIO",Param("WMA  RATIO",1,0,10,1),0,1,1);
R5 = Optimize("HMA  RATIO",Param("HMA  RATIO",1,0,10,1),0,1,1);
R6 = Optimize("MA   RATIO",Param("MA   RATIO",1,0,10,1),0,1,1);
R7 = Optimize("Wilder RATIO",Param("Wilder RATIO",1,0,10,1),0,1,1);
R8 = Optimize("LinReg RATIO",Param("LinReg RATIO",1,0,10,1),0,1,1);

s = R1+R2+R3+R4+R5+R6+R7+R8;

function SuperMA(P, n) 
{ 
	m1	=	EMA(P,n);		m2	=	DEMA(P,n);		m3	=	TEMA(P,n);	
	m4	=	WMA(P,n);		m5	=	HMA(P,n);		m6	=	MA(P,n);	
	m7	=	Wilders(P,n);		m8	=	LinearReg(P,n);

	m  = (R1*m1+R2*m2+R3*m3+R4*m4+R5*m5+R6*m6+R7*m7+R8*m8)/s;	

   return m; 
} 


Len  = Optimize("PERIOD",Param("PERIOD",60,2,99,1),25,90,5);

SMA_C = SuperMA(C,Len);	SMA_O = SuperMA(O,Len);
SMA_H = SuperMA(H,Len);	SMA_L = SuperMA(L,Len);
Col = IIf(SMA_C > SMA_O,colorBlue,colorRed);
Plot(SMA_H,"SMA_H",Col,styleThick);	
Plot(SMA_L,"SMA_L",Col,styleThick);

_SECTION_END();

_SECTION_BEGIN("SYSTEM");
SetPositionSize(100,4);
Buy  = SMA_C > SMA_O AND C > SMA_H;		Short = SMA_C < SMA_O AND C < SMA_L;
Sell = SMA_C < SMA_O AND C < SMA_L;		Cover = SMA_C > SMA_O AND C > SMA_H; 
Buy  = ExRem(Buy,Sell);						Short = ExRem(Short,Cover);
Sell = ExRem(Sell,Buy);						Cover = ExRem(Cover,Short);
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H),-30);
_SECTION_END();

Happy :)
 
Last edited:

vijkris

Learner and Follower
Not now its here on TJ since last 2 years :D

maybe you are not looking hard enough, anyway . . .


Instead of starting with some code and testing it, its always better to start with some premise or concept . . .

In your case lets say you want to use pivots for entry/exit trigger and some kind of filter for trade direction


Now this filter could be any kind of curve/MA/regression line maybe oscillator or momentum or even open interest / change of OI

To start with lets say you have decided to go with some MA or combination of it.
So what is the criteria in selecting it, running tests maybe a small part of it
but first of all understanding these diff types of averages is important

Any MA curve should be judged based on its Smoothness, Responsiveness, Lag and Overshoot.

The more Smoothness you try to introduce more is the Lag you get and
if we introduce more of Responsiveness we usually get overshot i.e the MA starts moving ahead of price . . .

on the other hand some Lag is not always bad, Lag is v useful to filter out whipsaws

Different types of MAs behave differently for eg TEMA, HMA & LinReg have good responsiveness but they tend to overshoot,
MA, WMA have great smoothness but also a big lag. Wilder also has a big lag

The combination MA was coded to try and get a super MA :lol:

Here super does not mean max profit, but getting a balance or say desired behavior.

Wish you Happy Testing, and hope you guys settle in to some stable code that you can use for your type of trading.

Thanks

Happy :)




The old code with some modification for back testing i.e.
this thread's most favorite command - - - "Optimize" :)
Code:
_SECTION_BEGIN("Price");
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_END();


// Using Ratio 0-10 will make optimize loops impossiblly huge :)
// Range 0 to 1 makes it the type of -  OFF / ON For every MA
// i.e 0 = Exclude & 1 = Include that type of MA
_SECTION_BEGIN("SUPER_MA");
R1 = Optimize("EMA  RATIO",Param("EMA  RATIO",1,0,10,1),0,1,1);
R2 = Optimize("DEMA RATIO",Param("DEMA RATIO",1,0,10,1),0,1,1);
R3 = Optimize("TEMA RATIO",Param("TEMA RATIO",1,0,10,1),0,1,1);
R4 = Optimize("WMA  RATIO",Param("WMA  RATIO",1,0,10,1),0,1,1);
R5 = Optimize("HMA  RATIO",Param("HMA  RATIO",1,0,10,1),0,1,1);
R6 = Optimize("MA   RATIO",Param("MA   RATIO",1,0,10,1),0,1,1);
R7 = Optimize("Wilder RATIO",Param("Wilder RATIO",1,0,10,1),0,1,1);
R8 = Optimize("LinReg RATIO",Param("LinReg RATIO",1,0,10,1),0,1,1);

s = R1+R2+R3+R4+R5+R6+R7+R8;

function SuperMA(P, n) 
{ 
	m1	=	EMA(P,n);		m2	=	DEMA(P,n);		m3	=	TEMA(P,n);	
	m4	=	WMA(P,n);		m5	=	HMA(P,n);		m6	=	MA(P,n);	
	m7	=	Wilders(P,n);		m8	=	LinearReg(P,n);

	m  = (R1*m1+R2*m2+R3*m3+R4*m4+R5*m5+R6*m6+R7*m7+R8*m8)/s;	

   return m; 
} 


Len  = Optimize("PERIOD",Param("PERIOD",60,2,99,1),25,90,5);

SMA_C = SuperMA(C,Len);	SMA_O = SuperMA(O,Len);
SMA_H = SuperMA(H,Len);	SMA_L = SuperMA(L,Len);
Col = IIf(SMA_C > SMA_O,colorBlue,colorRed);
Plot(SMA_H,"SMA_H",Col,styleThick);	
Plot(SMA_L,"SMA_L",Col,styleThick);

_SECTION_END();

_SECTION_BEGIN("SYSTEM");
SetPositionSize(100,4);
Buy  = SMA_C > SMA_O AND C > SMA_H;		Short = SMA_C < SMA_O AND C < SMA_L;
Sell = SMA_C < SMA_O AND C < SMA_L;		Cover = SMA_C > SMA_O AND C > SMA_H; 
Buy  = ExRem(Buy,Sell);						Short = ExRem(Short,Cover);
Sell = ExRem(Sell,Buy);						Cover = ExRem(Cover,Short);
PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H),-30);
_SECTION_END();

Happy :)
thanks for the support.

actually all the afls which I m using was buried in TJ. even pratap sir's visual pivots afl was buried somewhere. :lol:
yes my intention was to use that vwap code as a filter for direction and pivots as a trigger for entry/exit.

BAcktesting and coding is a big task for me as basically I m not a coder. :lol:
thanks to oldtrader, I can outsource the backtesting part to him(or her) :D
( oldtrader can be female also !!! :D)

all ppl here has backtested system which is profitable, my system works but is not backtested :(
 

vijkris

Learner and Follower
oldtrader ji,
here I have combined happy ji's superMA with visual pivots(minor pivots of higher tf).

for consistency loaded nf data since jan 2015-may 2016.
since it was repainting, added ref in buy/sell condition.
pls backtest as it is with default parameters first.
there are lot of params in visual pivots, so if u want to optimize look for tf factor param, default is 3. I wont recommend above 5. don't optimize any other param, its of no use, I think.

my swing results for 7tf nf.
pls backtest and let us know the results.
keeping my fingers crossed. :rolleyes:



Code:
// thanks to happy ji and pratap ji for the valuable contribution
//test happy and pivots.afl
_SECTION_BEGIN("Price");
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_END();
_SECTION_BEGIN("Visual Pivots");


ro = ParamField("Open", 0) ;
rh = ParamField("High", 1) ;
rl = ParamField("Low", 2) ;
rc = ParamField("Close", 3) ;


P = (rH+rL+rC)/3 ;
p1 = Param("Fast", 1, 1, 100, 1) ;
p2 = Param("Slow", 3, 1, 100, 1) ;
usebpvts = ParamToggle("Use Body Pvts", "No|Yes", 0) ;
isemapvts = ParamToggle("Pvt Type", "H-L|EMA", 1) ;

ismph = H-H ;
ismpl = L-L ;
bph = Max(rO,rC);
bpl = Min(rO,rC);

if (isemapvts)
{
EMA1 = EMA(P, p1) ;
EMA2 = EMA(P, p2) ;

upcross = Cross(EMA1, EMA2) ;
downcross = Cross(EMA2, EMA1) ;

//bph = Max(O,C);
//bpl = Min(O,C);
bi = BarIndex() ;

mphbar = HighestSinceBars(upcross, rH) ;
mplbar = LowestSinceBars(downcross, rL) ;

mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;

mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;

ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;

bmphbar = HighestSinceBars(upcross, bph) ;
bmplbar = LowestSinceBars(downcross, bpl) ;

bmphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, bmphbar, 0) ;
isbmph = bmphbi == bi ;

bmplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, bmplbar, 0) ;
isbmpl = bmplbi == bi ;

isbmph = IIf(downCross AND bmphbar == 0, True, isbmph) ;
isbmpl = IIf(upcross AND bmplbar == 0, True, isbmpl) ;
}
else
{
	isbmph = ismph = rH > Ref(rH, -1) AND rH > Ref(rH, 1) ;
	isbmpl = ismpl = rL < Ref(rL, -1) AND rL < Ref(rL, 1) ;

}

showminor = ParamToggle("Show Minor Pvts", "No|Yes", 1) ;

issquare = ParamToggle("Pvt style", "Circle|Square", 0) ;
Clrmph = ParamColor("MPH Color", colorGreen) ;
Clrmpl = ParamColor("MPL Color", colorBrown) ;

pvtmarker = IIf(issquare, shapeSmallSquare, shapeSmallCircle) ;

if (showminor)
{
if (usebpvts)
{
	PlotShapes(isbmph*pvtmarker , Clrmph , 0, rH, 12) ;
	PlotShapes(isbmpl*pvtmarker , Clrmpl, 0, rL, -12) ;
}
else
{
	PlotShapes(ismph*pvtmarker , Clrmph , 0, rH, 12) ;
	PlotShapes(ismpl*pvtmarker , Clrmpl, 0, rL, -12) ;
}
}

showminorlvls = ParamToggle("Show Minor Levels", "No|Yes", 0) ;

mph = ValueWhen(ismph, rH) ;
mpl = ValueWhen(ismpl, rL) ;

if (showminorlvls)
{
	x = LineArray(0, SelectedValue(mph), (BarCount-1), SelectedValue(mph));

	Plot(x, "", colorGold, styleDashed);

	x = LineArray(0, SelectedValue(mpl), (BarCount-1), SelectedValue(mpl));

	Plot(x, "", colorGold, styleDashed);
}

showminortrend = ParamToggle("Show Minor Trend", "No|Yes", 0) ;
if (showminortrend)
{
	// initialize minor levels
	mph = ValueWhen(ismph, rH) ;
	mpl = ValueWhen(ismpl, rL) ;
	mbph = ValueWhen(isbmph, bph) ;
	mbpl = ValueWhen(isbmpl, bpl) ;

	// minor trend
	mut = rH > mph OR (rC > mbph) OR (ismph AND rH > Ref(mph, -1));
	mdt = rL < mpl OR (rC < mbpl) OR (ismpl AND rL < Ref(mpl, -1));
	mdt = Flip(mdt, mut) ;
	mut = Flip(mut, mdt) ;
	//mutst = ExRem(mut, mdt) ;
	//mdtst = ExRem(mdt, mut) ;
	
	Clr = IIf(mut, colorBlue, colorRed) ;
	PlotOHLC(rO,rH,rL,rC, "", Clr, styleCandle|styleNoLabel);
	Plot(4, "", Clr, styleArea|styleOwnScale, 0, 100, 0, -1) ;

}


tffactor = Param("TF Factor", 3, 1, 100, 1)  ;
showhigher = ParamToggle("Show Higher", "No|Yes", 1) ;

//if (showhigher)
//{
tfs = tffactor *Interval() ;

TimeFrameSet(tfs) ;

if (isemapvts)
{
Ptf = (H+L+C)/3 ;
EMA1tf = EMA(Ptf, p1) ;
EMA2tf = EMA(Ptf, p2) ;

upcrosstf = Cross(EMA1tf, EMA2tf) ;
downcrosstf = Cross(EMA2tf, EMA1tf) ;
bphtf = Max(O,C) ;
bpltf = Min(O,C) ;

if (usebpvts)
{
	Refhtf = bphtf ;
	Refltf = bpltf ;
}
else
{
	Refhtf = H ;
	Refltf = L ;
}

mphbartf = HighestSinceBars(upcrosstf, Refhtf) ;
mplbartf = LowestSinceBars(downcrosstf, Refltf) ;

bitf = BarIndex() ;
mphbitf = ValueWhen(downcrosstf, bitf, 0) - ValueWhen(downcrosstf, mphbartf, 0) ;
ismphtf = mphbitf == bitf ;

mplbitf = ValueWhen(upCrosstf, bitf, 0) - ValueWhen(upCrosstf, mplbartf, 0) ;
ismpltf = mplbitf == bitf ;

ismphtf = IIf(downCrosstf AND mphbartf == 0, True, ismphtf) ;
ismpltf = IIf(upcrosstf AND mplbartf == 0, True, ismpltf) ;
}
else
{
	ismphtf = H > Ref(H, -1) AND H > Ref(H, 1) ;
	ismpltf = L < Ref(L, -1) AND L < Ref(L, 1) ;
}

if (showminortrend)
{
	// initialize minor levels
	mphtf = ValueWhen(ismphtf, H) ;
	mpltf = ValueWhen(ismpltf, L) ;
	mbphtf = ValueWhen(ismphtf, bphtf) ;
	mbpltf = ValueWhen(ismpltf, bpltf) ;

	// minor trend
	muttf = H > mphtf OR (C > mbphtf) OR (ismphtf AND H > Ref(mphtf, -1));
	mdttf = L < mpltf OR (C < mbpltf) OR (ismpltf AND L < Ref(mpltf, -1));
	mdttf = Flip(mdttf, muttf) ;
	muttf = Flip(muttf, mdttf) ;
	//mutst = ExRem(mut, mdt) ;
	//mdtst = ExRem(mdt, mut) ;
	
	Clrtf = IIf(muttf, colorBlue, colorRed) ;
//	PlotOHLC(rO,rH,rL,rC, "", Clr, styleCandle|styleNoLabel);
	Clrtfe = TimeFrameExpand(Clrtf, tfs, expandLast) ;
	Plot(2, "htf", Clrtfe, styleArea|styleOwnScale, 0, 100) ;


}



ismphtfe = TimeFrameExpand(ismphtf, tfs, expandFirst) ;
ismpltfe = TimeFrameExpand(ismpltf, tfs, expandFirst) ;

He=TimeFrameExpand(H, tfs, expandFirst) ;
Le=TimeFrameExpand(L, tfs, expandFirst) ;

TimeFrameRestore() ;

ishtfmph = IIf(ismph == ismphtfe, 1, 0) ;
ishtfmpl = IIf(ismpl == ismpltfe, 1, 0) ;


PlotShapes(ismphtfe *shapeSmallSquare, Clrmph , 0, He, 12) ;
PlotShapes(ismpltfe *shapeSmallSquare, Clrmpl, 0, Le, -12) ;

showhtflvls = ParamToggle("Show HTF levels", "No|Yes", 1) ;
Clrhtflvl = colorPaleGreen ;
//mphhtf = ValueWhen(ismphtfe , He, 1) ;
	//mplhtf = ValueWhen(ismpltfe , Le, 1) ;

//Plot(2, "", IIf(ismph , colorBlue, IIf(ismpl, colorRed, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
//Plot(4, "", IIf(ishtfmph , colorBlue, IIf(ishtfmpl , colorRed, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
if (showhtflvls )
{
	mphhtf = ValueWhen(ismphtfe , He, 1) ;
	mplhtf = ValueWhen(ismpltfe , Le, 1) ;
	x = LineArray(0, SelectedValue(mphhtf), (BarCount-1), SelectedValue(mphhtf));

	Plot(x, "", Clrhtflvl ,styleLine| styleDots);

	x = LineArray(0, SelectedValue(mplhtf), (BarCount-1), SelectedValue(mplhtf));

	Plot(x, "", Clrhtflvl ,styleLine| styleDots);
}


//Plot(2, "", IIf(ismphtfe , colorRed, IIf(ismpltfe , colorBlue, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
//Plot(4, "", IIf(ismph, colorRed, IIf(ismpl , colorBlue, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;

_SECTION_END();



// Using Ratio 0-10 will make optimize loops impossiblly huge :)
// Range 0 to 1 makes it the type of -  OFF / ON For every MA
// i.e 0 = Exclude & 1 = Include that type of MA
_SECTION_BEGIN("SUPER_MA");
R1 = Optimize("EMA  RATIO",Param("EMA  RATIO",1,0,10,1),0,1,1);
R2 = Optimize("DEMA RATIO",Param("DEMA RATIO",1,0,10,1),0,1,1);
R3 = Optimize("TEMA RATIO",Param("TEMA RATIO",1,0,10,1),0,1,1);
R4 = Optimize("WMA  RATIO",Param("WMA  RATIO",1,0,10,1),0,1,1);
R5 = Optimize("HMA  RATIO",Param("HMA  RATIO",1,0,10,1),0,1,1);
R6 = Optimize("MA   RATIO",Param("MA   RATIO",1,0,10,1),0,1,1);
R7 = Optimize("Wilder RATIO",Param("Wilder RATIO",1,0,10,1),0,1,1);
R8 = Optimize("LinReg RATIO",Param("LinReg RATIO",1,0,10,1),0,1,1);

s = R1+R2+R3+R4+R5+R6+R7+R8;

function SuperMA(P, n) 
{ 
	m1	=	EMA(P,n);		m2	=	DEMA(P,n);		m3	=	TEMA(P,n);	
	m4	=	WMA(P,n);		m5	=	HMA(P,n);		m6	=	MA(P,n);	
	m7	=	Wilders(P,n);		m8	=	LinearReg(P,n);

	m  = (R1*m1+R2*m2+R3*m3+R4*m4+R5*m5+R6*m6+R7*m7+R8*m8)/s;	

   return m; 
} 


Len  = Optimize("PERIOD",Param("PERIOD",60,2,99,1),25,90,5);

SMA_C = SuperMA(C,Len);	SMA_O = SuperMA(O,Len);
SMA_H = SuperMA(H,Len);	SMA_L = SuperMA(L,Len);
Col = IIf(SMA_C > SMA_O,colorBlue,colorRed);
Plot(SMA_H,"SMA_H",Col,styleThick);	
Plot(SMA_L,"SMA_L",Col,styleThick);

_SECTION_END();

_SECTION_BEGIN("SYSTEM");
SetPositionSize(75,4);
Buy1  = SMA_C > SMA_O AND C > SMA_H;		Short1 = SMA_C < SMA_O AND C < SMA_L;
Sell1 = SMA_C < SMA_O AND C < SMA_L;		Cover1 = SMA_C > SMA_O AND C > SMA_H; 

 Sellpivot = ValueWhen(Buy1,Ref(mplhtf,-1));      Coverpivot =  ValueWhen(short1,Ref(mphhtf,-1));
Buypivot = ValueWhen(Buy1,Ref(mphhtf,-1));       shortpivot =  ValueWhen(short1,Ref(mplhtf,-1));
Buy = Buy1  AND Cross(C,Buypivot);
Short = Short1 AND Cross(Shortpivot,C);
Sell= Sell1 AND Cross(Sellpivot,C);
Cover = Cover1 AND Cross(C,Coverpivot);

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

PlotShapes(Buy+2*Sell,colorWhite,0,IIf(Buy,L,H),-30);
_SECTION_END();
edit: I m not sure abt the logical accuracy of the code. .
 
Last edited:

oldtrader

Well-Known Member
oldtrader ji,
here I have combined happy ji's superMA with visual pivots(minor pivots of higher tf).

for consistency loaded nf data since jan 2015-may 2016.
since it was repainting, added ref in buy/sell condition.
pls backtest as it is with default parameters first.
there are lot of params in visual pivots, so if u want to optimize look for tf factor param, default is 3. I wont recommend above 5. don't optimize any other param, its of no use, I think.

my swing results for 7tf nf.
pls backtest and let us know the results.
keeping my fingers crossed. :rolleyes:

edit: I m not sure abt the logical accuracy of the code. .
I have backtested with the default parameters, find below the result.

 

Similar threads