ProRealCode - Trading & Coding with ProRealTime™
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
I 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.
// 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 parameter
DEFPARAM CUMULATEORDERS = true // cumulate orders if not turned off
DEFPARAM PRELOADBARS = 10000 // define intraday trading window
ONCE startTime = 80000
ONCE endTime = 220000 // define instrument signalline with help of multiple smoothed av-erages
ONCE periodFirstMA = 5
ONCE periodSecondMA = 10
ONCE periodThirdMA = 3 // define filter parameter
ONCE periodLongMA = 300
ONCE periodShortMA = 50 // define position and money man-agement parameter
ONCE positionSize = 1
ONCE maxPositionSizeLong = 15
ONCE maxPositionSizeShort = 10
ONCE 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 candles
ONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candles
ONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles
ONCE maxCandlesShortWithoutProfit = 25 // limit short loss latest after 25 candles
// define saisonal position multiplier >0 - long / <0 - short / 0 no trade
ONCE January = 2
ONCE February = 2
ONCE March = 2
ONCE April = 3
ONCE May = 2
ONCE June = 2
ONCE July = 3
ONCE August = -1
ONCE September = -2
ONCE October = 1
ONCE November = 3
ONCE December = 3
// calculate daily high/low
dailyHigh = DHigh(1)
dailyLow = DLow(1)
// calculate weekly high/low
If DayOfWeek < DayOfWeek[1] then
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
lastWeekBarIndex = BarIndex
ENDIF
// calculate monthly high/low
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// calculate instrument signalline with multiple smoothed averages
firstMA = WilderAverage[periodFirstMA](close)
secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
signalline = TimeSeriesAverage[periodThirdMA](secondMA)
// save position before trading window is open #Miguel
If Time < startTime then
startPositionLong = COUNTOFLONGSHARES
startPositionShort = COUNTOFSHORTSHARES
EndIF
// trade only in defined trading window
IF Time >= startTime AND Time <= endTime THEN
// filter criteria because not every breakout is profitable
f1 = close > Average[periodLongMA](close)
f2 = close < Average[periodLongMA](close)
f3 = close > Average[periodShortMA](close)
// reduced position? #Miguel
reduceLongInTradingWindow = COUNTOFLONGSHARES < startPositionLong
reduceShortInTradingWindow = COUNTOFSHORTSHARES < startPositionShort
// saisonal pattern
IF CurrentMonth = 1 THEN
saisonalPatternMultiplier = January
ELSIF CurrentMonth = 2 THEN
saisonalPatternMultiplier = February
ELSIF CurrentMonth = 3 THEN
saisonalPatternMultiplier = March
ELSIF CurrentMonth = 4 THEN
saisonalPatternMultiplier = April
ELSIF CurrentMonth = 5 THEN
saisonalPatternMultiplier = May
ELSIF CurrentMonth = 6 THEN
saisonalPatternMultiplier = June
ELSIF CurrentMonth = 7 THEN
saisonalPatternMultiplier = July
ELSIF CurrentMonth = 8 THEN
saisonalPatternMultiplier = August
ELSIF CurrentMonth = 9 THEN
saisonalPatternMultiplier = September
ELSIF CurrentMonth = 10 THEN
saisonalPatternMultiplier = October
ELSIF CurrentMonth = 11 THEN
saisonalPatternMultiplier = November
ELSIF CurrentMonth = 12 THEN
saisonalPatternMultiplier = December
ENDIF
// long position conditions
l1 = signalline CROSSES OVER monthlyHigh
l2 = signalline CROSSES OVER weeklyHigh
l3 = signalline CROSSES OVER dailyHigh
l4 = signalline CROSSES OVER monthlyLow
// short position conditions
s1 = signalline CROSSES UNDER monthlyHigh
s2 = signalline CROSSES UNDER dailyLow
// long entry (L1)
IF l1 AND not reduceLongInTradingWindow THEN // cumulate orders for long trades #Miguel
IF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossL1
takeProfit = takeProfitL1
ENDIF
// long entry (L2)
IF l2 AND not reduceLongInTradingWindow THEN // cumulate orders for long trades #Miguel
IF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossL2
takeProfit = takeProfitL2
ENDIF
// long entry (L3)
IF ( (l3 AND f2) AND not reduceLongInTradingWindow ) THEN // cumulate orders for long trades #Miguel
IF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossL3
takeProfit = takeProfitL3
ENDIF
// long entry (L4)
IF ( l4 AND not reduceLongInTradingWindow ) THEN // cumulate orders for long trades #Miguel
IF saisonalPatternMultiplier > 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossL4
takeProfit = takeProfitL4
ENDIF
// short entry (S1)
IF NOT SHORTONMARKET AND (s1 AND f3) AND not reduceShortInTradingWindow THEN // no cumulation for short trades #Miguel
IF saisonalPatternMultiplier < 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THEN
SELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
SELLSHORT positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossS1
takeProfit = takeProfitS1
ENDIF
// short entry (S2)
IF NOT SHORTONMARKET AND (s2 AND f1) AND not reduceShortInTradingWindow THEN // no cumulation for short trades #Miguel
IF saisonalPatternMultiplier < 0 THEN // check saisonal booster setup and max position size
IF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THEN
SELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
SELLSHORT positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stoppLossS2
takeProfit = takeProfitS2
ENDIF
// stop and profit management
posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
m1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit
IF LONGONMARKET AND (m1 OR m3) THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND (m2 OR m4) THEN
EXITSHORT AT MARKET
ENDIF
SET STOP %LOSS stopLoss
SET TARGET %PROFIT takeProfit
ENDIF
Someone 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:
// 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 parameter
DEFPARAM CUMULATEORDERS = true // cumulate orders if not turned off
DEFPARAM PRELOADBARS = 10000
// define intraday trading window
ONCE startTime = 80000
ONCE endTime = 220000
// define instrument signalline with help of multiple smoothed averages
ONCE periodFirstMA = 5
ONCE periodSecondMA = 10
ONCE periodThirdMA = 3
// define filter parameter
ONCE periodLongMA = 300
ONCE periodShortMA = 50
// define position and money management parameter
ONCE positionSize = 1
ONCE maxPositionSizeLong = 15
ONCE maxPositionSizeShort = 10
ONCE 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 candles
ONCE maxCandlesShortWithProfit = 13 // take short profit latest after 13 candles
ONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles 30
ONCE maxCandlesShortWithoutProfit = 13 // limit short loss latest after 13 candles
// define saisonal position multiplier >0 - long / <0 - short / 0 no trade
ONCE January = 2
ONCE February = 2
ONCE March = 2
ONCE April = 3
ONCE May = 2
ONCE June = 2
ONCE July = 3
ONCE August = -1
ONCE September = -2
ONCE October = 1
ONCE November = 3
ONCE December = 3
// calculate daily high/low (include sunday values if available)
dailyHigh = DHigh(1)
dailyLow = DLow(1)
// calculate weekly high/low
If DayOfWeek < DayOfWeek[1] then
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
lastWeekBarIndex = BarIndex
ENDIF
// calculate monthly high/low
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// calculate instrument signalline with multiple smoothed averages
firstMA = WilderAverage[periodFirstMA](close)
secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
signalline = TimeSeriesAverage[periodThirdMA](secondMA)
// save position before trading window is open
If Time < startTime then
startPositionLong = COUNTOFLONGSHARES
startPositionShort = COUNTOFSHORTSHARES
EndIF
// trade only in defined trading window
IF Time >= startTime AND Time <= endTime THEN
// set saisonal pattern
IF CurrentMonth = 1 THEN
saisonalPatternMultiplier = January
ELSIF CurrentMonth = 2 THEN
saisonalPatternMultiplier = February
ELSIF CurrentMonth = 3 THEN
saisonalPatternMultiplier = March
ELSIF CurrentMonth = 4 THEN
saisonalPatternMultiplier = April
ELSIF CurrentMonth = 5 THEN
saisonalPatternMultiplier = May
ELSIF CurrentMonth = 6 THEN
saisonalPatternMultiplier = June
ELSIF CurrentMonth = 7 THEN
saisonalPatternMultiplier = July
ELSIF CurrentMonth = 8 THEN
saisonalPatternMultiplier = August
ELSIF CurrentMonth = 9 THEN
saisonalPatternMultiplier = September
ELSIF CurrentMonth = 10 THEN
saisonalPatternMultiplier = October
ELSIF CurrentMonth = 11 THEN
saisonalPatternMultiplier = November
ELSIF CurrentMonth = 12 THEN
saisonalPatternMultiplier = December
ENDIF
// define trading filters
// 1. use fast and slow averages as filter because not every breakout is profitable
f1 = 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 criteria
alreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLong
alreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort
// long position conditions
l1 = signalline CROSSES OVER monthlyHigh
l2 = signalline CROSSES OVER weeklyHigh
l3 = signalline CROSSES OVER dailyHigh
l4 = signalline CROSSES OVER monthlyLow
// short position conditions
s1 = signalline CROSSES UNDER monthlyHigh
s2 = signalline CROSSES UNDER dailyLow
// long entry with order cumulation
IF ( (l1 OR l4 OR l2 OR (l3 AND f2)) AND NOT alreadyReducedLongPosition) THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier > 0 THEN
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossLong
takeProfit = takeProfitLong
ENDIF
// short entry without order cumulation
IF NOT SHORTONMARKET AND ( (s1 AND f3) OR (s2 AND f1) ) AND NOT alreadyReducedShortPosition THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier < 0 THEN
IF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THEN
SELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
SELLSHORT positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossShort
takeProfit = takeProfitShort
ENDIF
// stop and profit management
IF LONGONMARKET THEN
posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
ELSIF SHORTONMARKET THEN
posProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsize
ENDIF
m1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit
// take profit after max candles
IF LONGONMARKET AND (m1 OR m3) THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND (m2 OR m4) THEN
EXITSHORT AT MARKET
ENDIF
//trailing stop function
trailingStartInPoints = tradeprice(1) * trailingStart / 100
trailingStepInPoints = tradeprice(1) * trailingstep / 100
//reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL = 0 AND close - tradeprice(1) >= trailingStartInPoints * pipsize THEN
newSL = tradeprice(1) + trailingStepInPoints * pipsize
ENDIF
//next moves
IF newSL > 0 AND close - newSL >= trailingStepInPoints * pipsize THEN
newSL = newSL + trailingStepInPoints * pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL = 0 AND tradeprice(1) - close >= trailingStartInPoints * pipsize THEN
newSL = tradeprice(1) - trailingStepInPoints * pipsize
ENDIF
//next moves
IF newSL > 0 AND newSL - close >= trailingStepInPoints * pipsize THEN
newSL = newSL - trailingStepInPoints * pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
SET STOP %LOSS stopLoss
SET TARGET %PROFIT takeProfit
ENDIF
Maybe it is just a few single trades with high profit that make the difference, but see for yourselfs.
Flowsen ,
I checked in backtest results, excellent performance but very aggressive and therefore more dangerous.
Hi 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
My 2 cents about max position sizing : adjust it with max “Average Daily Range” from X lookback days.
Hi 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
Before 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.
I 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:
changes in detail for the DAX:
Here is the code for the DAX (backtest is attached):
// 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 parameter
DEFPARAM CUMULATEORDERS = true // cumulate orders if not turned off
DEFPARAM PRELOADBARS = 10000
// define intraday trading window
ONCE startTime = 80000
ONCE endTime = 220000
// define instrument signalline with help of multiple smoothed averages
ONCE periodFirstMA = 5
ONCE periodSecondMA = 10
ONCE periodThirdMA = 3
// define filter parameter
ONCE periodLongMA = 300
ONCE periodShortMA = 40
// define position and money management parameter
ONCE positionSize = 1
Capital = 10000
Risk = 2 // in %
equity = Capital + StrategyProfit
maxRisk = 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 candles
ONCE maxCandlesShortWithProfit = 15 // take short profit latest after 15 candles
ONCE maxCandlesLongWithoutProfit = 30 // limit long loss latest after 30 candles
ONCE maxCandlesShortWithoutProfit = 13 // limit short loss latest after 13 candles
// define saisonal position multiplier >0 - long / <0 - short / 0 no trade
ONCE January = 2
ONCE February = 2
ONCE March = 2
ONCE April = 3
ONCE May = 2
ONCE June = 2
ONCE July = 3
ONCE August = -1
ONCE September = -2
ONCE October = 1
ONCE November = 3
ONCE December = 3
// calculate daily high/low (include sunday values if available)
dailyHigh = DHigh(1)
dailyLow = DLow(1)
// calculate weekly high/low
If DayOfWeek < DayOfWeek[1] then
weeklyHigh = Highest[BarIndex - lastWeekBarIndex](dailyHigh)
lastWeekBarIndex = BarIndex
ENDIF
// calculate monthly high/low
If Month <> Month[1] then
monthlyHigh = Highest[BarIndex - lastMonthBarIndex](dailyHigh)
monthlyLow = Lowest[BarIndex - lastMonthBarIndex](dailyLow)
lastMonthBarIndex = BarIndex
ENDIF
// calculate instrument signalline with multiple smoothed averages
firstMA = WilderAverage[periodFirstMA](close)
secondMA = TimeSeriesAverage[periodSecondMA](firstMA)
signalline = TimeSeriesAverage[periodThirdMA](secondMA)
// save position before trading window is open
If Time < startTime then
startPositionLong = COUNTOFLONGSHARES
startPositionShort = COUNTOFSHORTSHARES
EndIF
// trade only in defined trading window
IF Time >= startTime AND Time <= endTime THEN
// set saisonal pattern
IF CurrentMonth = 1 THEN
saisonalPatternMultiplier = January
ELSIF CurrentMonth = 2 THEN
saisonalPatternMultiplier = February
ELSIF CurrentMonth = 3 THEN
saisonalPatternMultiplier = March
ELSIF CurrentMonth = 4 THEN
saisonalPatternMultiplier = April
ELSIF CurrentMonth = 5 THEN
saisonalPatternMultiplier = May
ELSIF CurrentMonth = 6 THEN
saisonalPatternMultiplier = June
ELSIF CurrentMonth = 7 THEN
saisonalPatternMultiplier = July
ELSIF CurrentMonth = 8 THEN
saisonalPatternMultiplier = August
ELSIF CurrentMonth = 9 THEN
saisonalPatternMultiplier = September
ELSIF CurrentMonth = 10 THEN
saisonalPatternMultiplier = October
ELSIF CurrentMonth = 11 THEN
saisonalPatternMultiplier = November
ELSIF CurrentMonth = 12 THEN
saisonalPatternMultiplier = December
ENDIF
// define trading filters
// 1. use fast and slow averages as filter because not every breakout is profitable
f1 = 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 criteria
alreadyReducedLongPosition = COUNTOFLONGSHARES < startPositionLong
alreadyReducedShortPosition = COUNTOFSHORTSHARES < startPositionShort
// long position conditions
l1 = signalline CROSSES OVER monthlyHigh
l2 = signalline CROSSES OVER weeklyHigh
l3 = signalline CROSSES OVER dailyHigh
l4 = signalline CROSSES OVER monthlyLow
// short position conditions
s1 = signalline CROSSES UNDER monthlyHigh
s2 = signalline CROSSES UNDER dailyLow
// long entry with order cumulation
IF ( (l1 OR l4 OR l2 OR (l3 AND f2)) AND NOT alreadyReducedLongPosition) THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier > 0 THEN
IF (COUNTOFPOSITION + (positionSize * saisonalPatternMultiplier)) <= maxPositionSizeLong THEN
BUY positionSize * saisonalPatternMultiplier CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
BUY positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossLong
takeProfit = takeProfitLong
ENDIF
// short entry without order cumulation
IF NOT SHORTONMARKET AND ( (s1 AND f3) OR (s2 AND f1) ) AND NOT alreadyReducedShortPosition THEN
// check saisonal booster setup and max position size
IF saisonalPatternMultiplier < 0 THEN
IF (COUNTOFPOSITION + (positionSize * ABS(saisonalPatternMultiplier))) <= maxPositionSizeShort THEN
SELLSHORT positionSize * ABS(saisonalPatternMultiplier) CONTRACT AT MARKET
ENDIF
ELSIF saisonalPatternMultiplier <> 0 THEN
IF (COUNTOFPOSITION + positionSize) <= maxPositionSizeLong THEN
SELLSHORT positionSize CONTRACT AT MARKET
ENDIF
ENDIF
stopLoss = stopLossShort
takeProfit = takeProfitShort
ENDIF
// stop and profit management
IF LONGONMARKET THEN
posProfit = (((close - positionprice) * pointvalue) * countofposition) / pipsize
ELSIF SHORTONMARKET THEN
posProfit = (((positionprice - close) * pointvalue) * countofposition) / pipsize
ENDIF
m1 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithProfit
m2 = posProfit > 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithProfit
m3 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesLongWithoutProfit
m4 = posProfit < 0 AND (BarIndex - TradeIndex) >= maxCandlesShortWithoutProfit
// take profit after max candles
IF LONGONMARKET AND (m1 OR m3) THEN
SELL AT MARKET
ENDIF
IF SHORTONMARKET AND (m2 OR m4) THEN
EXITSHORT AT MARKET
ENDIF
// trailing stop function
trailingStartLongInPoints = tradeprice(1) * trailingStartLong / 100
trailingStartShortInPoints = tradeprice(1) * trailingStartShort / 100
trailingStepLongInPoints = tradeprice(1) * trailingStepLong / 100
trailingStepShortInPoints = tradeprice(1) * trailingStepShort / 100
// reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
ENDIF
// manage long positions
IF LONGONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND close - tradeprice(1) >= trailingStartLongInPoints * pipsize THEN
newSL = tradeprice(1) + trailingStepLongInPoints * pipsize
ENDIF
// next moves
IF newSL > 0 AND close - newSL >= trailingStepLongInPoints * pipsize THEN
newSL = newSL + trailingStepLongInPoints * pipsize
ENDIF
ENDIF
// manage short positions
IF SHORTONMARKET THEN
// first move (breakeven)
IF newSL = 0 AND tradeprice(1) - close >= trailingStartShortInPoints * pipsize THEN
newSL = tradeprice(1) - trailingStepShortInPoints * pipsize
ENDIF
// next moves
IF newSL > 0 AND newSL - close >= trailingStepShortInPoints * pipsize THEN
newSL = newSL - trailingStepShortInPoints * pipsize
ENDIF
ENDIF
// stop order to exit the positions
IF newSL > 0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
// superordinate stop and take profit
SET STOP %LOSS stopLoss
SET TARGET %PROFIT takeProfit
ENDIF
Hi 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
Unfortunately, I can’t attach the both files. Here is the first, 10k, 2% risk and at least 1 contract
and here is the second attachment, 10k account, 2% risk and at least 5 possible contracts
Hey 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.
Pathfinder Trading System
This topic contains 1,834 replies,
has 139 voices, and was last updated by CFD AutoTrading
2 years, 6 months ago.
| Forum: | ProOrder support |
| Language: | English |
| Started: | 09/22/2016 |
| Status: | Active |
| Attachments: | 435 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.