help in back testing strategy
Forums › ProRealTime English forum › ProBuilder support › help in back testing strategy
- This topic has 12 replies, 3 voices, and was last updated 2 years ago by zak1982.
-
-
02/23/2022 at 12:13 PM #188704
Hi All
I am to back test a strategy with below conditions for differ time frame. I want the entry to be in 5 min once the first bar close above MA 20. But should meet below conditions as well. SL based on 1.5 ATR and TP same distance SL. I tried first below coding but every time in back test no results showed as all. I am new in back testing process. any help please ?
=============================================================================================================
TIMEFRAME(4 hours)
indicator1= MACDline [21,89,8](High+Low/2)
indicator2= MACDSignal[21,89,8](High+Low/2)
indictaor3= exponentialaverage[50](close)
indictaor4= exponentialaverage[20](close)
xClose = (open + close + high + low) / 4
c1=(indicator1<indicator2)
c2= (xClose[1] <indictaor3)
c3= (xClose[1] < indictaor4)
REM The following code is related to this timescale:daily
TIMEFRAME(1 hour)
indicator5= MACDline [21,89,8](High+Low/2)
indicator6= MACDSignal[21,89,8](High+Low/2)
c4=(indicator5<indicator6)
REM The following code is related to this timescale:4 hours
TIMEFRAME(15 minute)
indicator7= MACDline [21,89,8](High+Low/2)
indicator8= MACDSignal[21,89,8](High+Low/2)
c5=(indicator7< indicator8)
indictaor9=exponentialaverage[10](close[2])
//xClose = (open + close + high + low) / 4
c6=(xClose[1] < indictaor9)IF c1 AND c2 and c3 and c4 and c5 and c6 THEN
SELLSHORT AT MARKET
ENDIF02/23/2022 at 11:55 PM #188736I think you have coded a wrong expression: High+Low/2, which high + half the Low, perhaps this is what you want:
1(High+Low)/2 //or simply (range/2)02/26/2022 at 7:35 AM #188861Thanks for correction
I am still getting an issue in back tests. Though i selected right period , some time i got a message said invalid back test date and sometime it run but not getting me a results. Any issue with above code for back test. How i can intergrade TP and SL/
02/27/2022 at 9:44 AM #188935The following code works fine on a 5 min chart. You seem to have too many restrictions. With all conditions, there are no trades on 1k bars on Dow 5min. When I remove C4, 19 trades are generated on 5min TF. If you want to keep C4, then you need to find MACD 1 hour TF parameters which are compatible with all the other conditions.
I added TP & SL at 1.5 x ATR.
At first glance on 1k bars, the system looks profitable, but way too much drawdown, large SL, R/R 1:1 is not enough. I didn’t dig into the subject, but it seems like you have late entries. You may want to add more conditions on lower TF and relax the conditions on H4 TF (suggestion/intuition). As you seem to be new here, trade on Demo account first, because sexy backtest rarely reflect what can happen next…
Hope this helps.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657DEFPARAM CUMULATEORDERS = FALSETIMEFRAME(4 hours)c1=0c2=0c3=0indicator1= MACDline [21,89,8]((High+Low)/2)indicator2= MACDSignal[21,89,8]((High+Low)/2)indictaor3= exponentialaverage[50](close)indictaor4= exponentialaverage[20](close)xClose = (open + close + high + low) / 4c1=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low)/2))c2= (xClose[1] < exponentialaverage[50](close))c3= (xClose[1] < exponentialaverage[20](close))TIMEFRAME(1 hour)c4=0indicator5= MACDline [21,89,8]((High+Low)/2)indicator6= MACDSignal[21,89,8]((High+Low/2))ATR = AverageTrueRange[14](close)c4=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low/2)))TIMEFRAME(15 minute)c5=0c6=0indicator7= MACDline [21,89,8]((High+Low)/2)indicator8= MACDSignal[21,89,8]((High+Low)/2)indictaor9=exponentialaverage[10](close[2])c5=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low)/2))c6=(xClose[1] < exponentialaverage[10](close[2]))//xClose = (open + close + high + low) / 4TIMEFRAME(DEFAULT)IF c1 and c2 and c3 and c5 and c6 THEN // c4 andSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP PLOSS (1.5 * ATR)SET TARGET PPROFIT (1.5 * ATR)1 user thanked author for this post.
02/27/2022 at 10:20 AM #188941Thanks Dear Khaled
really appreciated. I realized that for manual entry will get late reply. If I want to make entry in M15 only by closing the first bar above EMA 10. Who ic an express this in coding. As sometimes the pentation happen at late stage and as you said it is difficult to reach 1:1
02/27/2022 at 10:26 AM #18894202/27/2022 at 1:48 PM #18895502/27/2022 at 3:30 PM #188956It depends 🙂
- if you’re running your system on a 15 min TF graph: the code will be executed at the end of each 15 min candle and take a trade if there a Signal in the closed candle.
- if you’re running your system on TF lower than 15 min – for example 5 min TF:
- if you put TIMEFRAME(15 minutes, updateonclose), then the code will be executed each 15 min
- if you put TIMEFRAME(15 minutes), then the code will be executed at the end of each 5 min candle. If there is a Signal on the 15 min TF (suppose your signal appears in min 9, then code will be executed at min 10:00:01.)
The best way to get grasp of this MTF is to put your system into an indicator and see how the indicator behaves on different TF. The smaller the TF, the earlier you catch the trade, but you will get way higher number of false signals, i.e. higher number of losses. So there is a balance to find according to your Money Management and Psychology between higher number of trades and higher losers and potentially higher gains, or lower number of trades, lower losses and lower gains. Unfortunately, there is no free lunch in trading.
02/27/2022 at 5:08 PM #188957Many thanks Dear Khaled and sorry for hanging you a lot on this. I am new in this software , I normally back test in Metrader4 (but not professional software form back testing). Totally agree with you that lower time frame will be earlier catch for the trade. I am trying differ scenario. My manual back test good. I entered as well in demo for 3 weeks , so far good results (apart form 1:1 R to reward). (I normally trade live with diff. system)
I tried to modify the code in such way that once condition in TF daily and 1 hr met to open the trade once the closed of candle above EMA 10 in time frame 1 H (as per defied condition) but I got sell and buy trades (which is very strange to me). Which means in daily time frame if conditions met , then looking for 1 H and should conditions met as per 1 h conditions and also to execuate the trade after meeting 1 h criteria . In particular closing 1h candle above/below 10 EM.(b elow case for sell , should be below)
DEFPARAM CUMULATEORDERS = FALSE
TIMEFRAME(daily)
c1=0
c2=0
c3=0indicator1= MACDline [21,89,8]((High+Low)/2)
indicator2= MACDSignal[21,89,8]((High+Low)/2)indictaor3= exponentialaverage[50](close)
indictaor4= exponentialaverage[20](close)xClose = (open + close + high + low) / 4
c1=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low)/2))
c2= (xClose[1] < exponentialaverage[50](close))
c3= (xClose[1] < exponentialaverage[20](close))
TIMEFRAME(4 hour )
c4=0indicator5= MACDline [21,89,8](High+Low)/2
indicator6= MACDSignal[21,89,8](High+Low)/2
ATR = AverageTrueRange[14](close)c4=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)
TIMEFRAME(1 hour)
c5=0
c6=0indicator7= MACDline [21,89,8]((High+Low)/2)
indicator8= MACDSignal[21,89,8]((High+Low)/2)
indictaor9=exponentialaverage[10](close[2])c5=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)
c6=(xClose[1] < exponentialaverage[10](close[2]))
//xClose = (open + close + high + low) / 4TIMEFRAME(1 hour ,updateonclose)
IF c1 and c2 and c3 and c6 THEN // c4 and
SELLSHORT 1 CONTRACT AT MARKET
ENDIFSET STOP PLOSS (1.5 * ATR)
SET TARGET PPROFIT (1.5 * ATR)02/28/2022 at 9:19 AM #188979I tested your code on DAX40 and it didn’t generate any buy orders, only Shorts (as expected – see screenshot 2).
The code shows a crossing of EMA10 of 2 periods before the current candle.
1exponentialaverage[10](close[2])Is this what you want?
I cleaned up the code.
123456789101112131415161718192021222324252627282930313233343536DEFPARAM CUMULATEORDERS = FALSETIMEFRAME(daily)c1=0c2=0c3=0xClose = (open + close + high + low) / 4c1=(MACDline [21,89,8]((High+Low)/2) < MACDSignal[21,89,8]((High+Low)/2))c2= (xClose[1] < exponentialaverage[50](close))c3= (xClose[1] < exponentialaverage[20](close))TIMEFRAME(4 hour )c4=0ATR = AverageTrueRange[14](close)c4=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)TIMEFRAME(1 hour)c5=0c6=0c5=(MACDline [21,89,8](High+Low)/2 < MACDSignal[21,89,8](High+Low)/2)c6=(xClose[1] < exponentialaverage[10](close[2]))TIMEFRAME(1 hour,updateonclose)IF c1 and c2 and c3 and c6 THENSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP PLOSS (1.8 * ATR)SET TARGET PPROFIT (2.6 * ATR)02/28/2022 at 9:53 AM #188990Thanks Dear Khaled
I will re run it again. For EMA , I thought this is the expression of EMA 10 shifted by 2 (offset) , unless I am doing the wrong code. So with this EMA setup once a 1hr candle close below should sell provided daily conditions as wel met.
02/28/2022 at 10:05 AM #18899402/28/2022 at 10:11 AM #188995 -
AuthorPosts
Find exclusive trading pro-tools on