Forum Replies Created
-
AuthorPosts
-
LeeDanelloParticipant
Thanks. Don’t trade this type system so wasn’t sure of the mechanics. So on the ASX are you always filled in the auction.
LeeDanelloParticipantSo if there are 40 signals and you can only take 30 doesn’t that introduce selection bias.
LeeDanelloParticipantposqty = Param(“# Positions”,30,1,100,1);
Why is this line in the code if there is no selection bias?
LeeDanelloParticipantSaid Bitar wrote:Julian Cohen wrote:Not quiteCode:Dur = Param(“ROC Length”,126,125,250,25);
LDur = Param(“LMA Length”,100,10,400,5);MYROC2 = ROC(C,Dur);
LMA = EMA(C,LDur);//=================================================================================
//Entry & Exit
//=================================================================================Cond1 = Close > LMA;
Cond2 = MYROC2 > 0;
Cond3 = OptFilt AND IndexUp AND HDBFilter AND gapFilter;I set the ATR and ROC duration the same.
This gave me
I thought for rotational system better not to skip any trades and take all of them as they come
So how many positions do you normally have open?
LeeDanelloParticipantTrent Rothall wrote:Len Zir wrote:_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);
Referring to the section i’ve made bold above. Won’t this cause an error or possible error. Both lines are using the identifier “Score”
Or am i wrong?
I think he likes scoring twice!
LeeDanelloParticipantThat’s going straight to the pool room
LeeDanelloParticipantconfirmed stupidity then
LeeDanelloParticipantI’m below average
51.84 out of 100LeeDanelloParticipantJulian 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 workLeeDanelloParticipantJulian 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;LeeDanelloParticipantElder 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 ———————————————————————————————————————
LeeDanelloParticipantIsn’t it all? Your fitting a trading system to a universe of stocks to profit. Maybe I should have written exploiting patterns. If it improves your results why not. Sounds like a good idea.
LeeDanelloParticipantLooking for a discarded rotational system.
LeeDanelloParticipantScott, I think that’s what I basically posted above. I’ve found that stops don’t work too well for short term systems
LeeDanelloParticipantA couple more for the gravy yard.
Nothing too imaginative here.
Both MR systems. 1st one uses the lower Bollinger band to enter, 2nd one uses consecutive lower closes and an oversold RSI.
-
AuthorPosts