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/04/2016 at 9:10 AM #14197
Hello everyone, I appeal especially to the more experienced, I think you have to work on the code to improve it and not waste energy on other time-frame. we must still improve and work on indexes and commodities. this and my thoughts to succeed as soon as possible. thanks and good luck to all.
Miguel
10/04/2016 at 4:13 PM #14257I like Reiners Version better because of the smaller Drawdown, but I tried to change his Version into one with variable StopLoss7Take Profit Levels for each Buy/Sell condition.
Maybe somebody is able to finde a combination of limit/sell percentages which will reduce the drawdown.
10/04/2016 at 4:15 PM #14261123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241// 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 4 - avoid reopen of intraday positions in same direction (from Miguel)// Instrument: DAX mini 4H, 8-22 CET, 2 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 = 80000ONCE endTime = 220000 // define instrument signalline with help of multiple smoothed av-eragesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 3 // define filter parameterONCE periodLongMA = 300ONCE periodShortMA = 50 // define position and money man-agement parameterONCE positionSize = 1ONCE maxPositionSizeLong = 15ONCE maxPositionSizeShort = 10ONCE stoppLossL1 = 3 // in %ONCE stoppLossL2 = 5.5 // in %ONCE stoppLossL3 = 5.5 // in %ONCE stoppLossL4 = 5.5 // in %ONCE stoppLossS1 = 2.5 // in %ONCE stoppLossS2 = 5.5 // in %ONCE takeProfitL1 = 5 // in %ONCE takeProfitL2 = 9.5 // in %ONCE takeProfitL3 = 8 // in %ONCE takeProfitL4 = 6.25 // in %ONCE takeProfitS1 = 2.5 // in %ONCE takeProfitS2 = 2.25 // in %ONCE maxCandlesLongWithProfit = 15 // take long profit latest after 15 candlesONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candlesONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candlesONCE maxCandlesShortWithoutProfit = 25 // limit short loss latest after 25 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/lowdailyHigh = 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 open #MiguelIf Time < startTime thenstartPositionLong = COUNTOFLONGSHARESstartPositionShort = COUNTOFSHORTSHARESEndIF// trade only in defined trading windowIF Time >= startTime AND Time <= endTime THEN// filter criteria because not every breakout is profitablef1 = close > Average[periodLongMA](close)f2 = close < Average[periodLongMA](close)f3 = close > Average[periodShortMA](close)// reduced position? #MiguelreduceLongInTradingWindow = COUNTOFLONGSHARES < startPositionLongreduceShortInTradingWindow = COUNTOFSHORTSHARES < startPositionShort// 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// 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 monthlyHighs2 = signalline CROSSES UNDER dailyLow// long entry (L1)IF l1 AND not reduceLongInTradingWindow THEN // cumulate orders for long trades #MiguelIF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossL1takeProfit = takeProfitL1ENDIF// long entry (L2)IF l2 AND not reduceLongInTradingWindow THEN // cumulate orders for long trades #MiguelIF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossL2takeProfit = takeProfitL2ENDIF// long entry (L3)IF ( (l3 AND f2) AND not reduceLongInTradingWindow ) THEN // cumulate orders for long trades #MiguelIF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossL3takeProfit = takeProfitL3ENDIF// long entry (L4)IF ( l4 AND not reduceLongInTradingWindow ) THEN // cumulate orders for long trades #MiguelIF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THENBUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENBUY positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossL4takeProfit = takeProfitL4ENDIF// short entry (S1)IF NOT SHORTONMARKET AND (s1 AND f3) AND not reduceShortInTradingWindow THEN // no cumulation for short trades #MiguelIF saisonalPatternMultiplier < 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THENSELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENSELLSHORT positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossS1takeProfit = takeProfitS1ENDIF// short entry (S2)IF NOT SHORTONMARKET AND (s2 AND f1) AND not reduceShortInTradingWindow THEN // no cumulation for short trades #MiguelIF saisonalPatternMultiplier < 0 THEN // check saisonal booster setup and max position sizeIF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THENSELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKETENDIFELSIF saisonalPatternMultiplier <> 0 THENIF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THENSELLSHORT positionSize CONTRACT AT MARKETENDIFENDIFstopLoss = stoppLossS2takeProfit = takeProfitS2ENDIF// stop and profit managementposProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsizem1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfitm2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfitm3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfitm4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfitIF LONGONMARKET AND (m1 OR m3) THENSELL AT MARKETENDIFIF SHORTONMARKET AND (m2 OR m4) THENEXITSHORT AT MARKETENDIFSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfitENDIF10/04/2016 at 4:16 PM #14262Someone requested trailing stop and breakeven functionality for Pathfinder. Several tests with the DAX didn’t show significant improvement of the performance. The existing framework seems to be well balanced.
Here is the code to play around:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233// 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 1 - with traling stop// Instrument: DAX mini 4H, 8-22 CET, 2 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 = 80000ONCE endTime = 220000// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 3// define filter parameterONCE periodLongMA = 300ONCE periodShortMA = 50// define position and money management parameterONCE positionSize = 1ONCE maxPositionSizeLong = 15ONCE maxPositionSizeShort = 10ONCE stopLossLong = 5.5 // in %ONCE stopLossShort = 3.5 // in %ONCE takeProfitLong = 2.75 // in %ONCE takeProfitShort = 1.75 // in %ONCE trailingStart = 1.75 // in %ONCE trailingStep = 0.2 // in %ONCE maxCandlesLongWithProfit = 15 // take long profit latest after 15 candlesONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candlesONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles 30ONCE maxCandlesShortWithoutProfit = 13 // limit short loss latest after 13 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)// 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 monthlyHighs2 = 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 without order cumulationIF NOT SHORTONMARKET AND ( (s1 AND f3) OR (s2 AND f1) ) 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 functiontrailingStartInPoints = tradeprice(1) * trailingStart / 100trailingStepInPoints = tradeprice(1) * trailingstep / 100//reset the stoploss valueIF NOT ONMARKET THENnewSL = 0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL = 0 AND close - tradeprice(1) >= trailingStartInPoints * pipsize THENnewSL = tradeprice(1) + trailingStepInPoints * pipsizeENDIF//next movesIF newSL > 0 AND close - newSL >= trailingStepInPoints * pipsize THENnewSL = newSL + trailingStepInPoints * pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL = 0 AND tradeprice(1) - close >= trailingStartInPoints * pipsize THENnewSL = tradeprice(1) - trailingStepInPoints * pipsizeENDIF//next movesIF newSL > 0 AND newSL - close >= trailingStepInPoints * pipsize THENnewSL = newSL - trailingStepInPoints * pipsizeENDIFENDIF//stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFSET STOP %LOSS stopLossSET TARGET %PROFIT takeProfitENDIF10/04/2016 at 4:18 PM #14263Maybe it is just a few single trades with high profit that make the difference, but see for yourselfs.
10/05/2016 at 9:15 AM #1427610/05/2016 at 9:55 AM #14280Hi Reiner, hi all
Thanks for this strategy and all your improvements.
Don’t you think that MaxPositionSize is a bit agressive and risky ? 15 mini with 10 000 Eur capital, you can kill your account in 3 or 4 days (for the Dax in average ,there is day move of 150pts between highest and lowest)
A newbie interested by easy money , will probably take your code without any understanding of all the details of Pathinder.
A reduction of MaxPositionSize or a more consequent capital as proposal would be safer for most of the viewers.
After for these who want to take more risks, they will do it knowingly.
Regards,
Reb
1 user thanked author for this post.
10/05/2016 at 11:13 AM #1428310/08/2016 at 7:02 AM #14467Hi Reiner, Hi all
To go beyond my previous post, I have just tested the strat (version 4 – miguel) since mai 2006:
The strat is negative until dec 2012, with a maximal loss of -14 000 eur. If you used a 10 000 eur capital , your account is dead.
Since 2013, it is very positive (see attachement), but to earn this money, you need to have more than 15 000 eur at the beginning and to be very confident (you will loose 90% of your capital and you have to wait 6.5 years before earning some money).
Reb
10/08/2016 at 8:42 AM #14470Before August 2010 the results are not really significant, because between 22:00 and 08:00 there has been no pricing. So the calculation of the number of candles is not correct and probably the calculation of the averages as well.
10/08/2016 at 4:25 PM #14487I have created a new version. Pathfinder V5 Beta 2. The version is still beta because off the ongoing discussion regarding position sizing. Here are the changes:
- fixed a bug in the profit calculation for short positions (variable posProfit)
- introduce trailing stop mechanism based on percent values (idea from MichiM, based on Nicolas work found here in the blog)
- add a filter to reduce unprofitable intraday trades (idea from Miguel)
- introduce maximal position size calculation dependent on capital and risk settings (inspired by comments from Elsborgtrading and reb)
- modify some trading parameter because of the bug fixing
changes in detail for the DAX:
- new: trailingStartLong
- new: trailingStartShort
- new: trailingStepLong
- new: trailingStepShort
Here is the code for the DAX (backtest is attached):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244// 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 2// Instrument: DAX mini 4H, 8-22 CET, 2 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 = 80000ONCE endTime = 220000// define instrument signalline with help of multiple smoothed averagesONCE periodFirstMA = 5ONCE periodSecondMA = 10ONCE periodThirdMA = 3// define filter parameterONCE periodLongMA = 300ONCE periodShortMA = 40// define position and money management parameterONCE positionSize = 1Capital = 10000Risk = 2 // in %equity = Capital + StrategyProfitmaxRisk = round(equity * Risk / 100)ONCE stopLossLong = 5.5 // in %ONCE stopLossShort = 3.5 // in %ONCE takeProfitLong = 2.75 // in %ONCE takeProfitShort = 2 // in %maxPositionSizeLong = MAX(15, 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 = 0.75 // in %ONCE trailingStepLong = 0.2 // in %ONCE trailingStepShort = 0.1 // in %ONCE maxCandlesLongWithProfit = 16 // take long profit latest after 16 candlesONCE maxCandlesShortWithProfit = 15 // take short profit latest after 15 candlesONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candlesONCE maxCandlesShortWithoutProfit = 13 // limit short loss latest after 13 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)// 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 monthlyHighs2 = 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 without order cumulationIF NOT SHORTONMARKET AND ( (s1 AND f3) OR (s2 AND f1) ) 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 takeProfitENDIF3 users thanked author for this post.
10/08/2016 at 5:33 PM #14491Hi reb,
Thanks for your contributions, I appreciate your review. You are absolutely right, 15 “naked” DAX mini contracts are too much for an 10k account. Please be aware that Pathfinder cumulated the position size only in very strong trends especially on the long side. The “signalline” has to crossed over the daily high (add pos), the weekly (add pos) and the monthly (add pos). When this extremly bullish scenario happens Pathfinder go “all in” and cumulate aggressiv the position. With the last trade the others are already in profit. This behavior is one of the booster of Pathfinder and the backtest showed since 2009 that the system were never in trouble with this logic.
I have added few lines of code in the last beta version to test the performance depending on risk and capital settings. I attached two backtests with 10k, 2% risk and at least 1 contract and 10k, 2% and at least 5 contracts to show how important it is to give Pathfinder enough room for cumulation.
I can’t judge your backtest before 2009 but I believe that the data conditions are not comparable. Any idea, review or improvement from your side is welcome.
regards
Reiner
1 user thanked author for this post.
10/08/2016 at 5:38 PM #1449210/08/2016 at 5:40 PM #1449510/09/2016 at 7:58 PM #14528Hey Reiner, Great work progressing an already great bit of code.
Thought you might like to see these. Not sure how relevant data from 2009 is for you but thought it was worth while posting…
Annoyingly, max runup/drawdown is not working for me sometimes at the moment.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on