Baby Steps – First Live System – DAX 5 Min
Forums › ProRealTime English forum › ProOrder support › Baby Steps – First Live System – DAX 5 Min
- This topic has 13 replies, 9 voices, and was last updated 4 years ago by Khaled.
-
-
06/01/2020 at 5:02 PM #134068
Hello – I hope this finds everybody well.
As I’ve just made my first foray into coding, after hanging around on the site for sometime over a year now, I thought I’d share and of course would welcome any feedback. By way on context, I’ve been fiddling around with trading (via a spread betting account with IG) for a couple of years. I’ve been up a bit, down a bit and a couple of months ago found myself pretty much back where I started, and struggling to find the time to concentrate properly what with a full time job and a young family. I’ve had several false starts with ProRealCode and never got as far as putting a system live – until about 3 weeks ago.
The very simple system runs on DAX 5 minute chart and uses a 200 period EMA and SuperTrend as filters, and an ADX/ADXR crossover as entry trigger. Stops and profit target is fixed (about a 1 to 1.6 R/R). Back-testing showed it to be profitable based on a 100K bars test (starting in February 2019), but with a horrible curve – a fairly consistent losing streak early on, but consistently profitable since about the end of last July. Now, I know this is far from satisfactory for the purist, but recent performance was enough to persuade me to make it live, with low position size and guaranteed stops.
I absolutely don’t expect this to run for ever – it’s going to stop working based on back test, but it’s given me the confidence that there’s something to build on for the future. Happily after 3 and a bit weeks of running, account is up about 18% and win rate is just the right side of 50%.
DAX 5 Min SuperTrend and ADX12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Common indicatorsindicator1 = ExponentialAverage[200](close)indicator2 = SuperTrend[3,10]indicator3 = ADX[11]indicator4 = ADXR[11]// Common variable valuesadxval = 22profitpoints = 83losspoints = 50// Conditions to enter long positionsc1 = (close > indicator1)c2 = (close > indicator2)c3 = (indicator3 CROSSES OVER indicator4)c4 = indicator3 > adxvalIF c1 AND c2 AND c3 AND c4 THENBUY 0.5 PERPOINT AT MARKETENDIF// Conditions to enter short positionsc5 = (close < indicator1)c6 = (close < indicator2)c7 = (indicator3 CROSSES OVER indicator4)c8 = indicator3 > adxvalIF c5 AND c6 AND c7 AND c8 THENSELLSHORT 0.5 PERPOINT AT MARKETENDIF// Stops and targetsSET STOP pLOSS losspointsSET TARGET pPROFIT profitpoints//EXIT for WeekendIF opendayofweek = 5 and openhour >= 21 and openminute >= 50 thensig=1elsesig=0endifIF sig=1 THENSELL AT MARKETEXITSHORT AT MARKETENDIFBack test view attached along with account growth chart based on the 46 trades placed to date.
Comments and advice welcome. I’m very new to this, and not even scratched the surface.
Cheers
WT
3 users thanked author for this post.
09/27/2020 at 11:05 AM #145500Thanks for sharing your code.
I think it will be useful to many and a source for new ideas 🙂
09/28/2020 at 9:27 AM #14562809/28/2020 at 11:43 AM #145658So, I ran this live for 2 months – 11th May to around 11th July. As per my original post, it started very well then began to tail off as market conditions changed. I lucked out really starting it at a good time. Win rate for the period was about 42% overall and it was a couple of hundred quid in profit when I stopped it. My intention has always been to go back and look at how I can refine it, probably initially looking at some multi-timeframe filters. Also keen to explore alternative exit (e.g. trailing stop) rather than fixed points target.
Results from running in back-test from 11th July to current are very bad, but the market’s basically been going sideways. So it definitely needs some better filtering to look for trending periods.
1 user thanked author for this post.
10/31/2020 at 12:43 AM #149062Hi Welshtrader, thank you for sharing your code. I’m a beginner, so please bear with me. I’ve added a few conditions (VWAP, KST and VWMA) to increase the WinRate to around 64% (Sept. 16th 2019 to date) with a R/R of x1.9 (Capital of 1500€, TF 5 minutes and Size = 1 DAX 1€ Contract). I’ve also copied the ML code from juanj (https://www.prorealcode.com/topic/machine-learning-in-proorder/) and the MFE from Nicolas (https://www.prorealcode.com/blog/learning/trailing-stop-max-favorable-excursion-mfe/).
Walk Forward shows a Win Rate of 62.5% and R/R of x1.6.
Not sure of the Tick by Tick mode in the backtest.
Please test and let me know…
A big thank you to robertogozzi and Nicolas who guided me through my learning process.
Baby Steps DAX M5123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172DEFPARAM CumulateOrders = False // Cumulating positions deactivatedN = 1Timeframe(5 minutes)EMA200 = ExponentialAverage[200](close)SupT = SuperTrend[3,10]iADX = ADX[13]iADXR = ADXR[13]VWAP = CALL "VWAP Intrady"OscKST, SignalKST = CALL "KST8"VWMA3 = CALL "VWMA Intraday"EMA3 = ExponentialAverage[3](close)// Common variable valuesadxval = StartingValueprofitpoints = 500losspoints = 84 //(Best in WF 94)trailingstop = 50///////////////////////////////////////////////////////////////////////// Conditions to enter long positionsc1 = (close > EMA200) AND (close > VWAP) AND (OscKST > SignalKST) AND (VWMA3 > EMA3)c2 = (close > SupT)c3 = (iADX CROSSES OVER iADXR)c4 = iADX > adxval// Conditions to enter short positionsc5 = (close < EMA200)c6 = (close < SupT)c7 = (iADX CROSSES OVER iADXR)c8 = iADX > adxval/////////////////////////////////////////////////////////////////////////// Heuristics Algorithm StartIf onmarket[1] = 1 and onmarket = 0 Thenoptimize = optimize + 1EnDifStartingValue = 24 //(Best in WF 24)ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement = 1MaxIncrement = 4 //Limit of no of increments either up or downReps = 5 //Number of trades to use for analysisMaxValue = 29 //Maximum allowed valueMinValue = increment //Minimum allowed valueonce monthinit = monthonce yearinit = yearIf (year = yearinit and month = (monthinit + ResetPeriod)) or (year = (yearinit + 1) and ((12 - monthinit) + month = ResetPeriod)) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0monthinit = monthyearinit = yearEndIfonce ValueX = StartingValueonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce Optimize = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsIf Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*100000)*-1)*-1)NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = ValueXEndIfIf WinCountA >= WinCountB ThenWinCountB = WinCountA //Update Best Win CountBestB = ValueXEndIfIf WinCountA > WinCountB and StratAvgA > StratAvgB ThenMode = 0ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 2 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2EndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement ThenIf BestA = BestB ThenValueX = BestAElseIf reps >= 10 ThenWeightedScore = 10ElseWeightedScore = round((reps/100)*100)EndIfValueX = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos = 1PIncPos = 1ElsIf ValueX > MaxValue ThenValueX = MaxValueElsIf ValueX < MinValue ThenValueX = MinValueEndIFOptimize = 0EndIf// Heuristics Algorithm End/////////////////////////////////////////////////////////////////////////IF c1 AND c2 AND c3 AND c4 THENBUY N CONTRACT AT MARKETENDIFIF c5 AND c6 AND c7 AND c8 THENSELLSHORT N CONTRACT AT MARKETENDIF//trailing stop//resetting variables when no trades are on marketif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endif//case SHORT orderif shortonmarket thenMINPRICE = MIN(MINPRICE,close) //saving the MFE of the current tradeif tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price levelendifendif//case LONG orderif longonmarket thenMAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current tradeif MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price levelendifendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPSELL AT priceexit STOPendif// Stops and targetsSET STOP pLOSS losspointsSET TARGET pPROFIT profitpoints2 users thanked author for this post.
10/31/2020 at 12:20 PM #14907610/31/2020 at 2:57 PM #149085Below the code I’ve used for VWAP courtesy of one of the members here. Let me know if you spot an error in the code.
VWAP Intraday12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152// VWAP@Time intraday// 10.04.2020// Daniele MaddalunoDEFPARAM CalculateOnLastBars = 2500startTime=080000endTime= 235959if opentime < startTime or opentime > endTime thenn = 0dwapT1 = 0//dwapT2 = 0priced = 0shared = 0summ = 0vwap = close//vwapstd = 0elsen = n + 1// This if has been added just for plot reasonsif n <= 1 thendwapT1 = 0//dwapT2 = 0elsedwapT1 = 190//dwapT2 = 128endifpriced = priced + (totalprice*volume)shared = shared + volumeif shared>0 thenvwap = priced/sharedsumm = summ + square(totalprice - vwap)//vwapstd = sqrt(summ / n)endifendif// Manage the coloring of vwap mid lineif close > vwap thendwapR = 0dwapG = 128dwapB = 192elsedwapR = 255dwapG = 0dwapB = 0endifreturn vwap coloured(dwapR, dwapG, dwapB, dwapT1) as "vwap"10/31/2020 at 4:54 PM #14909310/31/2020 at 5:57 PM #149094V WAP … hmm, brings to mind a certain song title. And everything else. And now you’re all going to think of that every time you see that indicator, hahaha.
1 user thanked author for this post.
10/31/2020 at 9:14 PM #14910210/31/2020 at 9:38 PM #14910310/31/2020 at 11:31 PM #14911111/01/2020 at 10:46 AM #14912711/02/2020 at 12:24 AM #149228Thank you for spotting this gross mistake. My bad!
I’ve “tried” to correct it and run again backtest and WF.
So, the initial version (ver 1 ) I posted (working witout ML) did generate in backtest 6574€ WinRate 64.23% and Profit Rate 1.9x. When running the WF, the results are 5509€ WinRate 60.96% and Profit Rate 1.5x. (files below)
The version with ML embedded (ver 3) did generate in backtest 8073€ WinRate 60.43% and Profit Rate 2.04x. When running the WF, the results are 6249€ WinRate 55.79% and Profit Rate 1.56x. (files below + ITF)
So, the results with ML appear to be better in normal backtest and in WF.
Please review and let me know how we can further improve the result.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on