I found a very simple formula few days ago over the internet it is able to catch the up and down moves and gives good returns but only when there is a clear trend and when the price is not in trend then a lots and lots of whipsaws.......so i decided to combine with another trading system that I was having........when I tested them side by side then I found that when 1st system is giving whipsaws the 2nd system is filtering them and when the second system is giving whipsaws the 1st system is filtering them most of the time and overall giving satisfactory signals with less whipsaws.......I tried to code them together where a buy signal condition is
Buy = ((1st System Buy) and (2nd System Buy)) or ((2nd System Buy) and (1st System Buy))
Sell = ((1st System Sell) and (2nd System Sell)) or ((2nd System Sell) and (1st System Sell))
But when I tested the code, I was not satisfied cos the signals are not being projected as I wanted.........So can someone please combine these two system and correct me where I went wrong......
I am posting.....
- Trading System 1
- Trading System 2
- Combined code of the above two systems by me
Trading System 1
Trading System 2
The combined code of the above two systems
Buy = ((1st System Buy) and (2nd System Buy)) or ((2nd System Buy) and (1st System Buy))
Sell = ((1st System Sell) and (2nd System Sell)) or ((2nd System Sell) and (1st System Sell))
But when I tested the code, I was not satisfied cos the signals are not being projected as I wanted.........So can someone please combine these two system and correct me where I went wrong......
I am posting.....
- Trading System 1
- Trading System 2
- Combined code of the above two systems by me
Trading System 1
_SECTION_BEGIN("Trading System 1");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
n=Param("n",34,1,500,1);
A = Wilders( H,n );
B = Wilders( L,n );
SetPositionSize(1,spsShares);
x= Ref(A,-n);
y= Ref(B,-n);
p=Param("p",0.0009,0.0001,1,0.0001);
D=p;
xt=x+x*D;
xb=x-x*D;
yt=y+y*D;
yb=y-y*D;
/* Buy or Sell Condition */
Buy = Cross(Close,xt);
Sell = Cross(yt,Close);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2 );
Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
Title = EncodeColor(colorWhite)+ "Trading System 1" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");
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, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
n=Param("n",34,1,500,1);
A = Wilders( H,n );
B = Wilders( L,n );
SetPositionSize(1,spsShares);
x= Ref(A,-n);
y= Ref(B,-n);
p=Param("p",0.0009,0.0001,1,0.0001);
D=p;
xt=x+x*D;
xb=x-x*D;
yt=y+y*D;
yb=y-y*D;
/* Buy or Sell Condition */
Buy = Cross(Close,xt);
Sell = Cross(yt,Close);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2);
AlertIf( Sell, "SOUND C:\\Windows\\Media\\tada.wav", "Audio alert", 2 );
Filter = Buy OR Sell;
/* Exploration Parameters */
AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy", 1 );
AddColumn( Sell, "Sell", 1 );
AddColumn( C, "Close", 1.3 );
AddColumn( H, "High", 1.3 );
Title = EncodeColor(colorWhite)+ "Trading System 1" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");
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, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();
Trading System 2
/////////////////Optimize////////////////////
x = Optimize("B", 20, 1, 30, 1 );
y = Optimize("S", 20, 1, 30, 1 );
z = Optimize("L", 30, 2, 100, 2 );
/////////////////PercentR////////////////////
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods
) );
}
/////////////////TrendScore ////////////////////
TrendScore =
IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
/////////////////AROON////////////////////
Period = 14;
LLVBarsSince = LLVBars(L, Period) + 1;
HHVBarsSince = HHVBars(H, Period) + 1;
AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1);
AroonUp = 100 * (Period - HHVBarsSince) / (Period - 1);
/////////////////Basic////////////////////
_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", colorBlack ), styleLine);
_SECTION_END();
_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 7, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width%", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
CenterLine = EMA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color,
Style );
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color,
Style );
_SECTION_END();
_SECTION_BEGIN("Percent Bands1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width%", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
CenterLine = EMA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color,
Style );
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color,
Style );
_SECTION_END();
_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA4");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
/////////////////Twiggs Money Flow////////////////////
periods = Param( "Periods", 144, 5, 200, 1 );
TRH=Max(Ref(C,-1),H);
TRL=Min(Ref(C,-1),L);
TR=TRH-TRL;
ADV=V*((C-TRL)-(TRH-C))/ IIf(TR==0,9999999,TR);
WV=V+(Ref(V,-1)*0);
SmV= Wilders(WV,periods);
SmA= Wilders(ADV,periods);
TMF= IIf(SmV==0,0,SmA/SmV);
///////////////////////////Buy/////////////////////////////////
//PositionSize=1500;
Buy=IIf((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20)
,EMA(C,5)>EMA(C,63) AND EMA(C,63)>Ref(EMA(C,63),-1)
AND Close>Open
//AND C>1 AND EMA(V,20)*EMA(C,20)>50000
AND AroonUp>70
//AND TMF>0
AND TSF(percentR(14),30)>-50
AND trendscore>5,0);
///////////////////////////Sell/////////////////////////////////
Sell=IIf ((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20),
C<EMA(C,30)
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND trendscore<-5
AND TMF<0 //OR (TMF>0 AND C<0.97*EMA(C,30))
AND AroonDn>70
,(EMA(C,5)<0.97*EMA(C,63))
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND AroonDn>70
//AND TMF<0
//AND trendscore<-5
)
;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High )
);
//GraphXSpace = 105;
///////////////////////////Filter/////////////////////////////////
Filter=C>5;
//EMA(V,20)*EMA(C,20)>50000;
AddColumn( ADX(14), "ADX", 1.2 );
AddColumn( C, "C", 1.2 );
AddColumn( V, "V", 1.2 );
AddColumn( EMA(V,20), "EMAV20", 1.2 );
AddColumn( EMA(V,20)*EMA(C,20), "V*C", 1.2 );
x = Optimize("B", 20, 1, 30, 1 );
y = Optimize("S", 20, 1, 30, 1 );
z = Optimize("L", 30, 2, 100, 2 );
/////////////////PercentR////////////////////
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods
) );
}
/////////////////TrendScore ////////////////////
TrendScore =
IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
/////////////////AROON////////////////////
Period = 14;
LLVBarsSince = LLVBars(L, Period) + 1;
HHVBarsSince = HHVBars(H, Period) + 1;
AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1);
AroonUp = 100 * (Period - HHVBarsSince) / (Period - 1);
/////////////////Basic////////////////////
_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", colorBlack ), styleLine);
_SECTION_END();
_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 7, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("Percent Bands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width%", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
CenterLine = EMA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color,
Style );
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color,
Style );
_SECTION_END();
_SECTION_BEGIN("Percent Bands1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width%", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
CenterLine = EMA( P, Periods );
Plot( (1 + Width * 0.01) * CenterLine, "%EnvTop" + _PARAM_VALUES(), Color,
Style );
Plot( (1 - Width * 0.01) * CenterLine, "%EnvBot" + _PARAM_VALUES(), Color,
Style );
_SECTION_END();
_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
_SECTION_BEGIN("EMA4");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ),
ParamStyle("Style") );
_SECTION_END();
/////////////////Twiggs Money Flow////////////////////
periods = Param( "Periods", 144, 5, 200, 1 );
TRH=Max(Ref(C,-1),H);
TRL=Min(Ref(C,-1),L);
TR=TRH-TRL;
ADV=V*((C-TRL)-(TRH-C))/ IIf(TR==0,9999999,TR);
WV=V+(Ref(V,-1)*0);
SmV= Wilders(WV,periods);
SmA= Wilders(ADV,periods);
TMF= IIf(SmV==0,0,SmA/SmV);
///////////////////////////Buy/////////////////////////////////
//PositionSize=1500;
Buy=IIf((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20)
,EMA(C,5)>EMA(C,63) AND EMA(C,63)>Ref(EMA(C,63),-1)
AND Close>Open
//AND C>1 AND EMA(V,20)*EMA(C,20)>50000
AND AroonUp>70
//AND TMF>0
AND TSF(percentR(14),30)>-50
AND trendscore>5,0);
///////////////////////////Sell/////////////////////////////////
Sell=IIf ((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20),
C<EMA(C,30)
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND trendscore<-5
AND TMF<0 //OR (TMF>0 AND C<0.97*EMA(C,30))
AND AroonDn>70
,(EMA(C,5)<0.97*EMA(C,63))
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND AroonDn>70
//AND TMF<0
//AND trendscore<-5
)
;
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High )
);
//GraphXSpace = 105;
///////////////////////////Filter/////////////////////////////////
Filter=C>5;
//EMA(V,20)*EMA(C,20)>50000;
AddColumn( ADX(14), "ADX", 1.2 );
AddColumn( C, "C", 1.2 );
AddColumn( V, "V", 1.2 );
AddColumn( EMA(V,20), "EMAV20", 1.2 );
AddColumn( EMA(V,20)*EMA(C,20), "V*C", 1.2 );
The combined code of the above two systems
_SECTION_BEGIN("Trading System 1");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
n=Param("n",34,1,500,1);
A = Wilders( H,n );
B = Wilders( L,n );
SetPositionSize(1,spsShares);
x= Ref(A,-n);
y= Ref(B,-n);
p=Param("p",0.0009,0.0001,1,0.0001);
D=p;
xt=x+x*D;
xb=x-x*D;
yt=y+y*D;
yb=y-y*D;
BuyCond1 = Cross(Close,xt);
SellCond1 = Cross(yt,Close);
_SECTION_END();
_SECTION_BEGIN("Trading System 2");
/////////////////Optimize////////////////////
x = Optimize("B", 20, 1, 30, 1 );
y = Optimize("S", 20, 1, 30, 1 );
z = Optimize("L", 30, 2, 100, 2 );
/////////////////PercentR////////////////////
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods
) );
}
/////////////////TrendScore ////////////////////
TrendScore =
IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
/////////////////AROON////////////////////
Period = 14;
LLVBarsSince = LLVBars(L, Period) + 1;
HHVBarsSince = HHVBars(H, Period) + 1;
AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1);
AroonUp = 100 * (Period - HHVBarsSince) / (Period - 1);
/////////////////Basic////////////////////
_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", colorBlack ), styleLine);
_SECTION_END();
/////////////////Twiggs Money Flow////////////////////
periods = Param( "Periods", 144, 5, 200, 1 );
TRH=Max(Ref(C,-1),H);
TRL=Min(Ref(C,-1),L);
TR=TRH-TRL;
ADV=V*((C-TRL)-(TRH-C))/ IIf(TR==0,9999999,TR);
WV=V+(Ref(V,-1)*0);
SmV= Wilders(WV,periods);
SmA= Wilders(ADV,periods);
TMF= IIf(SmV==0,0,SmA/SmV);
///////////////////////////Buy/////////////////////////////////
//PositionSize=1500;
BuyCond2=IIf((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20)
,EMA(C,5)>EMA(C,63) AND EMA(C,63)>Ref(EMA(C,63),-1)
AND Close>Open
//AND C>1 AND EMA(V,20)*EMA(C,20)>50000
AND AroonUp>70
//AND TMF>0
AND TSF(percentR(14),30)>-50
AND trendscore>5,0);
///////////////////////////Sell/////////////////////////////////
SellCond2=IIf ((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20),
C<EMA(C,30)
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND trendscore<-5
AND TMF<0 //OR (TMF>0 AND C<0.97*EMA(C,30))
AND AroonDn>70
,(EMA(C,5)<0.97*EMA(C,63))
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND AroonDn>70
//AND TMF<0
//AND trendscore<-5
)
;
///////////////////////////Filter/////////////////////////////////
Filter=C>5;
//EMA(V,20)*EMA(C,20)>50000;
AddColumn( ADX(14), "ADX", 1.2 );
AddColumn( C, "C", 1.2 );
AddColumn( V, "V", 1.2 );
AddColumn( EMA(V,20), "EMAV20", 1.2 );
AddColumn( EMA(V,20)*EMA(C,20), "V*C", 1.2 );
_SECTION_END();
Buy = ((BuyCond1 AND BuyCond2) OR (BuyCond2 AND BuyCond1));
Sell = ((SellCond1 AND SellCond2) OR (SellCond2 AND SellCond1));
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
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, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
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", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
n=Param("n",34,1,500,1);
A = Wilders( H,n );
B = Wilders( L,n );
SetPositionSize(1,spsShares);
x= Ref(A,-n);
y= Ref(B,-n);
p=Param("p",0.0009,0.0001,1,0.0001);
D=p;
xt=x+x*D;
xb=x-x*D;
yt=y+y*D;
yb=y-y*D;
BuyCond1 = Cross(Close,xt);
SellCond1 = Cross(yt,Close);
_SECTION_END();
_SECTION_BEGIN("Trading System 2");
/////////////////Optimize////////////////////
x = Optimize("B", 20, 1, 30, 1 );
y = Optimize("S", 20, 1, 30, 1 );
z = Optimize("L", 30, 2, 100, 2 );
/////////////////PercentR////////////////////
function PercentR( periods )
{
return -100 * ( HHV( H, periods ) - C )/( HHV( H, periods ) - LLV( L, periods
) );
}
/////////////////TrendScore ////////////////////
TrendScore =
IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
/////////////////AROON////////////////////
Period = 14;
LLVBarsSince = LLVBars(L, Period) + 1;
HHVBarsSince = HHVBars(H, Period) + 1;
AroonDn = 100 * (Period - LLVBarsSince) / (Period - 1);
AroonUp = 100 * (Period - HHVBarsSince) / (Period - 1);
/////////////////Basic////////////////////
_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", colorBlack ), styleLine);
_SECTION_END();
/////////////////Twiggs Money Flow////////////////////
periods = Param( "Periods", 144, 5, 200, 1 );
TRH=Max(Ref(C,-1),H);
TRL=Min(Ref(C,-1),L);
TR=TRH-TRL;
ADV=V*((C-TRL)-(TRH-C))/ IIf(TR==0,9999999,TR);
WV=V+(Ref(V,-1)*0);
SmV= Wilders(WV,periods);
SmA= Wilders(ADV,periods);
TMF= IIf(SmV==0,0,SmA/SmV);
///////////////////////////Buy/////////////////////////////////
//PositionSize=1500;
BuyCond2=IIf((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20)
,EMA(C,5)>EMA(C,63) AND EMA(C,63)>Ref(EMA(C,63),-1)
AND Close>Open
//AND C>1 AND EMA(V,20)*EMA(C,20)>50000
AND AroonUp>70
//AND TMF>0
AND TSF(percentR(14),30)>-50
AND trendscore>5,0);
///////////////////////////Sell/////////////////////////////////
SellCond2=IIf ((ADX(14)>20 AND ADX(14)>Ref(ADX(14),-1)) OR V>EMA(V,20),
C<EMA(C,30)
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND trendscore<-5
AND TMF<0 //OR (TMF>0 AND C<0.97*EMA(C,30))
AND AroonDn>70
,(EMA(C,5)<0.97*EMA(C,63))
//AND Close<Open
//AND EMA(percentR(14),30)<-50
//AND AroonDn>70
//AND TMF<0
//AND trendscore<-5
)
;
///////////////////////////Filter/////////////////////////////////
Filter=C>5;
//EMA(V,20)*EMA(C,20)>50000;
AddColumn( ADX(14), "ADX", 1.2 );
AddColumn( C, "C", 1.2 );
AddColumn( V, "V", 1.2 );
AddColumn( EMA(V,20), "EMAV20", 1.2 );
AddColumn( EMA(V,20)*EMA(C,20), "V*C", 1.2 );
_SECTION_END();
Buy = ((BuyCond1 AND BuyCond2) OR (BuyCond2 AND BuyCond1));
Sell = ((SellCond1 AND SellCond2) OR (SellCond2 AND SellCond1));
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=Sell;
Cover=Buy;
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, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);