Home › Forums › Trading System Mentor Course Community › Trading System Brainstorming › Trading System Graveyard
- This topic is empty.
-
AuthorPosts
-
April 12, 2017 at 11:48 pm #106621LeeDanelloParticipant
Elder Triple Screen Wise Stocktrader
Code:// Elder Triple Screen Trading System.// This scan finds candidates by the Weekly MACD Historgam slope, and the Daily 2 Period Force Index dipping above or below it’s Zero Line. Plot a Weekly 26 Period EMA to
// help confirm the weekly direction. It should be rising along with an uptick on the Weekly MACD Histogram to go long. However, Elder writes that divergences in the MACD
// Histogram override the EMA. The Daily 2 Period Force Index will be below it’s Zero Line. Look for the stock to pullback to around it’s Daily 13 Period EMA. Also use the
// Daily 22 Period EMA to confirm the direction of the daily trend. Do the opposite for shorts. Use the Long/Short EMA Weekly Direction Tabs as filters to cull through the
// scan to only display the Weekly EMA going in the intended trading direction. Use the Long/Short Elder Ray Tabs (BullPower AND BearPower) to fine tune the entry signals.
// This tab is best used when in agreement with the Long/Short EMA Weekly Direction Tabs. A 50 Period EMA > 100000 is used to Filter Volume. A minimum of a 5 point run in
// one Month is used as a Filter for a stock’s range. This scan is best used as an Exploration.TimeFrameSet( inWeekly );
WeeklyMACD = MACD(12,26) – Signal(12,26,9);
WeekHistRising = Ref(WeeklyMACD, -1) < Ref(WeeklyMACD, 0); WeekHistFalling = Ref(WeeklyMACD, -1) > Ref(WeeklyMACD, 0);
FIWeekly = EMA(V*(C-Ref(C,-1)),13);
WeeklyForceIndexLong = FIWeekly > 0;
WeeklyForceIndexShort = FIWeekly < 0; TimeFrameRestore(); // Weekly criteria MACDLongW = WeekHistRising; MACDShortW= WeekHistFalling; FILongW = WeeklyForceIndexLong; FIShortW = WeeklyForceIndexShort; // Daily criteria FIDaily = EMA(V*(C-Ref(C,-1)),2); FILongD = FIDaily < 0; FIShortD = FIDaily > 0;
VFilter = EMA(V,50) > 100000;
TenTwentyFilter = HHV(H,20)-LLV(L,20); // How much price has gone in one month (>=10 points preferable)
FiftyDayHVFilter = round(StDev(log(C/Ref(C,-1)),50)*100*sqrt(256)); // One year volotility (>=40 preferable)
bullpower= High – EMA(Close,13);
bearpower= Low – EMA(Close,13);// Scan criteria
ElderLong = MACDLongW AND FILongD AND FILongW;
ElderShort = MACDShortW AND FIShortD AND FIShortW;// Columns for exploration
NumColumns = 12;
Column0 = FullName();
Column0Name = “Ticker name”;Column1 = ” “;
Column1Name =” “;Column2 = ElderLong;
Column2Name = “Long”;Column3 = ElderLong AND EMA(C,130) > Ref(EMA(C,130),-5);
Column3Name = “Long EMA Weekly Direction”;Column4 = Column3 AND (bearpower < 0 AND bullpower > 0);
Column4Name = “Long Elder Ray Filter”;Column5 = ” “;
Column5Name =” “;Column6 = ElderShort;
Column6Name = “Short”;Column7 = ElderShort AND EMA(C,130) < Ref(EMA(C,130),-5); Column7Name = "Short EMA Weekly Direction"; Column8 = Column7 AND (bearpower < 0 AND bullpower > 0);
Column8Name = “Short Elder Ray Filter”;Column9 = ” “;
Column9Name =” “;Column10 = TenTwentyFilter;
Column10Name = “One Month Point Range”;Column11 = FiftyDayHVFilter;
Column11Name = “Historical Volotility 50 Day”;AddTextColumn( IndustryID(1), “Industry” );
AddTextColumn( MarketID(1), “Market” );
// Filters
Filter = VFilter AND (ElderLong OR ElderShort);
Buy = ElderLong;
Sell = 0;
Short = ElderShort;
Cover = 0;// ———————————————————————————————————————-
// Charts — (cut and paste the chart/indicator to it’s own window with it’s own file name and remove the Remark Slashes “//”, except
// for the first line, this line desctibes the chart function. Example…leave “//Weekly Bar Chart” from the following first line as as.// Weekly Bar Chart
_SECTION_BEGIN(“Weekly Graph”);
TimeFrameSet( inWeekly );
wo = O;
wh = H;
wl = L;
wc = C;
TimeFrameRestore();
PlotOHLC( wo, wh, wl, wc, “Weekly Close”, colorCustom9, styleBar );
_SECTION_END();_SECTION_BEGIN(“EMA”);
P = ParamField(“Price field”,-1);
Periods = Param(“Periods”, 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( “Color”, colorYellow ), ParamStyle(“Style”) );
_SECTION_END();// ———————————————————————————————————————-
// Weekly Force Index 13 Chart
_SECTION_BEGIN(“Weekly Force Index Thirteen Period”);
TimeFrameSet( inWeekly );
FI=EMA(V*(C-Ref(C,-1)),13);
TimeFrameRestore();
Plot(FI,”FI”,colorCustom11,styleLine);
Plot(0,”ZERO LINE”,colorWhite,styleThick);
_SECTION_END();// ———————————————————————————————————————-
// Weekly MACD Histogran
_SECTION_BEGIN(“Weekly MACD”);
TimeFrameSet( inWeekly );
MACDw = MACD( 12, 26 ) – Signal( 12, 26, 9 );
MACDwLINE = MACD( 12, 26 ) ;
MACDwSignal = Signal( 12, 26, 9 );
TimeFrameRestore();
Plot(MACDw,”MACD Weekly”,colorYellow,styleHistogram);
Plot(MACDwLINE,”MACD Weekly Line”,colorRed,styleLine);
Plot(MACDwSignal,”MACD Weekly Signal Line”,colorBlue,styleLine);
_SECTION_END();// ———————————————————————————————————————-
// Daily Bar Chart
_SECTION_BEGIN(“Elder Daily Chart with Envelope”);
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( EMA(C,13),”EMA(13)”,colorRed,styleLine);
PlotForeign(GetBaseIndex(),IndustryID(1),colorWhite,styleLine|styleLeftAxisScale);
LookBkPd = 100 ;
AvgPd = 22 ;
ExternalBarPct = 15 ;
ConvergePct = 2 ;
Middle = EMA( C,AvgPd ) ;
Rng = HHV( H,LookBkPd ) – LLV( L,LookBkPd ) ;
X = Rng ;
deltaX = X/2 ;
do
{
Over = H > Middle + X ;
Under = L < Middle - X ; OuterPct = 100*( Sum( Over, LookBkPd ) + Sum( Under, LookBkPd ) )/LookBkPd ; OP = LastValue(OuterPct) ; Y= X + sign( OP - ExternalBarPct )*deltaX; }while ( sign( OP - ExternalBarPct ) > ConvergePct ) ;
Plot( Middle, “MA”, colorYellow, styleLine|styleNoTitle ) ;
Plot( Middle+Y, “MA”, colorSkyblue, styleDashed|styleNoTitle ) ;
Plot( Middle-Y, “MA”, colorSkyblue, styleDashed|styleNoTitle ) ;
_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”, colorCustom9 ), styleBar | ParamStyle(“Style”) | GetPriceStyle() );
_SECTION_END();// ———————————————————————————————————————-
// Daily Force Index 2 Period
_SECTION_BEGIN(“Force Index 2 Day”);
FI=EMA(V*(C-Ref(C,-1)),2);
Plot(FI,”FI”,colorCustom11,styleLine);
Plot(0,”ZERO LINE”,colorWhite,styleThick);
_SECTION_END();// ———————————————————————————————————————-
// Daily MACD Histogram
_SECTION_BEGIN(“MACD”);
r1 = Param( “Fast avg”, 12, 2, 200, 1 );
r2 = Param( “Slow avg”, 26, 2, 200, 1 );
r3 = Param( “Signal avg”, 9, 2, 200, 1 );
Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+”(%g,%g)”, r1, r2), ParamColor(“MACD color”, colorRed ), ParamStyle(“MACD style”) );
Plot( sl = Signal(r1,r2,r3), “Signal” + _PARAM_VALUES(), ParamColor(“Signal color”, colorBlue ), ParamStyle(“Signal style”) );
Plot( ml-sl, “MACD Histogram”, ParamColor(“Histogram color”, colorBlack ), styleNoTitle | ParamStyle(“Histogram style”, styleHistogram | styleNoLabel, maskHistogram ) );
_SECTION_END();// ———————————————————————————————————————-
// Daily BullPower
_SECTION_BEGIN(“Bull Power EMA”);
/*Bull Power*/
Lookback = Param (“EMA Lookback”,13);
BullPower = High – EMA(Close,Lookback);
Plot (BullPower, “”, ParamColor (“Color”, colorCustom11), styleHistogram );
Title = Name() + ” ” + Date() + ” Bull Power” + WriteVal (Lookback, 3.0) + ” Day: ” + WriteVal (BullPower, 5.3);
GraphXSpace = 5;
_SECTION_END();// ———————————————————————————————————————-
// Daily BearPower
_SECTION_BEGIN(“Bear Power EMA”);
/*Bear Power*/
Lookback = Param (“EMA Lookback”, 13);
BearPower = Low – EMA(Close,Lookback);
Plot (BearPower, “”, ParamColor (“Color”, colorRed), styleHistogram );
Title = Name() + ” ” + Date() + ” Bear Power” + WriteVal (Lookback, 3.0) + ” Day: ” + WriteVal (BearPower, 5.3);
GraphXSpace = 5;
_SECTION_END();// End ———————————————————————————————————————
April 14, 2017 at 3:57 am #106615LeeDanelloParticipantJulian Cohen wrote:Maurice Petterlin wrote:Looking for a discarded rotational system.here’s One for you maurice. I ran it for a few months but it went into hard drawdown so I stopped it. Fairly basic. I haven’t found a rotational system that I want to run yet. I feel better using WTT variants instead.
Code:/*
Gap Filter 25% over 100 days
Entry C>MA(200) and ADX(10)>=30
Index Filter 150 daysIf Index Filter is green on last day of month then OK to buy.
*/
#include_once “FormulasNorgate DataNorgate Data Functions.afl”
_SECTION_BEGIN(“Index Filter”);
//=====================================================================
//Index Filter
//=====================================================================
“”;
“Index Filter”;
IndexTog = ParamToggle(“Index Filter”,”On|Off”,0);
IndexCode = ParamStr(“Index Symbol”,”$XAO.AU”);
Index = Foreign(IndexCode,”C”);
IndMA = Param(“Index Filter MA”,200,75,200,25);
IndexFilterUp = Index > MA(Index,IndMA);
IndexUp = IIf(IndexTog,1,IndexFilterUp);
//=====================================================================
_SECTION_END();_SECTION_BEGIN(“Gap Filter”);
//=========================================================
// Gap Filter
//=========================================================
“nGap filter:”;
gapTog = ParamToggle(“Gap Filter”,”On|Off”,0);
gapPercent = Param(“Gap %”,15,5,40,5);
gapPeriod = Param(“Gap Up Lookback”,100,10,150,5);
priceField1 = C;
priceField2 = Ref(C,-1);
ratio = ((priceField1-priceField2)/priceField2)*100;gap = (GapUp() OR GapDown()) AND abs(ratio) >= gapPercent;
gapNumber = Sum(gap,gapPeriod);
gapFilter = gapNumber == 0;
gapFilterOn = IIf(gapTog,1,gapFilter);
//=========================================================
_SECTION_END();_SECTION_BEGIN(“Historical Data Base Testing”);
//=================================================================================
//Historical Data Base Testing
//=================================================================================
ASXList = ParamList(“ASX Historical Watchlist:”,”1: Off|2: ASX 20|3: ASX 50|4: ASX 100|5: ASX 200|6: ASX 300|7: ASX All Ordinaries|8: ASX Small Ordinaries|9: ASX Emerging Companies|10: Excluding ASX 300″,4);HistDB = 1;
if(ASXList == “1: Off”) HistDB = 1;
if(ASXList == “2: ASX 20”) HistDB = NorgateIndexConstituentTimeSeries(“$XTL”);
if(ASXList == “3: ASX 50”) HistDB = NorgateIndexConstituentTimeSeries(“$XFL”);
if(ASXList == “4: ASX 100”) HistDB = NorgateIndexConstituentTimeSeries(“$XTO”);
if(ASXList == “5: ASX 200”) HistDB = NorgateIndexConstituentTimeSeries(“$XJO”);
if(ASXList == “6: ASX 300”) HistDB = NorgateIndexConstituentTimeSeries(“$XKO”);
if(ASXList == “7: ASX All Ordinaries”) HistDB = NorgateIndexConstituentTimeSeries(“$XAO”);
if(ASXList == “8: ASX Small Ordinaries”) HistDB = NorgateIndexConstituentTimeSeries(“$XSO”);
if(ASXList == “9: ASX Emerging Companies”) HistDB = NorgateIndexConstituentTimeSeries(“$XEC”);
if(ASXList == “10: Excluding ASX 300”) HistDB = NorgateIndexConstituentTimeSeries(“$XKO”)==0;//———————————————————————————
USList = ParamList(“US Historical Watchlist:”,”1: Off|2: Russell 1000|3: Russell 2000|4: Russell 3000|5: NASDAQ 100|6: Dow Jones Industrial Average|7: S&P 500|8: S&P 100|9: S&P MidCap 400|10: S&P SmallCap 600|11: S&P 1500|12: Russell MicroCap|13: Russell MidCap|14: Russell 2000 Excluding S&P 500|15: Russell 1000 Excluding S&P 500″,0);USHistDB = 1;
if(USList == “1: Off”) USHistDB = 1;
if(USList == “2: Russell 1000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUI”);
if(USList == “3: Russell 2000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUT”);
if(USList == “4: Russell 3000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUA”);
if(USList == “5: NASDAQ 100”) USHistDB = NorgateIndexConstituentTimeSeries(“$NDX”);
if(USList == “6: Dow Jones Industrial Average”) USHistDB = NorgateIndexConstituentTimeSeries(“$DJI”);
if(USList == “7: S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$SPX”);
if(USList == “8: S&P 100”) USHistDB = NorgateIndexConstituentTimeSeries(“$OEX”);
if(USList == “9: S&P MidCap 400”) USHistDB = NorgateIndexConstituentTimeSeries(“$MID”);
if(USList == “10: S&P SmallCap 600”) USHistDB = NorgateIndexConstituentTimeSeries(“$SML”);
if(USList == “11: S&P 1500”) USHistDB = NorgateIndexConstituentTimeSeries(“$SP1500”);
if(USList == “12: Russell MicroCap”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUMIC”);
if(USList == “13: Russell MidCap”) USHistDB = NorgateIndexConstituentTimeSeries(“$RMC”);
if(USList == “14: Russell 2000 Excluding S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUT”) AND NOT NorgateIndexConstituentTimeSeries(“$SPX”);
if(USList == “15: Russell 1000 Excluding S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUI”) AND NOT NorgateIndexConstituentTimeSeries(“$SPX”);//———————————————————————————
HDBFilter = HistDB AND USHistDB;//=================================================================================
_SECTION_END();//=================================================================================
_SECTION_END();_SECTION_BEGIN(“Universe Filter”);
//=====================================================================
//Universe Filter
//=====================================================================
“”;
“Universe Filter:”;
Universe = ParamList(“Universe Filter:”,”1: Off|2: Rescources|3: Industrials”,0);
UniverseFilter = 1;
if(Universe == “1: Off”) UniverseFilter = 1;
if(Universe == “2: Rescources”) UniverserFilter = InGics(“10”) OR InGics(“151040”);
if(Universe == “3: Industrials”) UniverserFilter = InGics(“10”) == 0 AND InGics(“151040”)== 0;
//=====================================================================
_SECTION_END();_SECTION_BEGIN (“Optional Price & Volume Filters”);
//=================================================================================
//Optional Price & Volume Filters
//=================================================================================
PriceTog = ParamToggle(“Price Filter”,”Off|On”,1);
CloseToggle = ParamToggle(“Close Price”, “Adjusted|Unadjusted”,1);
CP = IIf(CloseToggle,NorgateOriginalCloseTimeSeries(),Close);
MinSP = Param(“Minimum Share Price – $”,0.20,0.00,1000,0.01);
MaxSP = Param(“Maximum Share Price – $”,150,0.00,1500,0.01);
MinMaxSP = CP >= MinSP AND CP <= MaxSP; PriceFilt = IIf(PriceTog,MinMaxSP,1); //--------------------------------------------------------------------------------- AveVolTog = ParamToggle("Average Volume Filter","Off|On",1); MinAveVol = Param("Minimum Average Volume",500000,0,10000000,1000); AVPer = Param("Volume EMA",50,1,200,1); AveVol = EMA(V,AVPer) > MinAveVol;
AveVolFilt = IIf(AveVolTog,AveVol,1);
//———————————————————————————
OptFilt = PriceFilt AND AveVolFilt;
_SECTION_END();_SECTION_BEGIN (“System Parameters”);
//=================================================================================
//Parameters
//=================================================================================
Duration = Param(“Length of ROC”,252,10,504,10);
MADuration = Param(“MA Length”,200,150,250,25);LMA = WMA(C,MADuration);
HV = 100 * StDev(log(C/Ref(C,-1)),20) * sqrt(252);//=================================================================================
//Entry & Exit
//=================================================================================
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));Cond1 = HV > 5 AND HV < 20; Cond2 = ROC(C,Duration) > 0;
Cond3 = C > LMA;
Cond4 = IndexUp AND OptFilt AND HDBFilter AND gapFilterOn;LESetup = Cond1 AND Cond2 AND Cond3 AND Cond4; //Any additional buy rules apart from the rotational criteria – e.g index, price filters etc
LE = Ref(LESetUp,-1) AND NOT OnLastTwoBarsOfDelistedSecurity;//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Backtesting Options”);
//=================================================================================
//Backtesting Parameters
//=================================================================================
posqty = Param(“# Positions”,30,1,100,1);
Eq = Param(“Initial Equity”,100000,1,10000000,1);
SetOption(“InitialEquity”,Eq);
SetOption(“MaxOpenPositions”,posqty);
SetOption(“UsePrevBarEquityForPosSizing”,True);
SetOption(“AccountMargin”,100);
SetOption(“AllowPositionShrinking”,True);
//SetOption(“WorstRankHeld”,100);
SetTradeDelays(0,0,0,0);SetBacktestMode(backtestRotational);
EOM = Month() != Ref(Month(),-1);
score = Ref(ROC(C, Duration),-1);//score is the rotational criteria
Score = IIf(LE,score,0);
PositionScore = IIf(Year()>=1985 AND EOM,score,scoreNoRotate);
//———————————————————————————
PortfRisk = Param(“% daily Portfolio Risk”, 0.2, 0, 2, 0.05);
SetPositionSize( Ref(C,-1) * PortfRisk /Ref(ATR(20),-1), spsPercentOfEquity);//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Exploration”);
//=================================================================================
//Exploration
//=================================================================================
Filter = LESetup;Capital = Param(“Account Balance”,100000,1,1000000,1);
AddTextColumn(WriteIf(LESetUp,”Buy SetUp”,””),”Entry Signal”,1.2,colorDefault,IIf(LESetUp,colorBrightGreen,colorDefault),130);
AddColumn(C * PortfRisk /ATR(21),”Position Size %”,1.2,colorDefault,colorDefault,100);
AddColumn(floor(Capital / 100 * (PortfRisk /ATR(20))),”# shares”,1,colorDefault,colorDefault,100);
AddColumn(ROC(C,Duration),”Rate of Change”,1.2);
AddColumn(C, “Closing Price”, 1.2);SetSortColumns(-6,1);
//=====================================================================
//Interpretation Window
//=====================================================================
“”;
“ROC Value: “+NumToStr(ROC(C,Duration),1);//”Breakout? “+WriteIf(Cond1==1,”Yes”,”No”);
//”Close above MA: “+WriteIf(Cond3==1,”Yes”,”No”);//=====================================================================
_SECTION_END();
_SECTION_BEGIN(“Chart Plotting”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat(“{{NAME}} – ” + FullName() + ” {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));“”;
“Chart Type:”;
ChartType = ParamList(“Chart Type”,”OHLC Bar|Candle|Line”,0);SetChartBkColor(ParamColor(“Background Colour”,colorWhite));
UpColour = ParamColor(“Bar/Candle Up Colour”,colorBrightGreen);
DownColour = ParamColor(“Bar/Candle Down Colour”,colorRed);
Colour1 = IIf(C > Ref(C,-1),UpColour,DownColour);
Colour2 = IIf(C > O,UpColour,DownColour);
Colour3 = ParamColor(“Line Chart Colour”,colorRed);
TextColour = ParamColor(“Text Colour”,colorBlack);if(ChartType == “OHLC Bar”) ChartOption = styleBar|styleThick;
if(ChartType == “Candle”) ChartOption = styleCandle;
if(ChartType == “Line”) ChartOption = styleLine;if(ChartType == “OHLC Bar”) ColourOption = Colour1;
if(ChartType == “Candle”) ColourOption = Colour2;
if(ChartType == “Line”) ColourOption = Colour3;Plot(Close,”Close”,ColourOption,styleNoTitle|ChartOption | ParamStyle(“Chart Style”));
GraphXSpace = 10;
//———————————————————————PlotShapes(shapeUpArrow*LESetUp,colorGreen,0,L,-80); //plots an arrow for the setup bar
//———————————————————————
Plot(LMA,”LMA”,colorBlue,styleLine);
//Plot(LinReg,”Linear Regression”,colorGreen,styleLine);
//———————————————————————
RibbonColour = IIf(IndexFilterUp,colorGreen,colorRed);
Rib = IIf(IndexTog,Null,1); //Links with the Index Filter.If off, nothing (null). If on, 1, which in this case is the ribbon height in percent of pane width
Plot(Rib,””,RibbonColour,styleArea|styleOwnScale|styleNoLabel,-0.00001,190); //Plots line above
//———————————————————————//=====================================================================
_SECTION_END();_SECTION_BEGIN(“Max Wait Days”);
SetCustomBacktestProc(“”);
if (Status(“action”) == actionPortfolio)
{
bo = GetBacktesterObject();
bo.Backtest();
Eqty = Foreign(“~~~Equity”, “C”);
MaxEq = Highest(Eqty);
FlatEq = BarsSince(MaxEq > Ref(MaxEq,-1));
MaxFlat = LastValue(Highest(FlatEq));
bo.AddCustomMetric(“Max Flat Eq Bars”, MaxFlat);
}_SECTION_END();
Julian,
I’ve been mucking around with the HV formula and don’t find it that beneficial. It tried this one instead and it gives much better results. I also find your max wait days to be too long. Maybe we should try and shorten that.Code:[b]// Historical Volatility
//———————————————————————————
lenPeriod = Param(“Periods”,20,5,1000,1);
HV = 100 * StDev(log(C/Ref(C,-1)),lenPeriod) * sqrt(252);
percentRanklimit = Param(“Percent Rank Limit”,90,10,100,5);
HVPercRank = PercentRank(HV,lenPeriod) >= percentRanklimit;
//———————————————————————————[/b]
//=================================================================================
//Entry & Exit
//=================================================================================
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));Cond1 =[b] HVPercRank;[/b]//HV > 5 AND HV < 20; Cond2 = ROC(C,Duration) > 0;
Cond3 = C > LMA;
Cond4 = IndexUp AND OptFilt AND HDBFilter AND gapFilterOn;April 14, 2017 at 3:59 am #106616LeeDanelloParticipantJulian Cohen wrote:Maurice Petterlin wrote:Looking for a discarded rotational system.here’s One for you maurice. I ran it for a few months but it went into hard drawdown so I stopped it. Fairly basic. I haven’t found a rotational system that I want to run yet. I feel better using WTT variants instead.
Code:/*
Gap Filter 25% over 100 days
Entry C>MA(200) and ADX(10)>=30
Index Filter 150 daysIf Index Filter is green on last day of month then OK to buy.
*/
#include_once “FormulasNorgate DataNorgate Data Functions.afl”
_SECTION_BEGIN(“Index Filter”);
//=====================================================================
//Index Filter
//=====================================================================
“”;
“Index Filter”;
IndexTog = ParamToggle(“Index Filter”,”On|Off”,0);
IndexCode = ParamStr(“Index Symbol”,”$XAO.AU”);
Index = Foreign(IndexCode,”C”);
IndMA = Param(“Index Filter MA”,200,75,200,25);
IndexFilterUp = Index > MA(Index,IndMA);
IndexUp = IIf(IndexTog,1,IndexFilterUp);
//=====================================================================
_SECTION_END();_SECTION_BEGIN(“Gap Filter”);
//=========================================================
// Gap Filter
//=========================================================
“nGap filter:”;
gapTog = ParamToggle(“Gap Filter”,”On|Off”,0);
gapPercent = Param(“Gap %”,15,5,40,5);
gapPeriod = Param(“Gap Up Lookback”,100,10,150,5);
priceField1 = C;
priceField2 = Ref(C,-1);
ratio = ((priceField1-priceField2)/priceField2)*100;gap = (GapUp() OR GapDown()) AND abs(ratio) >= gapPercent;
gapNumber = Sum(gap,gapPeriod);
gapFilter = gapNumber == 0;
gapFilterOn = IIf(gapTog,1,gapFilter);
//=========================================================
_SECTION_END();_SECTION_BEGIN(“Historical Data Base Testing”);
//=================================================================================
//Historical Data Base Testing
//=================================================================================
ASXList = ParamList(“ASX Historical Watchlist:”,”1: Off|2: ASX 20|3: ASX 50|4: ASX 100|5: ASX 200|6: ASX 300|7: ASX All Ordinaries|8: ASX Small Ordinaries|9: ASX Emerging Companies|10: Excluding ASX 300″,4);HistDB = 1;
if(ASXList == “1: Off”) HistDB = 1;
if(ASXList == “2: ASX 20”) HistDB = NorgateIndexConstituentTimeSeries(“$XTL”);
if(ASXList == “3: ASX 50”) HistDB = NorgateIndexConstituentTimeSeries(“$XFL”);
if(ASXList == “4: ASX 100”) HistDB = NorgateIndexConstituentTimeSeries(“$XTO”);
if(ASXList == “5: ASX 200”) HistDB = NorgateIndexConstituentTimeSeries(“$XJO”);
if(ASXList == “6: ASX 300”) HistDB = NorgateIndexConstituentTimeSeries(“$XKO”);
if(ASXList == “7: ASX All Ordinaries”) HistDB = NorgateIndexConstituentTimeSeries(“$XAO”);
if(ASXList == “8: ASX Small Ordinaries”) HistDB = NorgateIndexConstituentTimeSeries(“$XSO”);
if(ASXList == “9: ASX Emerging Companies”) HistDB = NorgateIndexConstituentTimeSeries(“$XEC”);
if(ASXList == “10: Excluding ASX 300”) HistDB = NorgateIndexConstituentTimeSeries(“$XKO”)==0;//———————————————————————————
USList = ParamList(“US Historical Watchlist:”,”1: Off|2: Russell 1000|3: Russell 2000|4: Russell 3000|5: NASDAQ 100|6: Dow Jones Industrial Average|7: S&P 500|8: S&P 100|9: S&P MidCap 400|10: S&P SmallCap 600|11: S&P 1500|12: Russell MicroCap|13: Russell MidCap|14: Russell 2000 Excluding S&P 500|15: Russell 1000 Excluding S&P 500″,0);USHistDB = 1;
if(USList == “1: Off”) USHistDB = 1;
if(USList == “2: Russell 1000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUI”);
if(USList == “3: Russell 2000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUT”);
if(USList == “4: Russell 3000”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUA”);
if(USList == “5: NASDAQ 100”) USHistDB = NorgateIndexConstituentTimeSeries(“$NDX”);
if(USList == “6: Dow Jones Industrial Average”) USHistDB = NorgateIndexConstituentTimeSeries(“$DJI”);
if(USList == “7: S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$SPX”);
if(USList == “8: S&P 100”) USHistDB = NorgateIndexConstituentTimeSeries(“$OEX”);
if(USList == “9: S&P MidCap 400”) USHistDB = NorgateIndexConstituentTimeSeries(“$MID”);
if(USList == “10: S&P SmallCap 600”) USHistDB = NorgateIndexConstituentTimeSeries(“$SML”);
if(USList == “11: S&P 1500”) USHistDB = NorgateIndexConstituentTimeSeries(“$SP1500”);
if(USList == “12: Russell MicroCap”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUMIC”);
if(USList == “13: Russell MidCap”) USHistDB = NorgateIndexConstituentTimeSeries(“$RMC”);
if(USList == “14: Russell 2000 Excluding S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUT”) AND NOT NorgateIndexConstituentTimeSeries(“$SPX”);
if(USList == “15: Russell 1000 Excluding S&P 500”) USHistDB = NorgateIndexConstituentTimeSeries(“$RUI”) AND NOT NorgateIndexConstituentTimeSeries(“$SPX”);//———————————————————————————
HDBFilter = HistDB AND USHistDB;//=================================================================================
_SECTION_END();//=================================================================================
_SECTION_END();_SECTION_BEGIN(“Universe Filter”);
//=====================================================================
//Universe Filter
//=====================================================================
“”;
“Universe Filter:”;
Universe = ParamList(“Universe Filter:”,”1: Off|2: Rescources|3: Industrials”,0);
UniverseFilter = 1;
if(Universe == “1: Off”) UniverseFilter = 1;
if(Universe == “2: Rescources”) UniverserFilter = InGics(“10”) OR InGics(“151040”);
if(Universe == “3: Industrials”) UniverserFilter = InGics(“10”) == 0 AND InGics(“151040”)== 0;
//=====================================================================
_SECTION_END();_SECTION_BEGIN (“Optional Price & Volume Filters”);
//=================================================================================
//Optional Price & Volume Filters
//=================================================================================
PriceTog = ParamToggle(“Price Filter”,”Off|On”,1);
CloseToggle = ParamToggle(“Close Price”, “Adjusted|Unadjusted”,1);
CP = IIf(CloseToggle,NorgateOriginalCloseTimeSeries(),Close);
MinSP = Param(“Minimum Share Price – $”,0.20,0.00,1000,0.01);
MaxSP = Param(“Maximum Share Price – $”,150,0.00,1500,0.01);
MinMaxSP = CP >= MinSP AND CP <= MaxSP; PriceFilt = IIf(PriceTog,MinMaxSP,1); //--------------------------------------------------------------------------------- AveVolTog = ParamToggle("Average Volume Filter","Off|On",1); MinAveVol = Param("Minimum Average Volume",500000,0,10000000,1000); AVPer = Param("Volume EMA",50,1,200,1); AveVol = EMA(V,AVPer) > MinAveVol;
AveVolFilt = IIf(AveVolTog,AveVol,1);
//———————————————————————————
OptFilt = PriceFilt AND AveVolFilt;
_SECTION_END();_SECTION_BEGIN (“System Parameters”);
//=================================================================================
//Parameters
//=================================================================================
Duration = Param(“Length of ROC”,252,10,504,10);
MADuration = Param(“MA Length”,200,150,250,25);LMA = WMA(C,MADuration);
HV = 100 * StDev(log(C/Ref(C,-1)),20) * sqrt(252);//=================================================================================
//Entry & Exit
//=================================================================================
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));Cond1 = HV > 5 AND HV < 20; Cond2 = ROC(C,Duration) > 0;
Cond3 = C > LMA;
Cond4 = IndexUp AND OptFilt AND HDBFilter AND gapFilterOn;LESetup = Cond1 AND Cond2 AND Cond3 AND Cond4; //Any additional buy rules apart from the rotational criteria – e.g index, price filters etc
LE = Ref(LESetUp,-1) AND NOT OnLastTwoBarsOfDelistedSecurity;//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Backtesting Options”);
//=================================================================================
//Backtesting Parameters
//=================================================================================
posqty = Param(“# Positions”,30,1,100,1);
Eq = Param(“Initial Equity”,100000,1,10000000,1);
SetOption(“InitialEquity”,Eq);
SetOption(“MaxOpenPositions”,posqty);
SetOption(“UsePrevBarEquityForPosSizing”,True);
SetOption(“AccountMargin”,100);
SetOption(“AllowPositionShrinking”,True);
//SetOption(“WorstRankHeld”,100);
SetTradeDelays(0,0,0,0);SetBacktestMode(backtestRotational);
EOM = Month() != Ref(Month(),-1);
score = Ref(ROC(C, Duration),-1);//score is the rotational criteria
Score = IIf(LE,score,0);
PositionScore = IIf(Year()>=1985 AND EOM,score,scoreNoRotate);
//———————————————————————————
PortfRisk = Param(“% daily Portfolio Risk”, 0.2, 0, 2, 0.05);
SetPositionSize( Ref(C,-1) * PortfRisk /Ref(ATR(20),-1), spsPercentOfEquity);//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Exploration”);
//=================================================================================
//Exploration
//=================================================================================
Filter = LESetup;Capital = Param(“Account Balance”,100000,1,1000000,1);
AddTextColumn(WriteIf(LESetUp,”Buy SetUp”,””),”Entry Signal”,1.2,colorDefault,IIf(LESetUp,colorBrightGreen,colorDefault),130);
AddColumn(C * PortfRisk /ATR(21),”Position Size %”,1.2,colorDefault,colorDefault,100);
AddColumn(floor(Capital / 100 * (PortfRisk /ATR(20))),”# shares”,1,colorDefault,colorDefault,100);
AddColumn(ROC(C,Duration),”Rate of Change”,1.2);
AddColumn(C, “Closing Price”, 1.2);SetSortColumns(-6,1);
//=====================================================================
//Interpretation Window
//=====================================================================
“”;
“ROC Value: “+NumToStr(ROC(C,Duration),1);//”Breakout? “+WriteIf(Cond1==1,”Yes”,”No”);
//”Close above MA: “+WriteIf(Cond3==1,”Yes”,”No”);//=====================================================================
_SECTION_END();
_SECTION_BEGIN(“Chart Plotting”);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat(“{{NAME}} – ” + FullName() + ” {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}”, O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));“”;
“Chart Type:”;
ChartType = ParamList(“Chart Type”,”OHLC Bar|Candle|Line”,0);SetChartBkColor(ParamColor(“Background Colour”,colorWhite));
UpColour = ParamColor(“Bar/Candle Up Colour”,colorBrightGreen);
DownColour = ParamColor(“Bar/Candle Down Colour”,colorRed);
Colour1 = IIf(C > Ref(C,-1),UpColour,DownColour);
Colour2 = IIf(C > O,UpColour,DownColour);
Colour3 = ParamColor(“Line Chart Colour”,colorRed);
TextColour = ParamColor(“Text Colour”,colorBlack);if(ChartType == “OHLC Bar”) ChartOption = styleBar|styleThick;
if(ChartType == “Candle”) ChartOption = styleCandle;
if(ChartType == “Line”) ChartOption = styleLine;if(ChartType == “OHLC Bar”) ColourOption = Colour1;
if(ChartType == “Candle”) ColourOption = Colour2;
if(ChartType == “Line”) ColourOption = Colour3;Plot(Close,”Close”,ColourOption,styleNoTitle|ChartOption | ParamStyle(“Chart Style”));
GraphXSpace = 10;
//———————————————————————PlotShapes(shapeUpArrow*LESetUp,colorGreen,0,L,-80); //plots an arrow for the setup bar
//———————————————————————
Plot(LMA,”LMA”,colorBlue,styleLine);
//Plot(LinReg,”Linear Regression”,colorGreen,styleLine);
//———————————————————————
RibbonColour = IIf(IndexFilterUp,colorGreen,colorRed);
Rib = IIf(IndexTog,Null,1); //Links with the Index Filter.If off, nothing (null). If on, 1, which in this case is the ribbon height in percent of pane width
Plot(Rib,””,RibbonColour,styleArea|styleOwnScale|styleNoLabel,-0.00001,190); //Plots line above
//———————————————————————//=====================================================================
_SECTION_END();_SECTION_BEGIN(“Max Wait Days”);
SetCustomBacktestProc(“”);
if (Status(“action”) == actionPortfolio)
{
bo = GetBacktesterObject();
bo.Backtest();
Eqty = Foreign(“~~~Equity”, “C”);
MaxEq = Highest(Eqty);
FlatEq = BarsSince(MaxEq > Ref(MaxEq,-1));
MaxFlat = LastValue(Highest(FlatEq));
bo.AddCustomMetric(“Max Flat Eq Bars”, MaxFlat);
}_SECTION_END();
Julian,
I’ve been mucking around with the HV formula and don’t find it that beneficial. It tried this one instead and it gives much better results. I also find your max wait days to be too long. Maybe we should try and shorten that.Code:// Historical Volatility
//———————————————————————————
lenPeriod = Param(“Periods”,20,5,1000,1);
HV = 100 * StDev(log(C/Ref(C,-1)),lenPeriod) * sqrt(252);
percentRanklimit = Param(“Percent Rank Limit”,90,10,100,5);
HVPercRank = PercentRank(HV,lenPeriod) >= percentRanklimit;
//———————————————————————————
//=================================================================================
//Entry & Exit
//=================================================================================
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));Cond1 = HVPercRank;//HV > 5 AND HV < 20; Cond2 = ROC(C,Duration) > 0;
Cond3 = C > LMA;
Cond4 = IndexUp AND OptFilt AND HDBFilter AND gapFilterOn;
Sorry double post. Tried bolding code changes but it didn’t workApril 14, 2017 at 10:29 pm #106622JulianCohenParticipantMaurice it’s probably better to remove the HV completely. I didn’t make notes so I’m not sure why I added it in the first place
April 17, 2017 at 10:38 am #106623SaidBitarMemberOne thing I noticed about rotational momentum systems that they work on the US stocks better that ASX stocks. weekly TF system on the ASX will give better results than momentum system. Regarding the US stocks still weekly TF can give better results but also if you want less volatility then momentum is better.
here are the results from my Momentum strategy on the SP500 (It is still on the waiting list to go live)
the test duration is from 01/01/2000 till todaythere are not huge returns but the volatility is so low.
April 17, 2017 at 10:54 am #106635SaidBitarMemberI ran the same system on the ASX200 no idea why I was thinking it is not good and the WTT is better :whistle:
here are the results from 2000 until today
price filters from 0.2$ till 1000$
No volume filter (I imagine the ASX 200 is liquid enough for a monthly system)I will take a look at my code again but if everything looks Ok then this will go to the waiting list as well 👿
April 17, 2017 at 11:10 am #106637ScottMcNabParticipantInteresting that seems to be a lower correlation than I would have imagined between two longer term strategies in US and ASX..nice to run them both if have low correlation
April 17, 2017 at 11:26 am #106638SaidBitarMemberSaid Bitar wrote:I ran the same system on the ASX200 no idea why I was thinking it is not good and the WTT is better :whistle:here are the results from 2000 until today
price filters from 0.2$ till 1000$
No volume filter (I imagine the ASX 200 is liquid enough for a monthly system)I will take a look at my code again but if everything looks Ok then this will go to the waiting list as well 👿
PFFFT
I found the mistake
I believe the code is correct but when testing the ASX 200 i forgot to pick the universe here are the correct resultsnow makes more sense
April 17, 2017 at 9:23 pm #106636LEONARDZIRParticipantSaid. Those are outstanding results for your momentum strategy on the sp500. A car of 19% and max dd of 16% is excellent. The best I could do on the sp500 was car 15% and. Dd of 23%.
What did you use to define momentum? I only used ROC.April 17, 2017 at 10:04 pm #106642Nick RadgeKeymasterAgree with Len. That drawdown is excellent.
April 18, 2017 at 7:05 am #106644SaidBitarMemberI wish that i am on my computer to attach some graphs that will make my point easier.
but here how it goes
The system that i am using is the one that most are using with ROC ranking
but there are two scenarios there are stocks that will achieve their performance and they have the price action all over the place and other that will move up steadily and slowly.so what i am catching are the ones that are only going up slow and steady
the way to measure this is by using ATR as measure I know that the value of ATR is dependent on the price so the ATR of 5$ stock is not like the ATR of 100$ stock. the way to come over this is by dividing the ROC by ATRso i am ranking using ROC(C, Duration)/ATR(Duration)
here is the code so that you can test
score = Ref(ROC(C,Duration)/ATR(Duration),-1);
score = iif(LE,score,0);
positionscore = iif(year()>=1985 AND Month() != ref(Month(),-1),score,scoreNoRotate);also i am using volatility based position sizing
give it a try and tell me your finidings
April 18, 2017 at 10:16 am #106646SaidBitarMemberadvantages of living next to office
here are the snapshots
Case 1:
case 2:
both of them are candidates for the system but with the modifications i am making sure to capture the first one and not the second
April 18, 2017 at 11:50 am #106647LEONARDZIRParticipantSaid,
Are you using the same duration for ROC and ATR?
LenApril 18, 2017 at 3:27 pm #106648SaidBitarMemberyes
the reason is that i do not like to have many parameters in the system.
maybe other settings will give better results but this is ok for meApril 18, 2017 at 9:00 pm #106601LEONARDZIRParticipantSaid,
I substituted roc/atr for roc but didn’t get much improvement on the sp500. I used ROC(200),ATR(200) 30 positions with risk of 0.2, price 10-110 from 2000 until today.Ended up with CAR/MDD of 15/20.
I am not the most proficient of coders so perhaps that is where the error lies. I have included some of my code for you to take a look._SECTION_BEGIN (“System Parameters”);
//=================================================================================
//Parameters
//=================================================================================
//MYROC = Param(“ROC periods”,200,10,260,10);
//MYROC = Optimize(“ROC periods”,240,10,260,10);
//SetOption(“ExtraColumnsLocation”,1);
//MYROC2 = ROC( Close,MYROC);GpP = Param(“Gap %”,15,1,200,0.01);
GpD = Param(“Gap Up Lookback”,100,1,1000,1);
PF1 = C;
PF2 = Ref(C,-1);
R1 = ((PF1-PF2)/PF2)*100;G1 = GapUp() AND R1 > GpP;
GapNum = Sum(G1,GpD);
GapFilt = GapNum == 0;MyDuration =Param(“ROC and ATR”,200,10,260,10);
//ROCDURATION = ROC(MyDuration);
//ATRDuration = ATR(MyDuration);//=================================================================================
//Entry & Exit
//=================================================================================
Cond1 = Close > MA(C,100);
Cond2 = ROC(C,MyDuration)> 0;
Cond3 = OptFilt AND IndexUp AND HDBFilter AND GapFilt;//all the optional filtersOnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
LESetup = Cond1 AND Cond2 AND Cond3; //Any additional buy rules apart from the rotational criteria – e.g index, price filters etc
LE = Ref(LESetUp,-1) AND NOT OnLastTwoBarsOfDelistedSecurity;
// MCS code part2
if(MCP)
LE = LE && Random()*100>=MCP;
//=================================================================================
_SECTION_END();_SECTION_BEGIN (“Backtesting Options”);
//=================================================================================
//Backtesting Parameters close
//=================================================================================
posqty = Param(“# Positions”,30,1,100,1);
Eq = Param(“Initial Equity”,100000,1,10000000,1);
SetOption(“InitialEquity”,Eq);
SetOption(“MaxOpenPositions”,posqty);
SetOption(“UsePrevBarEquityForPosSizing”,True);
SetOption(“AccountMargin”,100);
SetOption(“AllowPositionShrinking”,True);
//SetOption(“WorstRankHeld”,100);
SetTradeDelays(0,0,0,0);SetBacktestMode(backtestRotational);
EOM = Month() != Ref(Month(),-1);
//score = Ref(MYROC2,-1) ;//score is the rotational criteria
//Score = IIf(LE,score,0);
//PositionScore = IIf(Year()>=1985 AND EOM,score,scoreNoRotate);
score = Ref(ROC(C,MyDuration)/ATR(14),-1);
score = iif(LE,score,0);
positionscore = iif(year()>=1985 AND Month() != ref(Month(),-1),score,scoreNoRotate);//
//SetPositionSize(100/posqty,spsPercentOfEquity);
Riskfactor = Param(“Risk Factor”,0.2,0.005,1,0.005);Risk = Riskfactor*(Ref(C,-1)/Ref(ATR(21),-1));
SetPositionSize(Risk,spsPercentOfEquity);
-
AuthorPosts
- You must be logged in to reply to this topic.