Home › Forums › Trading System Mentor Course Community › Trading System Brainstorming › Group Collaboration System Ideas
- This topic is empty.
-
AuthorPosts
-
May 22, 2016 at 10:58 pm #104046LeeDanelloParticipant
Hi Darryl,
What’s the gapFilter that you’re using?
Code:cond1 = C > longMA;
cond2 = L < bolliBot; cond3 = bolliWidth > bolliWidthMin;
cond4 = optionalFilter AND HDBFilter AND volFilter AND gapFilter;Those numbers are looking promising
May 23, 2016 at 7:53 am #104047SaidBitarMemberLooks much better now
May 23, 2016 at 8:06 am #103739ScottMcNabParticipantNice stats…will try…Thanks Darryl..
May 23, 2016 at 8:21 am #104048AnonymousInactiveMaurice Petterlin wrote:Hi Darryl,What’s the gapFilter that you’re using?
Those numbers are looking promisingHi Maurice
I got it from a post Nick made some time ago regarding clenow’s strategy:Code:_SECTION_BEGIN(“Gap Filter”);
//=========================================================
// Gap Filter
//=========================================================
“nGap filter:”;
gapTog = ParamToggle(“Gap Filter”,”On|Off”,0);
gapPercent = Param(“Gap %”,15,10,100,1);
gapPeriod = Param(“Gap Up Lookback”,100,20,100,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();May 23, 2016 at 1:21 pm #103740ChrisViridesMemberSince my last post I have been trying to get similar CAR/MDD ratios as you guys. Can you guys see anything in my code that is logically wrong. I have inserted all of it except the Chart Plotting.
Thanks in advance, its probably something super simple that is staring right at my blind self.
Please also see Parameters as well as Single Backtest Screenshot:
Universe: Russell 1000
Dates: 1/1/2000 – 1/1/2016Code://The rules are as follows:
// – No index Filter
// – Min average Volume is 500K
// – Close is above MA 100 days
// – BB (5,1.5)
// – Close bellow the lower band
// – BB width is greater than 5% (BBWidth = (BBTop – BBBot)/ BBBot *100;)
// – Buy on limit order if the price drops a bit under the low (0.5ATR(10))
// – Sell cross with MA 5days_SECTION_BEGIN(“Monte Carlo Coding”);
// MCS Monte Carlo Part 1 of 2
Runs = Param(“Number of Runs”,100,0,100000,100);
Run = Optimize(“Run”,1,1,Runs,1);
MCP = Param(“Probability of Ignoring any Entry Signal %”,5,1,100,1);
function RandPercent(percent)
{
perc = percent/100;
rand = 1+(perc – mtRandom() * (perc*2));
return rand;
}
MCRP = Param(“Random Percent”,2.5,1,100,1);
_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|11: In XAO but Exc ASX 100|12: Exc XAO”,0);HistDB = 1; //set to 1 to start
if(ASXList == “1: Off”) HistDB = 1;
if(ASXList == “2: ASX 20”) HistDB = IsIndexConstituent(“$XTL”);
if(ASXList == “3: ASX 50”) HistDB = IsIndexConstituent(“$XFL”);
if(ASXList == “4: ASX 100”) HistDB = IsIndexConstituent(“$XTO”);
if(ASXList == “5: ASX 200”) HistDB = IsIndexConstituent(“$XJO”);
if(ASXList == “6: ASX 300”) HistDB = IsIndexConstituent(“$XKO”);
if(ASXList == “7: ASX All Ordinaries”) HistDB = IsIndexConstituent(“$XAO”);
if(ASXList == “8: ASX Small Ordinaries”) HistDB = IsIndexConstituent(“$XKO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “9: ASX Emerging Companies”) HistDB = IsIndexConstituent(“$XEC”);
if(ASXList == “10: Excluding ASX 300”) HistDB = IsIndexConstituent(“$XKO”) == 0;
if(ASXList == “11: In XAO but Exc ASX 100”) HistDB = IsIndexConstituent(“$XAO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “12: Exc XAO”) HistDB = IsIndexConstituent(“$XAO”) == 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”,0);USHistDB = 1; //set to 1 to start
if(USList == “1: Off”) USHistDB = 1;
if(USList == “2: Russell 1000”) USHistDB = IsIndexConstituent(“$RUI”);
if(USList == “3: Russell 2000”) USHistDB = IsIndexConstituent(“$RUT”);
if(USList == “4: Russell 3000”) USHistDB = IsIndexConstituent(“$RUA”);
if(USList == “5: NASDAQ 100”) USHistDB = IsIndexConstituent(“$NDX”);
if(USList == “6: Dow Jones Industrial Average”) USHistDB = IsIndexConstituent(“$DJI”);
if(USList == “7: S&P 500”) USHistDB = IsIndexConstituent(“$SPX”);
if(USList == “8: S&P 100”) USHistDB = IsIndexConstituent(“$OEX”);
if(USList == “9: S&P MidCap 400”) USHistDB = IsIndexConstituent(“$MID”);
if(USList == “10: S&P SmallCap 600”) USHistDB = IsIndexConstituent(“$SML”);
if(USList == “11: S&P 1500”) USHistDB = IsIndexConstituent(“$SP1500”);
if(USList == “12: Russell MicroCap”) USHistDB = IsIndexConstituent(“$RUMIC”);
if(USList == “12: Russell MidCap”) USHistDB = IsIndexConstituent(“$RMC”);//————————————————————————–
HDBFilter = HistDB AND USHistDB; //combine both lists for a filter//==========================================================================
_SECTION_END();_SECTION_BEGIN(“Index Filter”);
//============================================================================
//Index Filter
//============================================================================
“”;
“Index Filter:”;
IndexTog = ParamToggle(“Index Filter”,”Off|On”, 0);
IndexCode = ParamStr(“Index Symbol”,”$XAO.asx”);
Index = Foreign(IndexCode, “Close”);
IndexMA = Param(“Index Filter MA”, 200,2,1000,1);
IndexFilterUp = Index > MA(Index,IndexMA);
IndexUp = IIf(IndexTog, IndexFilterUp, 1 );
//============================================================================
_SECTION_END();//===========================================================================
//Optional Price, Volume and Liquidity Filters
//===========================================================================
_SECTION_BEGIN(“Price Filter (Optional)”);
PriceTog = ParamToggle(“Price Filter”,”Off|On”, 0);
PF = ParamField(“Price Field”, 3);
MinSP = Param(“Minimum Share Price – $”, 5,0.00,1000,.01);
MaxSP = Param(“Maximum Share Price – $”, 100,0.00,1000,.01);
MinMaxSP = PF >= MinSP AND PF <= MaxSP; PriceFilt = IIf(PriceTog, MinMaxSP, 1); _SECTION_END(); _SECTION_BEGIN("Turnover Filter (Optional)"); TOTog = ParamToggle("Turnover Filter","Off|On", 0); Turnover = PF *V; MinTO = Param("Minimum Turnover - $", 500000,0,10000000,1000); TOMA = Param("Turnover MA", 7,1,200,1); AveTO = EMA(Turnover, TOMA); TOFilter = AveTO > MinTO AND Turnover > MinTO;
TOFilt = IIf(TOTog, TOFilter, 1);
_SECTION_END();_SECTION_BEGIN(“Liquidity Filter (Optional)”);
liqTog = ParamToggle(“Liquidity Filter”,”Off|On”, 0);
MinLiq = Param(“Minimum Liquidity”, 500000,0,10000000,1000);
liMA = Param(“Liquidity MA”, 7,1,200,1);
aveLiq = EMA(V, liMA);
liqFilter = aveLiq > MinLiq;
liqFilt = IIf(liqTog, liqFilter, 1);
_SECTION_END();OptFilt = PriceFilt AND TOFilt AND liqFilt;
//=================================================================================_SECTION_BEGIN(“Universe Filter”);
//============================================================================
//Universe Filter
//============================================================================
“”;
“Universe Filter:”;
Universe = ParamList(“Universe Filter:”, “1: Off|2: Resources|3: Industrials”,0);
UniverseFilter = 1;
if (Universe == “1: Off”) UniverseFilter = 1;
if (Universe == “2: Resources”) UniverseFilter = InGics(“10”) OR InGics(“151040”);
if (Universe == “3: Industrials”) UniverseFilter = InGics(“10”) == 0 AND InGics(“151040”) == 0;
//============================================================================
_SECTION_END();_SECTION_BEGIN(“Parameters”);
//=================================================================================
//Parameters
//=================================================================================
ATRPeriod = Param(“ATR Period”, 10,1,100,1);
ATRMultiply = Param(“ATR Multiplier”,0.5,0,10,.01);
SellMAParam = Param(“Sell MA Period”, 5,2,200,1);
BuyMAParam = Param(“Long MA Period”, 100,2,200,1);//=================================================================================
//BuySetup and Buy Rules
//=================================================================================
UpperBB = BBandTop(C,5,1.5);
LowerBB = BBandBot(C,5,1.5);
BBWidth = ((UpperBB – LowerBB)/ LowerBB) * 100;
ATRStop = ATR(ATRPeriod) * ATRMultiply;
IsFilter = OptFilt AND IndexUp AND UniverseFilter AND HDBFilter;Cond1 = C > MA(C, BuyMAParam);
Cond2 = C < LowerBB; Cond3 = BBWidth > 5;BuySetup = Cond1 AND Cond2 AND Cond3 AND IsFilter;
BuyStop = L – ATRStop;
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
OnSecondLastBarOfDelistedSecurity = BarIndex() == (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));//=================================================================================
//Entry and Exit Signals
//=================================================================================LE = Ref(BuySetup,-1) AND L <= Ref(BuyStop,-1) AND NOT OnLastTwoBarsOfDelistedSecurity; //Long Entry LEPrice = Min(O,Ref(BuyStop,-1)); //Entry Price //--------------------------------------------------------------------------------- //initial stop LIS = MA(C,SellMAParam); //Long Initial Stop //MCS code part 2 if (MCP) LE = LE && Random()*100 >= MCP;
Short = Cover = False;//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
LStop = Null;
//=================================================================================
for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LStop[j] = LIS[j]; LStop[j-1] = LIS[j-1]; LBIT[j] = 1; if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j]>1)
{
LStop[j] = LIS[j];
}if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}
}//———————————————————————————
InitialExit = C >= LStop;
LESetup = IIf(LBIT==0 OR Sell==1,BuySetUp,0); //Long Entry Setup
LExSetup = IIf(LBIT>0 AND Sell==0,InitialExit,0); //Long Exit Setup
//———————————————————————————
Short = Cover = False;//=================================================================================
//Exploration
//=================================================================================
Filter = Buy OR Sell OR LESetup OR LExSetup OR LBIT > 0;//=================================================================================
//Interpretation Window
//=================================================================================
AddTextColumn(WriteIf(LESetup,”Buy Setup”,””),”Entry Signal”,1.2,colorDefault,IIf(LESetup,colorBrightGreen,colorDefault),130);
AddTextColumn(WriteIf(LExSetup,”Exit”,””),”Exit Signal”,1.2,colorDefault,IIf(LExSetup,colorRed,colorDefault),100);
AddTextColumn(WriteIf(Buy,”Buy”,””),”Today’s Entries”,1.2,colorDefault,IIf(Buy,colorGreen,colorDefault),130);
AddTextColumn(WriteIf(Sell,”Sell”,””),”Today’s Exits”,1.2,colorDefault,IIf(Sell,colorRed,colorDefault),130);
AddColumn(LBIT,”LBIT”,1.0);
SetSortColumns(-3,-4,-5,-6,1);//=================================================================================
_SECTION_END();
_SECTION_BEGIN (“Backtesting”);
//=================================================================================
//Backtesting Parameters & Position Sizing
//=================================================================================
SetTradeDelays(0,0,0,0);
Capital = Param(“Initial Equity $”,100000,1000,10000000,100);
SetOption(“InitialEquity”,Capital);
MaxPos = Param(“Maxium Open Positions”,20,1,100,1);
SetOption(“MaxOpenPositions”,MaxPos);
SetPositionSize(100/MaxPos,spsPercentOfEquity);
SetOption(“CommissionMode”, 3);
SetOption(“CommissionAmount”, 0.005);
PositionScore = mtRandom();//=================================================================================
_SECTION_END();May 23, 2016 at 1:26 pm #103741LeeDanelloParticipantI’m trying to understand the logic here, especially this gapFilter = gapNumber == 0;
Code:gap = (GapUp() OR GapDown()) AND abs(ratio) >= gapPercent;
gapNumber = Sum(gap,gapPeriod);
gapFilter = gapNumber == 0;
gapFilterOn = IIf(gapTog,1,gapFilter);May 23, 2016 at 3:04 pm #104055SaidBitarMemberPaul Leavitt wrote:Since my last post I have been trying to get similar CAR/MDD ratios as you guys. Can you guys see anything in my code that is logically wrong. I have inserted all of it except the Chart Plotting.Thanks in advance, its probably something super simple that is staring right at my blind self.
Please also see Parameters as well as Single Backtest Screenshot:
Universe: Russell 1000
Dates: 1/1/2000 – 1/1/2016Code://The rules are as follows:
// – No index Filter
// – Min average Volume is 500K
// – Close is above MA 100 days
// – BB (5,1.5)
// – Close bellow the lower band
// – BB width is greater than 5% (BBWidth = (BBTop – BBBot)/ BBBot *100;)
// – Buy on limit order if the price drops a bit under the low (0.5ATR(10))
// – Sell cross with MA 5days_SECTION_BEGIN(“Monte Carlo Coding”);
// MCS Monte Carlo Part 1 of 2
Runs = Param(“Number of Runs”,100,0,100000,100);
Run = Optimize(“Run”,1,1,Runs,1);
MCP = Param(“Probability of Ignoring any Entry Signal %”,5,1,100,1);
function RandPercent(percent)
{
perc = percent/100;
rand = 1+(perc – mtRandom() * (perc*2));
return rand;
}
MCRP = Param(“Random Percent”,2.5,1,100,1);
_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|11: In XAO but Exc ASX 100|12: Exc XAO”,0);HistDB = 1; //set to 1 to start
if(ASXList == “1: Off”) HistDB = 1;
if(ASXList == “2: ASX 20”) HistDB = IsIndexConstituent(“$XTL”);
if(ASXList == “3: ASX 50”) HistDB = IsIndexConstituent(“$XFL”);
if(ASXList == “4: ASX 100”) HistDB = IsIndexConstituent(“$XTO”);
if(ASXList == “5: ASX 200”) HistDB = IsIndexConstituent(“$XJO”);
if(ASXList == “6: ASX 300”) HistDB = IsIndexConstituent(“$XKO”);
if(ASXList == “7: ASX All Ordinaries”) HistDB = IsIndexConstituent(“$XAO”);
if(ASXList == “8: ASX Small Ordinaries”) HistDB = IsIndexConstituent(“$XKO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “9: ASX Emerging Companies”) HistDB = IsIndexConstituent(“$XEC”);
if(ASXList == “10: Excluding ASX 300”) HistDB = IsIndexConstituent(“$XKO”) == 0;
if(ASXList == “11: In XAO but Exc ASX 100”) HistDB = IsIndexConstituent(“$XAO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “12: Exc XAO”) HistDB = IsIndexConstituent(“$XAO”) == 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”,0);USHistDB = 1; //set to 1 to start
if(USList == “1: Off”) USHistDB = 1;
if(USList == “2: Russell 1000”) USHistDB = IsIndexConstituent(“$RUI”);
if(USList == “3: Russell 2000”) USHistDB = IsIndexConstituent(“$RUT”);
if(USList == “4: Russell 3000”) USHistDB = IsIndexConstituent(“$RUA”);
if(USList == “5: NASDAQ 100”) USHistDB = IsIndexConstituent(“$NDX”);
if(USList == “6: Dow Jones Industrial Average”) USHistDB = IsIndexConstituent(“$DJI”);
if(USList == “7: S&P 500”) USHistDB = IsIndexConstituent(“$SPX”);
if(USList == “8: S&P 100”) USHistDB = IsIndexConstituent(“$OEX”);
if(USList == “9: S&P MidCap 400”) USHistDB = IsIndexConstituent(“$MID”);
if(USList == “10: S&P SmallCap 600”) USHistDB = IsIndexConstituent(“$SML”);
if(USList == “11: S&P 1500”) USHistDB = IsIndexConstituent(“$SP1500”);
if(USList == “12: Russell MicroCap”) USHistDB = IsIndexConstituent(“$RUMIC”);
if(USList == “12: Russell MidCap”) USHistDB = IsIndexConstituent(“$RMC”);//————————————————————————–
HDBFilter = HistDB AND USHistDB; //combine both lists for a filter//==========================================================================
_SECTION_END();_SECTION_BEGIN(“Index Filter”);
//============================================================================
//Index Filter
//============================================================================
“”;
“Index Filter:”;
IndexTog = ParamToggle(“Index Filter”,”Off|On”, 0);
IndexCode = ParamStr(“Index Symbol”,”$XAO.asx”);
Index = Foreign(IndexCode, “Close”);
IndexMA = Param(“Index Filter MA”, 200,2,1000,1);
IndexFilterUp = Index > MA(Index,IndexMA);
IndexUp = IIf(IndexTog, IndexFilterUp, 1 );
//============================================================================
_SECTION_END();//===========================================================================
//Optional Price, Volume and Liquidity Filters
//===========================================================================
_SECTION_BEGIN(“Price Filter (Optional)”);
PriceTog = ParamToggle(“Price Filter”,”Off|On”, 0);
PF = ParamField(“Price Field”, 3);
MinSP = Param(“Minimum Share Price – $”, 5,0.00,1000,.01);
MaxSP = Param(“Maximum Share Price – $”, 100,0.00,1000,.01);
MinMaxSP = PF >= MinSP AND PF <= MaxSP; PriceFilt = IIf(PriceTog, MinMaxSP, 1); _SECTION_END(); _SECTION_BEGIN("Turnover Filter (Optional)"); TOTog = ParamToggle("Turnover Filter","Off|On", 0); Turnover = PF *V; MinTO = Param("Minimum Turnover - $", 500000,0,10000000,1000); TOMA = Param("Turnover MA", 7,1,200,1); AveTO = EMA(Turnover, TOMA); TOFilter = AveTO > MinTO AND Turnover > MinTO;
TOFilt = IIf(TOTog, TOFilter, 1);
_SECTION_END();_SECTION_BEGIN(“Liquidity Filter (Optional)”);
liqTog = ParamToggle(“Liquidity Filter”,”Off|On”, 0);
MinLiq = Param(“Minimum Liquidity”, 500000,0,10000000,1000);
liMA = Param(“Liquidity MA”, 7,1,200,1);
aveLiq = EMA(V, liMA);
liqFilter = aveLiq > MinLiq;
liqFilt = IIf(liqTog, liqFilter, 1);
_SECTION_END();OptFilt = PriceFilt AND TOFilt AND liqFilt;
//=================================================================================_SECTION_BEGIN(“Universe Filter”);
//============================================================================
//Universe Filter
//============================================================================
“”;
“Universe Filter:”;
Universe = ParamList(“Universe Filter:”, “1: Off|2: Resources|3: Industrials”,0);
UniverseFilter = 1;
if (Universe == “1: Off”) UniverseFilter = 1;
if (Universe == “2: Resources”) UniverseFilter = InGics(“10”) OR InGics(“151040”);
if (Universe == “3: Industrials”) UniverseFilter = InGics(“10”) == 0 AND InGics(“151040”) == 0;
//============================================================================
_SECTION_END();_SECTION_BEGIN(“Parameters”);
//=================================================================================
//Parameters
//=================================================================================
ATRPeriod = Param(“ATR Period”, 10,1,100,1);
ATRMultiply = Param(“ATR Multiplier”,0.5,0,10,.01);
SellMAParam = Param(“Sell MA Period”, 5,2,200,1);
BuyMAParam = Param(“Long MA Period”, 100,2,200,1);//=================================================================================
//BuySetup and Buy Rules
//=================================================================================
UpperBB = BBandTop(C,5,1.5);
LowerBB = BBandBot(C,5,1.5);
BBWidth = ((UpperBB – LowerBB)/ LowerBB) * 100;
ATRStop = ATR(ATRPeriod) * ATRMultiply;
IsFilter = OptFilt AND IndexUp AND UniverseFilter AND HDBFilter;Cond1 = C > MA(C, BuyMAParam);
Cond2 = C < LowerBB; Cond3 = BBWidth > 5;BuySetup = Cond1 AND Cond2 AND Cond3 AND IsFilter;
BuyStop = L – ATRStop;
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
OnSecondLastBarOfDelistedSecurity = BarIndex() == (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));//=================================================================================
//Entry and Exit Signals
//=================================================================================LE = Ref(BuySetup,-1) AND L <= Ref(BuyStop,-1) AND NOT OnLastTwoBarsOfDelistedSecurity; //Long Entry LEPrice = Min(O,Ref(BuyStop,-1)); //Entry Price //--------------------------------------------------------------------------------- //initial stop LIS = MA(C,SellMAParam); //Long Initial Stop //MCS code part 2 if (MCP) LE = LE && Random()*100 >= MCP;
Short = Cover = False;//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
LStop = Null;
//=================================================================================
for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LStop[j] = LIS[j]; LStop[j-1] = LIS[j-1]; LBIT[j] = 1; if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j]>1)
{
LStop[j] = LIS[j];
}if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}
}//———————————————————————————
InitialExit = C >= LStop;
LESetup = IIf(LBIT==0 OR Sell==1,BuySetUp,0); //Long Entry Setup
LExSetup = IIf(LBIT>0 AND Sell==0,InitialExit,0); //Long Exit Setup
//———————————————————————————
Short = Cover = False;//=================================================================================
//Exploration
//=================================================================================
Filter = Buy OR Sell OR LESetup OR LExSetup OR LBIT > 0;//=================================================================================
//Interpretation Window
//=================================================================================
AddTextColumn(WriteIf(LESetup,”Buy Setup”,””),”Entry Signal”,1.2,colorDefault,IIf(LESetup,colorBrightGreen,colorDefault),130);
AddTextColumn(WriteIf(LExSetup,”Exit”,””),”Exit Signal”,1.2,colorDefault,IIf(LExSetup,colorRed,colorDefault),100);
AddTextColumn(WriteIf(Buy,”Buy”,””),”Today’s Entries”,1.2,colorDefault,IIf(Buy,colorGreen,colorDefault),130);
AddTextColumn(WriteIf(Sell,”Sell”,””),”Today’s Exits”,1.2,colorDefault,IIf(Sell,colorRed,colorDefault),130);
AddColumn(LBIT,”LBIT”,1.0);
SetSortColumns(-3,-4,-5,-6,1);//=================================================================================
_SECTION_END();
_SECTION_BEGIN (“Backtesting”);
//=================================================================================
//Backtesting Parameters & Position Sizing
//=================================================================================
SetTradeDelays(0,0,0,0);
Capital = Param(“Initial Equity $”,100000,1000,10000000,100);
SetOption(“InitialEquity”,Capital);
MaxPos = Param(“Maxium Open Positions”,20,1,100,1);
SetOption(“MaxOpenPositions”,MaxPos);
SetPositionSize(100/MaxPos,spsPercentOfEquity);
SetOption(“CommissionMode”, 3);
SetOption(“CommissionAmount”, 0.005);
PositionScore = mtRandom();//=================================================================================
_SECTION_END();i did not check all the code but you have this
IndexCode = ParamStr(“Index Symbol”,”$XAO.asx”);
you need to use $SPX instead
May 23, 2016 at 3:24 pm #104056SaidBitarMemberPaul Leavitt wrote:Since my last post I have been trying to get similar CAR/MDD ratios as you guys. Can you guys see anything in my code that is logically wrong. I have inserted all of it except the Chart Plotting.Thanks in advance, its probably something super simple that is staring right at my blind self.
Please also see Parameters as well as Single Backtest Screenshot:
Universe: Russell 1000
Dates: 1/1/2000 – 1/1/2016Code://The rules are as follows:
// – No index Filter
// – Min average Volume is 500K
// – Close is above MA 100 days
// – BB (5,1.5)
// – Close bellow the lower band
// – BB width is greater than 5% (BBWidth = (BBTop – BBBot)/ BBBot *100;)
// – Buy on limit order if the price drops a bit under the low (0.5ATR(10))
// – Sell cross with MA 5days_SECTION_BEGIN(“Monte Carlo Coding”);
// MCS Monte Carlo Part 1 of 2
Runs = Param(“Number of Runs”,100,0,100000,100);
Run = Optimize(“Run”,1,1,Runs,1);
MCP = Param(“Probability of Ignoring any Entry Signal %”,5,1,100,1);
function RandPercent(percent)
{
perc = percent/100;
rand = 1+(perc – mtRandom() * (perc*2));
return rand;
}
MCRP = Param(“Random Percent”,2.5,1,100,1);
_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|11: In XAO but Exc ASX 100|12: Exc XAO”,0);HistDB = 1; //set to 1 to start
if(ASXList == “1: Off”) HistDB = 1;
if(ASXList == “2: ASX 20”) HistDB = IsIndexConstituent(“$XTL”);
if(ASXList == “3: ASX 50”) HistDB = IsIndexConstituent(“$XFL”);
if(ASXList == “4: ASX 100”) HistDB = IsIndexConstituent(“$XTO”);
if(ASXList == “5: ASX 200”) HistDB = IsIndexConstituent(“$XJO”);
if(ASXList == “6: ASX 300”) HistDB = IsIndexConstituent(“$XKO”);
if(ASXList == “7: ASX All Ordinaries”) HistDB = IsIndexConstituent(“$XAO”);
if(ASXList == “8: ASX Small Ordinaries”) HistDB = IsIndexConstituent(“$XKO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “9: ASX Emerging Companies”) HistDB = IsIndexConstituent(“$XEC”);
if(ASXList == “10: Excluding ASX 300”) HistDB = IsIndexConstituent(“$XKO”) == 0;
if(ASXList == “11: In XAO but Exc ASX 100”) HistDB = IsIndexConstituent(“$XAO”) AND NOT IsIndexConstituent(“$XTO”);
if(ASXList == “12: Exc XAO”) HistDB = IsIndexConstituent(“$XAO”) == 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”,0);USHistDB = 1; //set to 1 to start
if(USList == “1: Off”) USHistDB = 1;
if(USList == “2: Russell 1000”) USHistDB = IsIndexConstituent(“$RUI”);
if(USList == “3: Russell 2000”) USHistDB = IsIndexConstituent(“$RUT”);
if(USList == “4: Russell 3000”) USHistDB = IsIndexConstituent(“$RUA”);
if(USList == “5: NASDAQ 100”) USHistDB = IsIndexConstituent(“$NDX”);
if(USList == “6: Dow Jones Industrial Average”) USHistDB = IsIndexConstituent(“$DJI”);
if(USList == “7: S&P 500”) USHistDB = IsIndexConstituent(“$SPX”);
if(USList == “8: S&P 100”) USHistDB = IsIndexConstituent(“$OEX”);
if(USList == “9: S&P MidCap 400”) USHistDB = IsIndexConstituent(“$MID”);
if(USList == “10: S&P SmallCap 600”) USHistDB = IsIndexConstituent(“$SML”);
if(USList == “11: S&P 1500”) USHistDB = IsIndexConstituent(“$SP1500”);
if(USList == “12: Russell MicroCap”) USHistDB = IsIndexConstituent(“$RUMIC”);
if(USList == “12: Russell MidCap”) USHistDB = IsIndexConstituent(“$RMC”);//————————————————————————–
HDBFilter = HistDB AND USHistDB; //combine both lists for a filter//==========================================================================
_SECTION_END();_SECTION_BEGIN(“Index Filter”);
//============================================================================
//Index Filter
//============================================================================
“”;
“Index Filter:”;
IndexTog = ParamToggle(“Index Filter”,”Off|On”, 0);
IndexCode = ParamStr(“Index Symbol”,”$XAO.asx”);
Index = Foreign(IndexCode, “Close”);
IndexMA = Param(“Index Filter MA”, 200,2,1000,1);
IndexFilterUp = Index > MA(Index,IndexMA);
IndexUp = IIf(IndexTog, IndexFilterUp, 1 );
//============================================================================
_SECTION_END();//===========================================================================
//Optional Price, Volume and Liquidity Filters
//===========================================================================
_SECTION_BEGIN(“Price Filter (Optional)”);
PriceTog = ParamToggle(“Price Filter”,”Off|On”, 0);
PF = ParamField(“Price Field”, 3);
MinSP = Param(“Minimum Share Price – $”, 5,0.00,1000,.01);
MaxSP = Param(“Maximum Share Price – $”, 100,0.00,1000,.01);
MinMaxSP = PF >= MinSP AND PF <= MaxSP; PriceFilt = IIf(PriceTog, MinMaxSP, 1); _SECTION_END(); _SECTION_BEGIN("Turnover Filter (Optional)"); TOTog = ParamToggle("Turnover Filter","Off|On", 0); Turnover = PF *V; MinTO = Param("Minimum Turnover - $", 500000,0,10000000,1000); TOMA = Param("Turnover MA", 7,1,200,1); AveTO = EMA(Turnover, TOMA); TOFilter = AveTO > MinTO AND Turnover > MinTO;
TOFilt = IIf(TOTog, TOFilter, 1);
_SECTION_END();_SECTION_BEGIN(“Liquidity Filter (Optional)”);
liqTog = ParamToggle(“Liquidity Filter”,”Off|On”, 0);
MinLiq = Param(“Minimum Liquidity”, 500000,0,10000000,1000);
liMA = Param(“Liquidity MA”, 7,1,200,1);
aveLiq = EMA(V, liMA);
liqFilter = aveLiq > MinLiq;
liqFilt = IIf(liqTog, liqFilter, 1);
_SECTION_END();OptFilt = PriceFilt AND TOFilt AND liqFilt;
//=================================================================================_SECTION_BEGIN(“Universe Filter”);
//============================================================================
//Universe Filter
//============================================================================
“”;
“Universe Filter:”;
Universe = ParamList(“Universe Filter:”, “1: Off|2: Resources|3: Industrials”,0);
UniverseFilter = 1;
if (Universe == “1: Off”) UniverseFilter = 1;
if (Universe == “2: Resources”) UniverseFilter = InGics(“10”) OR InGics(“151040”);
if (Universe == “3: Industrials”) UniverseFilter = InGics(“10”) == 0 AND InGics(“151040”) == 0;
//============================================================================
_SECTION_END();_SECTION_BEGIN(“Parameters”);
//=================================================================================
//Parameters
//=================================================================================
ATRPeriod = Param(“ATR Period”, 10,1,100,1);
ATRMultiply = Param(“ATR Multiplier”,0.5,0,10,.01);
SellMAParam = Param(“Sell MA Period”, 5,2,200,1);
BuyMAParam = Param(“Long MA Period”, 100,2,200,1);//=================================================================================
//BuySetup and Buy Rules
//=================================================================================
UpperBB = BBandTop(C,5,1.5);
LowerBB = BBandBot(C,5,1.5);
BBWidth = ((UpperBB – LowerBB)/ LowerBB) * 100;
ATRStop = ATR(ATRPeriod) * ATRMultiply;
IsFilter = OptFilt AND IndexUp AND UniverseFilter AND HDBFilter;Cond1 = C > MA(C, BuyMAParam);
Cond2 = C < LowerBB; Cond3 = BBWidth > 5;BuySetup = Cond1 AND Cond2 AND Cond3 AND IsFilter;
BuyStop = L – ATRStop;
OnLastTwoBarsOfDelistedSecurity = BarIndex() >= (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));
OnSecondLastBarOfDelistedSecurity = BarIndex() == (LastValue(BarIndex()) -1) AND !IsNull(GetFnData(“DelistingDate”));//=================================================================================
//Entry and Exit Signals
//=================================================================================LE = Ref(BuySetup,-1) AND L <= Ref(BuyStop,-1) AND NOT OnLastTwoBarsOfDelistedSecurity; //Long Entry LEPrice = Min(O,Ref(BuyStop,-1)); //Entry Price //--------------------------------------------------------------------------------- //initial stop LIS = MA(C,SellMAParam); //Long Initial Stop //MCS code part 2 if (MCP) LE = LE && Random()*100 >= MCP;
Short = Cover = False;//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
LStop = Null;
//=================================================================================
for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LStop[j] = LIS[j]; LStop[j-1] = LIS[j-1]; LBIT[j] = 1; if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j]>1)
{
LStop[j] = LIS[j];
}if (LBIT[j]>1 AND C[j-1] >= LStop[j-1] OR OnSecondLastBarOfDelistedSecurity[j])
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}
}//———————————————————————————
InitialExit = C >= LStop;
LESetup = IIf(LBIT==0 OR Sell==1,BuySetUp,0); //Long Entry Setup
LExSetup = IIf(LBIT>0 AND Sell==0,InitialExit,0); //Long Exit Setup
//———————————————————————————
Short = Cover = False;//=================================================================================
//Exploration
//=================================================================================
Filter = Buy OR Sell OR LESetup OR LExSetup OR LBIT > 0;//=================================================================================
//Interpretation Window
//=================================================================================
AddTextColumn(WriteIf(LESetup,”Buy Setup”,””),”Entry Signal”,1.2,colorDefault,IIf(LESetup,colorBrightGreen,colorDefault),130);
AddTextColumn(WriteIf(LExSetup,”Exit”,””),”Exit Signal”,1.2,colorDefault,IIf(LExSetup,colorRed,colorDefault),100);
AddTextColumn(WriteIf(Buy,”Buy”,””),”Today’s Entries”,1.2,colorDefault,IIf(Buy,colorGreen,colorDefault),130);
AddTextColumn(WriteIf(Sell,”Sell”,””),”Today’s Exits”,1.2,colorDefault,IIf(Sell,colorRed,colorDefault),130);
AddColumn(LBIT,”LBIT”,1.0);
SetSortColumns(-3,-4,-5,-6,1);//=================================================================================
_SECTION_END();
_SECTION_BEGIN (“Backtesting”);
//=================================================================================
//Backtesting Parameters & Position Sizing
//=================================================================================
SetTradeDelays(0,0,0,0);
Capital = Param(“Initial Equity $”,100000,1000,10000000,100);
SetOption(“InitialEquity”,Capital);
MaxPos = Param(“Maxium Open Positions”,20,1,100,1);
SetOption(“MaxOpenPositions”,MaxPos);
SetPositionSize(100/MaxPos,spsPercentOfEquity);
SetOption(“CommissionMode”, 3);
SetOption(“CommissionAmount”, 0.005);
PositionScore = mtRandom();//=================================================================================
_SECTION_END();the loop looks a bit different , you are trying to use the MA as trailing stop, and this is not correct because i need the value of the MA to change with each bar.
any how try this modifications
Code:if (MCP)
LE = LE && Random()*100 >= MCP;LExSetUp = Cross(C,LIS);
LEx = Ref(LExSetUp,-1);
Short = Cover = False;//=================================================================================
//Looping
//=================================================================================
Buy = 0;
Sell = 0;
PriceAtBuy = 0;
LBIT = 0;
//=================================================================================
for (j = 1; j < BarCount; j++) { if (PriceAtBuy==0 AND LE[j]) { Buy[j] = True; PriceAtBuy = LEPrice[j]; BuyPrice[j] = LEPrice[j]; LBIT[j] = 1; if (LBIT[j]>1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]) )
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}else
if (PriceAtBuy > 0)
{
LBIT[j] = LBIT[j-1]+1;if (LBIT[j]>1)
{
LStop[j] = LIS[j];
}if (LBIT[j]>1 AND (LEx[j] OR OnSecondLastBarOfDelistedSecurity[j]))
{
Sell[j] = True;
SellPrice[j] = O[j];
PriceAtBuy = 0;
}
}
}//———————————————————————————
LETrigger = IIf((LBIT==0 ) OR (Sell==1),BuySetup,0);
LExTrigger = IIf((LBIT>0 AND Sell==0),LExSetUp,0);May 23, 2016 at 3:31 pm #104057SaidBitarMemberMaurice Petterlin wrote:I’m trying to understand the logic here, especially this gapFilter = gapNumber == 0;Code:gap = (GapUp() OR GapDown()) AND abs(ratio) >= gapPercent;
gapNumber = Sum(gap,gapPeriod);
gapFilter = gapNumber == 0;
gapFilterOn = IIf(gapTog,1,gapFilter);line 1 gap is 1 if you have gap up or down and the gap percentage is greater than or equal to a pre specified value otherwise it is ZERO
line 2:
assume Today is Friday and the values were as following
Monday gap = 0
Tuesday gap = 1
wed gap = 0
Thursday gap = 0
so when you say gapnumber = sum (gap, duration) it will add the values of the gap (filter) to each other over this duration so in our case it will be Mon + Tues+WED +Thur ( 0+1+0+0) = 1line 3 : gapfilter it will check the answer from the previous step (gapnumber) and it will check if it is ZERO if yes it will return true otherwise false
line 4 : if gapfilter is on then check the value of gapfilter (to be true) if the filter is OFF then do not care about the value and return true
May 23, 2016 at 5:11 pm #104059LeeDanelloParticipantSaid Bitar wrote:Maurice Petterlin wrote:I’m trying to understand the logic here, especially this gapFilter = gapNumber == 0;Code:gap = (GapUp() OR GapDown()) AND abs(ratio) >= gapPercent;
gapNumber = Sum(gap,gapPeriod);
gapFilter = gapNumber == 0;
gapFilterOn = IIf(gapTog,1,gapFilter);line 1 gap is 1 if you have gap up or down and the gap percentage is greater than or equal to a pre specified value otherwise it is ZERO
line 2:
assume Today is Friday and the values were as following
Monday gap = 0
Tuesday gap = 1
wed gap = 0
Thursday gap = 0
so when you say gapnumber = sum (gap, duration) it will add the values of the gap (filter) to each other over this duration so in our case it will be Mon + Tues+WED +Thur ( 0+1+0+0) = 1line 3 : gapfilter it will check the answer from the previous step (gapnumber) and it will check if it is ZERO if yes it will return true otherwise false
line 4 : if gapfilter is on then check the value of gapfilter (to be true) if the filter is OFF then do not care about the value and return true
I understand line 1 and 2 but I’m lost on line 3. If gapfilter is false ie it has gaps over the lookback period, then the last line becomes
gapFilterOn = IIf(gapTog,1,0);And thats where I get lost
May 23, 2016 at 7:55 pm #104063SaidBitarMemberMaurice Petterlin wrote:I understand line 1 and 2 but I’m lost on line 3. If gapfilter is false ie it has gaps over the lookback period, then the last line becomes
gapFilterOn = IIf(gapTog,1,0);And thats where I get lost
OK suppose Condition 3 is False and this means there were gaps in the lookback duration then in Condition 4 you need to check first if the switch is on or OFF, this means if you want to check for gaps or you do not want to check for gaps.
if the switch is ON then you want to check for gaps in this case you need to check the result of Condition 3 which is false and the signal will be skipped since there was a gap while if the switch is OFF this means that you are not interested in checking for gaps and the condition result will return true all the time
May 23, 2016 at 8:00 pm #104064SaidBitarMember
honestly i tested the modification that were suggested by Darryl I did not find huge benefit for the gap filter, may be my lookback period was shorter or longer than what he used. also i found out that the ADX helps in decreasing the DD.May 23, 2016 at 9:34 pm #104065AnonymousInactiveRealised that the results I posted last time where from using 10% equity on each position. Here are the more realistic results:
using the following code as setup and entry (gapFilter removed ):
Code:// moving averages
longMALength = Param(“Long MA length”,100,50,200,10);
shortMALength = Param(“Short MA length”,5,50,200,10);
longMA = MA(C, longMALength);
shortMA = MA(C, shortMALength);// ATR and ADX setup
atrMultiplier = Param(“ATR multiplier”,1,0.5,2,0.1);
atrBuyLength = Param(“Buylimit ATR length”,10,5,30,1);
adxPeriod = Param(“ADX period”,8,8,30,2);
adxMin = Param(“ADX Min”, 30,20,60,5);// setup for bollinger bands
bolliPeriod = Param(“Bollinger Period”,5,5,100,5);
topBandStd = Param(“B-Band top”,2,1.0,3,0.2);
botBandStd = Param(“B-Band bot”,1,1.0,3,0.2);
bolliTop = BBandTop(C,bolliPeriod,topBandStd);
bolliBot = BBandBot(C,bolliPeriod,botBandStd);
bolliWidthMin = Param(“Bollinger width min”,3,1,7,1);
bolliWidth = ((bolliTop – bolliBot)/bolliBot)*100;//=========================================================
// Entry and Exit signals
//=========================================================
cond1 = C > longMA;
cond2 = L < bolliBot; cond3 = bolliWidth > bolliWidthMin;
cond4 = optionalFilter AND HDBFilter AND volFilter;
cond5 = ADX(adxPeriod) > adxMin;
buySetup = cond1 AND cond2 AND cond3 AND cond4 AND cond5;
buyLimit = C – atrMultiplier*ATR(atrBuyLength);May 23, 2016 at 10:14 pm #104068AnonymousInactiveDarryl Vink wrote:Realised that the results I posted last time where from using 10% equity on each position. Here are the more realistic results:using the following code as setup and entry (gapFilter removed ):
Code:// moving averages
longMALength = Param(“Long MA length”,100,50,200,10);
shortMALength = Param(“Short MA length”,5,50,200,10);
longMA = MA(C, longMALength);
shortMA = MA(C, shortMALength);// ATR and ADX setup
atrMultiplier = Param(“ATR multiplier”,1,0.5,2,0.1);
atrBuyLength = Param(“Buylimit ATR length”,10,5,30,1);
adxPeriod = Param(“ADX period”,8,8,30,2);
adxMin = Param(“ADX Min”, 30,20,60,5);// setup for bollinger bands
bolliPeriod = Param(“Bollinger Period”,5,5,100,5);
topBandStd = Param(“B-Band top”,2,1.0,3,0.2);
botBandStd = Param(“B-Band bot”,1,1.0,3,0.2);
bolliTop = BBandTop(C,bolliPeriod,topBandStd);
bolliBot = BBandBot(C,bolliPeriod,botBandStd);
bolliWidthMin = Param(“Bollinger width min”,3,1,7,1);
bolliWidth = ((bolliTop – bolliBot)/bolliBot)*100;//=========================================================
// Entry and Exit signals
//=========================================================
cond1 = C > longMA;
cond2 = L < bolliBot; cond3 = bolliWidth > bolliWidthMin;
cond4 = optionalFilter AND HDBFilter AND volFilter;
cond5 = ADX(adxPeriod) > adxMin;
buySetup = cond1 AND cond2 AND cond3 AND cond4 AND cond5;
buyLimit = C – atrMultiplier*ATR(atrBuyLength);And now the same with some leverage.
20 positions @ 10% of equity:May 24, 2016 at 1:03 am #103742TrentRothallParticipantHi Guys
Can someone verify my stats please i am pretty sure my codes correct. Using 20 pos at 5%
Using these parameters
-
AuthorPosts
- You must be logged in to reply to this topic.