Pathfinder Trading System
Forums › ProRealTime English forum › ProOrder support › Pathfinder Trading System
- This topic has 1,834 replies, 139 voices, and was last updated 1 year ago by CFD AutoTrading.
Tagged: Pathfinder
-
-
10/10/2016 at 7:33 AM #1453810/12/2016 at 5:33 PM #14787I try to improve Pathfinder for instruments with changing trends and big moves on both sides. Hang Seng index is such an instrument that is perfect suitable for testing. I’m a little bit confused about the backtest result > 4.000% profit in 4 years. I never traded HS and therefore the question to the HS pros: Is that realistic?123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245// Breakout system triggered by previous daily, weekly and monthly high/low crossings with smart position management// Version 5 Beta 3// Instrument: Hang Seng mini 4H, 2:15-16:45 CET, 6 points spread, account size 10.000 Euro// ProOrder code parameterDEFPARAM CUMULATEORDERS = true // cumulate orders if not turned offDEFPARAM PRELOADBARS = 10000// define intraday trading windowONCE startTime = 21500ONCE endTime = 164500// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 8// define filter parameterONCE periodLongMA = 380ONCE periodShortMA = 30// define position and money management parameterONCE positionSize = 1Capital = 10000Risk = 5 // in %equity = Capital + StrategyProfitmaxRisk = round(equity * Risk / 100)ONCE stopLossLong = 3.25 // in %ONCE stopLossShort = 2.75 // in %ONCE takeProfitLong = 2 // in %ONCE takeProfitShort = 2.25 // in %maxPositionSizeLong = MAX(5, abs(round(maxRisk / (close * stopLossLong / 100) / PointValue) * pipsize))maxPositionSizeShort = MAX(5, abs(round(maxRisk / (close * stopLossShort / 100) / PointValue) * pipsize))ONCE trailingStartLong = 1.75 // in %ONCE trailingStartShort = 1 // in %ONCE trailingStepLong = 0.2 // in %ONCE trailingStepShort = 0.2 // in %ONCE maxCandlesLongWithProfit = 20 // take long profit latest after 20 candlesONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candlesONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles 30ONCE maxCandlesShortWithoutProfit = 6 // limit short loss latest after 6 candles// define saisonal position multiplier >0 - long / <0 - short / 0 no tradeONCE January = 2ONCE February = 2ONCE March = 2ONCE April = 3ONCE May = 2ONCE June = 2ONCE July = 3ONCE August = -1ONCE September = -2ONCE October = 1ONCE November = 3ONCE December = 3// calculate daily high/low (include sunday values if available)dailyHigh = DHigh(1)dailyLow = DLow(1)// calculate weekly high/lowIf DayOfWeek < DayOfWeek[1] thenweeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)lastWeekBarIndex = BarIndexENDIF// calculate monthly high/lowIf Month <> Month[1] thenmonthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)lastMonthBarIndex = BarIndexENDIF// calculate instrument signalline with multiple smoothed averagesfirstMA = WilderAverage[periodFirstMA](close)secondMA = TimeSeriesAverage[periodSecondMA](firstMA)signalline = TimeSeriesAverage[periodThirdMA](secondMA)// save position before trading window is openIf Time < startTime thenstartPositionLong = COUNTOFLONGSHARESstartPositionShort = COUNTOFSHORTSHARESEndIF// trade only in defined trading windowIF Time >= startTime AND Time <= endTime THEN// set saisonal patternIF CurrentMonth = 1 THENsaisonalPatternMultiplier = JanuaryELSIF CurrentMonth = 2 THENsaisonalPatternMultiplier = FebruaryELSIF CurrentMonth = 3 THENsaisonalPatternMultiplier = MarchELSIF CurrentMonth = 4 THENsaisonalPatternMultiplier = AprilELSIF CurrentMonth = 5 THENsaisonalPatternMultiplier = MayELSIF CurrentMonth = 6 THENsaisonalPatternMultiplier = JuneELSIF CurrentMonth = 7 THENsaisonalPatternMultiplier = JulyELSIF CurrentMonth = 8 THENsaisonalPatternMultiplier = AugustELSIF CurrentMonth = 9 THENsaisonalPatternMultiplier = SeptemberELSIF CurrentMonth = 10 THENsaisonalPatternMultiplier = OctoberELSIF CurrentMonth = 11 THENsaisonalPatternMultiplier = NovemberELSIF CurrentMonth = 12 THENsaisonalPatternMultiplier = DecemberENDIF// define trading filters// 1. use fast and slow averages as filter because not every breakout is profitablef1 = close > Average[periodLongMA](close)f2 = close < Average[periodLongMA](close)f3 = close > Average[periodShortMA](close)f4 = signalline < Average[periodshortMA](close)// 2. check if position already reduced in trading window as additonal filter criteriaalreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLongalreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort// long position conditionsl1 = signalline CROSSES OVER monthlyHighl2 = signalline CROSSES OVER weeklyHighl3 = signalline CROSSES OVER dailyHighl4 = signalline CROSSES OVER monthlyLow// short position conditionss1 = signalline CROSSES UNDER monthlyHighs4 = signalline CROSSES UNDER dailyHighs5 = signalline CROSSES UNDER dailyLow// long entry with order cumulationIF ( (l1 OR l4 OR l2 OR (l3 AND f2) ) AND NOT alreadyReducedLongPosition) THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier > 0 THENIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossLongtakeProfit = takeProfitLongENDIF// short entry with order cumulationIF ((s1 AND f3) OR (s5 AND f1) OR (f4 AND (s4 AND f2)) ) AND NOT alreadyReducedShortPosition THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier < 0 THENIF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THENSELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENSELLSHORT positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossShorttakeProfit = takeProfitShortENDIF// stop and profit managementIF LONGONMARKET THENposProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsizeELSIF SHORTONMARKET THENposProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsizeENDIFm1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfitm2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfitm3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfitm4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit// take profit after max candlesIF LONGONMARKET AND (m1 OR m3) THENSELL AT MARKETENDIFIF SHORTONMARKET AND (m2 OR m4) THENEXITSHORT AT MARKETENDIF// trailing stop functiontrailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100// reset the stoploss valueIF NOT ONMARKET THENnewSL = 0ENDIF// manage long positionsIF LONGONMARKET THEN// first move (breakeven)IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THENnewSL = tradeprice(1) + trailingStepLongInPoints * pipsizeENDIF// next movesIF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THENnewSL = newSL + trailingStepLongInPoints * pipsizeENDIFENDIF// manage short positionsIF SHORTONMARKET THEN// first move (breakeven)IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THENnewSL = tradeprice(1) - trailingStepShortInPoints * pipsizeENDIF// next movesIF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THENnewSL = newSL - trailingStepShortInPoints * pipsizeENDIFENDIF// stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF// superordinate stop and take profitSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfitENDIF1<span lang="en"> </span>
1 user thanked author for this post.
10/12/2016 at 7:56 PM #14793I think the hang seng index is for us Europeans to trade or difficult to follow. It would be more useful to examine in addition to the FTSE100 and DAX Wall street and then begin to see better OIL, GOLD and SILVER. As always good job Reiner. thank you.
Miguel
10/12/2016 at 9:19 PM #14794Ok, it’s clear now. Hang Seng backtest results are in HK$ and this mean that initial capital has to converted to HK$ as well (multiplied by 10). The performance is around 400% and not 4.000%. Sorry for the confusion.
@miguel: as mentioned above the topic isn’t to develop a fancy Hang Seng backtest, the aim is to improve the results under “stormy” conditions. Hang Seng had a wild ride over the last 3 -4 years and is perfect to hardening Pathfinders behavior esspecially in tough downtrends.10/12/2016 at 9:49 PM #1479510/13/2016 at 1:16 AM #1480110/13/2016 at 7:38 AM #1480310/13/2016 at 7:43 AM #1480610/13/2016 at 8:50 AM #1480910/13/2016 at 12:15 PM #14832I have seen that some guys are interested to test Pathfinder V5 with Hang Seng in demo mode.
Here is an improved backtest version. Spread of 10 points is now a more realistic value and the drawdown looks much better now. Nevertheless drawdown is significant but the return is also exceptionally good . I recommend 100.000 HKD as capital. Tests did show that it’s important for the result to let it run until 1600 (New York’s open).
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246// Pathfinder Trading System based on ProRealTime 10.2// Breakout system triggered by previous daily, weekly and monthly high/low crossings with smart position management// Version 5 Beta 3// Instrument: Hang Seng mini 4H, 2:15-16:00 CET, 10 points spread, account size 100.000 HKD// ProOrder code parameterDEFPARAM CUMULATEORDERS = true // cumulate orders if not turned offDEFPARAM PRELOADBARS = 10000// define intraday trading windowONCE startTime = 21500ONCE endTime = 160000// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 8// define filter parameterONCE periodLongMA = 380ONCE periodShortMA = 30// define position and money management parameterONCE positionSize = 1Capital = 10000Risk = 5 // in %equity = Capital + StrategyProfitmaxRisk = round(equity * Risk / 100)ONCE stopLossLong = 3.25 // in %ONCE stopLossShort = 2 // in %ONCE takeProfitLong = 2.25 // in %ONCE takeProfitShort = 2.25 // in %maxPositionSizeLong = MAX(6, abs(round(maxRisk / (close * stopLossLong / 100) / PointValue) * pipsize))maxPositionSizeShort = MAX(6, abs(round(maxRisk / (close * stopLossShort / 100) / PointValue) * pipsize))ONCE trailingStartLong = 1.75 // in %ONCE trailingStartShort = 1 // in %ONCE trailingStepLong = 0.2 // in %ONCE trailingStepShort = 0.2 // in %ONCE maxCandlesLongWithProfit = 20 // take long profit latest after 20 candlesONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candlesONCE maxCandlesLongWithoutProfit = 25 // limit long loss latest after 25 candlesONCE maxCandlesShortWithoutProfit = 6 // limit short loss latest after 6 candles// define saisonal position multiplier >0 - long / <0 - short / 0 no tradeONCE January = 1ONCE February = 1ONCE March = 1ONCE April = 3ONCE May = 1ONCE June = 1ONCE July = 3ONCE August = -1ONCE September = -2ONCE October = 1ONCE November = 3ONCE December = 2// calculate daily high/low (include sunday values if available)dailyHigh = DHigh(1)dailyLow = DLow(1)// calculate weekly high/lowIf DayOfWeek < DayOfWeek[1] thenweeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)lastWeekBarIndex = BarIndexENDIF// calculate monthly high/lowIf Month <> Month[1] thenmonthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)lastMonthBarIndex = BarIndexENDIF// calculate instrument signalline with multiple smoothed averagesfirstMA = WilderAverage[periodFirstMA](close)secondMA = TimeSeriesAverage[periodSecondMA](firstMA)signalline = TimeSeriesAverage[periodThirdMA](secondMA)// save position before trading window is openIf Time < startTime thenstartPositionLong = COUNTOFLONGSHARESstartPositionShort = COUNTOFSHORTSHARESEndIF// trade only in defined trading windowIF Time >= startTime AND Time <= endTime THEN// set saisonal patternIF CurrentMonth = 1 THENsaisonalPatternMultiplier = JanuaryELSIF CurrentMonth = 2 THENsaisonalPatternMultiplier = FebruaryELSIF CurrentMonth = 3 THENsaisonalPatternMultiplier = MarchELSIF CurrentMonth = 4 THENsaisonalPatternMultiplier = AprilELSIF CurrentMonth = 5 THENsaisonalPatternMultiplier = MayELSIF CurrentMonth = 6 THENsaisonalPatternMultiplier = JuneELSIF CurrentMonth = 7 THENsaisonalPatternMultiplier = JulyELSIF CurrentMonth = 8 THENsaisonalPatternMultiplier = AugustELSIF CurrentMonth = 9 THENsaisonalPatternMultiplier = SeptemberELSIF CurrentMonth = 10 THENsaisonalPatternMultiplier = OctoberELSIF CurrentMonth = 11 THENsaisonalPatternMultiplier = NovemberELSIF CurrentMonth = 12 THENsaisonalPatternMultiplier = DecemberENDIF// define trading filters// 1. use fast and slow averages as filter because not every breakout is profitablef1 = close > Average[periodLongMA](close)f2 = close < Average[periodLongMA](close)f3 = close > Average[periodShortMA](close)f4 = signalline < Average[periodshortMA](close)// 2. check if position already reduced in trading window as additonal filter criteriaalreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLongalreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort// long position conditionsl1 = signalline CROSSES OVER monthlyHighl2 = signalline CROSSES OVER weeklyHighl3 = signalline CROSSES OVER dailyHighl4 = signalline CROSSES OVER monthlyLow// short position conditionss1 = signalline CROSSES UNDER monthlyHighs4 = signalline CROSSES UNDER dailyHighs5 = signalline CROSSES UNDER dailyLow// long entry with order cumulationIF ( (l1 OR l4 OR l2 OR (l3 AND f2) ) AND NOT alreadyReducedLongPosition) THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier > 0 THENIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossLongtakeProfit = takeProfitLongENDIF// short entry with order cumulationIF ((s1 AND f3) OR (s5 AND f1) OR (f4 AND (s4 AND f2)) ) AND NOT alreadyReducedShortPosition THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier < 0 THENIF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THENSELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENSELLSHORT positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossShorttakeProfit = takeProfitShortENDIF// stop and profit managementIF LONGONMARKET THENposProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsizeELSIF SHORTONMARKET THENposProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsizeENDIFm1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfitm2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfitm3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfitm4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit// take profit after max candlesIF LONGONMARKET AND (m1 OR m3) THENSELL AT MARKETENDIFIF SHORTONMARKET AND (m2 OR m4) THENEXITSHORT AT MARKETENDIF// trailing stop functiontrailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100// reset the stoploss valueIF NOT ONMARKET THENnewSL = 0ENDIF// manage long positionsIF LONGONMARKET THEN// first move (breakeven)IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THENnewSL = tradeprice(1) + trailingStepLongInPoints * pipsizeENDIF// next movesIF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THENnewSL = newSL + trailingStepLongInPoints * pipsizeENDIFENDIF// manage short positionsIF SHORTONMARKET THEN// first move (breakeven)IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THENnewSL = tradeprice(1) - trailingStepShortInPoints * pipsizeENDIF// next movesIF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THENnewSL = newSL - trailingStepShortInPoints * pipsizeENDIFENDIF// stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF// superordinate stop and take profitSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfitENDIF10/13/2016 at 9:28 PM #1487710/14/2016 at 10:05 AM #14891hey reiner,
ich würde gerne dabei helfen pathfinder für andere instrumente anzupassen, aber es gibt so viele variablen die man anpassen kann, dass ich gar nicht weiß wo ich anfangen soll/kann/muss.
bei dir scheint das ja immer recht gut zu funktionieren 😉 hast du mir vllt einen tipp in welcher reihenfolge du dabei vorgehst?
danke
flo
10/14/2016 at 2:25 PM #14906Here is a first Pathfinder version for Gold mini. It would be great if somebody with longer history could verify the backtest result. Return (300% in 4 years) and drawdown (<20%) are OK but number of profitable trades is best case 66%. Pathfinder loses money as probable many systems when long term trend changes (7 loosers in a row Feb-March 16). Please be aware that the minimum contract size for Gold mini is 10 contracts.
Gold won’t be my favorit for Pathfinder.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246// Pathfinder Trading System based on ProRealTime 10.2// Breakout system triggered by previous daily, weekly and monthly high/low crossings with smart position management// Version 5 Beta 3// Instrument: Gold mini 4H, 2-22 CET, 0.3 points spread, account size 10.000 Euro// ProOrder code parameterDEFPARAM CUMULATEORDERS = true // cumulate orders if not turned offDEFPARAM PRELOADBARS = 10000// define intraday trading windowONCE startTime = 20000ONCE endTime = 220000// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 7// define filter parameterONCE periodLongMA = 270ONCE periodShortMA = 40// define position and money management parameterONCE positionSize = 10 // 10 contracts are the minimum size for Gold miniCapital = 10000Risk = 5 // in %equity = Capital + StrategyProfitmaxRisk = round(equity * Risk / 100)ONCE stopLossLong = 3.25 // in %ONCE stopLossShort = 2.75 // in %ONCE takeProfitLong = 2 // in %ONCE takeProfitShort = 4 // in %maxPositionSizeLong = MAX(40, abs(round(maxRisk / (close * stopLossLong / 100) / PointValue) * pipsize))maxPositionSizeShort = MAX(40, abs(round(maxRisk / (close * stopLossShort / 100) / PointValue) * pipsize))ONCE trailingStartLong = 1 // in %ONCE trailingStartShort = 2 // in %ONCE trailingStepLong = 0.7 // in %ONCE trailingStepShort = 0.7 // in %ONCE maxCandlesLongWithProfit = 20 // take long profit latest after 20 candlesONCE maxCandlesShortWithProfit = 20 // take short profit latest after 13 candlesONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles 30ONCE maxCandlesShortWithoutProfit = 14 // limit short loss latest after 6 candles// define saisonal position multiplier >0 - long / <0 - short / 0 no tradeONCE January = 2ONCE February = 2ONCE March = -1ONCE April = 1ONCE May = 1ONCE June = 2ONCE July = 3ONCE August = 2ONCE September = 3ONCE October = -2ONCE November = 1ONCE December = 1// calculate daily high/low (include sunday values if available)dailyHigh = DHigh(1)dailyLow = DLow(1)// calculate weekly high/lowIf DayOfWeek < DayOfWeek[1] thenweeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)lastWeekBarIndex = BarIndexENDIF// calculate monthly high/lowIf Month <> Month[1] thenmonthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)lastMonthBarIndex = BarIndexENDIF// calculate instrument signalline with multiple smoothed averagesfirstMA = WilderAverage[periodFirstMA](close)secondMA = TimeSeriesAverage[periodSecondMA](firstMA)signalline = TimeSeriesAverage[periodThirdMA](secondMA)// save position before trading window is openIf Time < startTime thenstartPositionLong = COUNTOFLONGSHARESstartPositionShort = COUNTOFSHORTSHARESEndIF// trade only in defined trading windowIF Time >= startTime AND Time <= endTime THEN// set saisonal patternIF CurrentMonth = 1 THENsaisonalPatternMultiplier = JanuaryELSIF CurrentMonth = 2 THENsaisonalPatternMultiplier = FebruaryELSIF CurrentMonth = 3 THENsaisonalPatternMultiplier = MarchELSIF CurrentMonth = 4 THENsaisonalPatternMultiplier = AprilELSIF CurrentMonth = 5 THENsaisonalPatternMultiplier = MayELSIF CurrentMonth = 6 THENsaisonalPatternMultiplier = JuneELSIF CurrentMonth = 7 THENsaisonalPatternMultiplier = JulyELSIF CurrentMonth = 8 THENsaisonalPatternMultiplier = AugustELSIF CurrentMonth = 9 THENsaisonalPatternMultiplier = SeptemberELSIF CurrentMonth = 10 THENsaisonalPatternMultiplier = OctoberELSIF CurrentMonth = 11 THENsaisonalPatternMultiplier = NovemberELSIF CurrentMonth = 12 THENsaisonalPatternMultiplier = DecemberENDIF// define trading filters// 1. use fast and slow averages as filter because not every breakout is profitablef1 = close > Average[periodLongMA](close)f2 = close < Average[periodLongMA](close)f3 = close > Average[periodShortMA](close)f4 = signalline < Average[periodshortMA](close)// 2. check if position already reduced in trading window as additonal filter criteriaalreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLongalreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort// long position conditionsl1 = signalline CROSSES OVER monthlyHighl2 = signalline CROSSES OVER weeklyHighl3 = signalline CROSSES OVER dailyHighl4 = signalline CROSSES OVER monthlyLow// short position conditionss1 = signalline CROSSES UNDER monthlyHighs4 = signalline CROSSES UNDER dailyHighs5 = signalline CROSSES UNDER dailyLow// long entry with order cumulationIF ( (l1 OR l4 OR l2 OR (l3 AND f2) ) AND NOT alreadyReducedLongPosition) THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier > 0 THENIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossLongtakeProfit = takeProfitLongENDIF// short entry with order cumulationIF ((s1 AND f3) OR (s5 AND f1) OR (f4 AND (s4 AND f2)) ) AND NOT alreadyReducedShortPosition THEN// check saisonal booster setup and max position sizeIF saisonalPatternMultiplier < 0 THENIF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THENSELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENSELLSHORT positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stopLossShorttakeProfit = takeProfitShortENDIF// stop and profit managementIF LONGONMARKET THENposProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsizeELSIF SHORTONMARKET THENposProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsizeENDIFm1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfitm2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfitm3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfitm4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit// take profit after max candlesIF LONGONMARKET AND (m1 OR m3) THENSELL AT MARKETENDIFIF SHORTONMARKET AND (m2 OR m4) THENEXITSHORT AT MARKETENDIF// trailing stop functiontrailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100// reset the stoploss valueIF NOT ONMARKET THENnewSL = 0ENDIF// manage long positionsIF LONGONMARKET THEN// first move (breakeven)IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THENnewSL = tradeprice(1) + trailingStepLongInPoints * pipsizeENDIF// next movesIF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THENnewSL = newSL + trailingStepLongInPoints * pipsizeENDIFENDIF// manage short positionsIF SHORTONMARKET THEN// first move (breakeven)IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THENnewSL = tradeprice(1) - trailingStepShortInPoints * pipsizeENDIF// next movesIF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THENnewSL = newSL - trailingStepShortInPoints * pipsizeENDIFENDIF// stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF// superordinate stop and take profitSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfitENDIF1 user thanked author for this post.
10/14/2016 at 4:08 PM #1490910/14/2016 at 4:10 PM #14910 -
AuthorPosts
Find exclusive trading pro-tools on