Simple Moving Average Crossover Strategy
Forums › ProRealTime English forum › ProOrder support › Simple Moving Average Crossover Strategy
- This topic has 95 replies, 12 voices, and was last updated 1 year ago by CRISRJ.
-
-
02/02/2022 at 9:04 AM #187308
Have added a volatility filter to the original 15 min version, which was optimized over the last 50k bars. Reduces draw down and increases performance so net happy with this minor addition. Will rerun the Walk Forward process but expect little change.
Am also testing the 5 min version which nonetheless kindly posted as this too looks very promising.
02/02/2022 at 1:23 PM #187341I advice you don’t surprise yourself with backtest, or maybe to be sure of the robustness of your code, test Long on some sample down trends and see how it reacts or maybe try with Walk Forward strategy, and I totally agree with you the simpler the better
this answer is for phoentzs, sorry
02/02/2022 at 1:26 PM #187343on the Backtest you only buy half a point ?
I do backtests at the minimum position size, in this case 0.5 pp
This is partly because the M0ney Management is based on the max drawdown @ min position size (line 26)
As for your further comments, my basic attitude is that no matter how good a backtest might look, I assume that it’s completely wrong and totally unreliable, will probably crash and burn.
Run it for months in demo, study the entries and exits – see if it behave the way you expected.
This one got off to a good start yesterday, 4 winning trades, ~400 pts.
maybe you can try to optimise with the Walk Forward method, it’s maybe will help you, I will study if in the future deeply maybe, now I’m not at this level
02/02/2022 at 7:25 PM #187395@samsampop
I haven’t a chance to run your new version but one thing you should change is line 69, should be:
PriceDistance = 4 * pipsize
this is the IG minimum stop distance, so it will change from one instrument to the next.
1 user thanked author for this post.
02/24/2022 at 6:10 PM #188786Quick update – strategy has stayed out of the market since Jan 20th and good job too for a long only strategy.
03/01/2022 at 6:30 PM #189149here’s a revised 5m version – better long term performance with lower drawdown, positionsize = 1
altered the 4h filter and added StochasticRSI
took one loss in Feb, but otherwise managed the Ukraine mess fairly well (so far)
5 users thanked author for this post.
03/03/2022 at 1:56 PM #189251Hi nonetheless
Quick question if I may – how often would you re-optimize the variables for this latest strategy that you have kindly posted?
Thanks very much
03/03/2022 at 2:58 PM #189257I don’t have a fixed policy on that. I rework things as and when I have an idea that might improve some aspect. Obviously, if you’re optimizing on max data on a 12 year backtest you’d hope that those numbers would be worth keeping. Someone else might keep the basic structure of the algo but optimize for maybe 6 years where most of the profit has been made – I guess then you’d want to refresh it more often. Who knows … 🤔
1 user thanked author for this post.
03/04/2022 at 6:46 AM #18929503/04/2022 at 10:26 AM #189303the 3 functions after the trail are standard bits of code that i add to most algos, the effect varies from one to the next. In this case they collectively add about 3%
If you’d rather not have an extra 3% then I suggest you switch them off immediately 😁
Attached are the results with a constant exposure value of €10k, gives a better visual on the histogram and the curve.
3 users thanked author for this post.
03/26/2022 at 1:32 AM #190505Hello @nonetheless, than you for your work. I am really confused, i’am not having same backtest as you, I am using V4.1 L, and i have add 1h at h1 and h2 because i’m in France. Can you share with us the last itf you have. Thank you very much.
03/26/2022 at 10:29 AM #190511I haven’t done any other work on that one, so v4.1L is the only itf I have. How much discrepancy are you seeing?
1 user thanked author for this post.
03/26/2022 at 3:08 PM #190518@nonetheless Here is my backtest for the same period and Position size 1 MM off so you can see the huge difference :’D . I added also the parametres. Thanks for you help.
03/26/2022 at 4:08 PM #190523the only thing i can think of is the time settings in the DSD section. Try it like this, allowing for the Euro time difference
12345678910111213141516171819202122DSD = 1if DSD thenonce openStrongLong = 0once openStrongShort = 0if (time <= 120000 or time >= 170000) then // 070000, 100000openStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = rok // 30once tradeMin = tm // 1000IF (time >= 120500) AND (time <= 120500 + tradeMin) AND ABS(close - open) > rangeOK THENIF close > open and close > open[1] THENopenStrongLong = 1openStrongShort = 0ENDIFIF close < open and close < open[1] THENopenStrongLong = 0openStrongShort = 1ENDIFENDIF1 user thanked author for this post.
03/26/2022 at 5:07 PM #190525Thank you, it ads a bit of amelioration but still not that great performance that you have.
This is my code, no spread for this backtest, no MM, parametres are the same.
I’m ready to change the time zone for PRT if it will improve my results.If you can’t see any solution. I will not be a problem. I am already grateful for your contribution.
ThanksNAS 5m MACross v4.1 L(1)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216// opt: 01/03/2022//=======================================================================DEFPARAM CUMULATEORDERS = FALSEDEFPARAM preloadbars = 10000positionsize = 1//Tradetime//adjustment for American Daylight Savings timeADLS =1if ADLS thenDLS =(Date >= 20100314 and date <=20100328) or (Date >= 20101031 and date <=20101107) or (Date >= 20110313 and date <=20110327) or (Date >= 20111030 and date <=20111106) or (Date >= 20120311 and date <=20120325) or (Date >= 20121028 and date <=20121104) or (Date >= 20130310 and date <=20130331) or (Date >= 20131027 and date <=20131103) or (Date >= 20140309 and date <=20140330) or (Date >= 20141026 and date <=20141102) or (Date >= 20150308 and date <=20150329) or (Date >= 20151025 and date <=20151101) or (Date >= 20160313 and date <=20160327) or (Date >= 20161030 and date <=20161106) or (Date >= 20170312 and date <=20170326) or (Date >= 20171030 and date <=20171105) or (Date >= 20180311 and date <=20180325) or (Date >= 20181028 and date <=20181104) or (Date >= 20190310 and date <=20190331) or (Date >= 20191027 and date <=20191103) or (Date >= 20200308 and date <=20200329) or (Date >= 20201025 and date <=20201101) or (Date >= 20210314 and date <=20210328) or (Date >= 20211031 and date <=20211107) or (Date >= 20220313 and date <=20220327) or (Date >= 20221030 and date <=20221106) or (Date >= 20230312 and date <=20230326) or (Date >= 20231029 and date <=20231105) or (Date >= 20240310 and date <=20240331) or (Date >= 20241027 and date <=20241103)If DLS thenTradetime = time >=h1-10000 and time <h2-10000elsif not DLS thenTradetime = time >=h1 and time <h2endifendifif not ADLS thenTradetime = time >=h1 and time <h2endif//Long Entry FilterTimeframe(4 hours)FMA1 = average[p,t](typicalprice)//FMA2 = average[p1,t](typicalprice)cb1 = FMA1 > FMA1[1]//cs1 = FMA1 < FMA2Timeframe(15 minutes)M15 = average[p2,t2](typicalprice)cb2 = (close>m15)//cs2 = close<average[p2,t2](typicalprice)Timeframe(Default)//Long Entry CriteriaMA1=average[p3,t3](typicalprice)MA2=average[p4,t3](typicalprice)cb3 = MA1 crosses over MA2//cs3 = MA1 crosses under MA2//Stochastic RSI | indicatorlengthRSI = lr //RSI periodlengthStoch = ls //Stochastic periodsmoothK = sk //Smooth signal of stochastic RSIsmoothD = sd //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K = average[smoothK](stochrsi)*100D = average[smoothD](K)cb4 = K>D// Conditions to enter long positionsIf Tradetime and cb1 and cb2 and cb3 and cb4 ThenBuy PositionSize CONTRACTS AT MARKETENDIFSET STOP %LOSS slSET TARGET %PROFIT tp// Break even and trailing stop RTSIF Not OnMarket THEN// when NOT OnMarket reset values to default valuests = (tradeprice*pc)/100 // % trailing startTrailStart = ts //30 Start trailing profits from this pointBasePerCent = base // 0.200 20.0% Profit percentage to keep when setting BerakEvenStepSize = ss //10 Pip chunks to increase PercentagePerCentInc = pci // 0.100 10.0% PerCent increment after each StepSize chunkBarNumber = bn //10 Add further % so that trades don't keep running too longBarPerCent = bpc // 0.100 10% Add this additional percentage every BarNumber barsRoundTO = 0 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviourPriceDistance = 4 * pipsize //IG minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0ProfitPerCent = BasePerCent //reset to desired default valueTradeBar = BarIndexELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN//LONG positions//// compute the value of the Percentage of profits, if any, to lock in for LONG trades//x1 = (close - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - x1) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profitENDIFELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN//SHORT positions//// compute the value of the Percentage of profits, if any, to lock in for SHORT trades//x2 = (tradeprice - close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN // go ahead only if N+ pipsDiff2 = abs(TrailStart - x2) //difference from current profit and TrailStartChunks2 = max(0,round((Diff2 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCent// compute number of bars elapsed and add an additionl percentage// (this percentage is different from PerCentInc, since it's a direct percentage, not a Percentage of BasePerCent)// (if BasePerCent is 20% and this is 10%, the whole percentage will be 30%, not 22%)BarCount = BarIndex - TradeBarIF BarCount MOD BarNumber = 0 THENProfitPerCent = ProfitPerCent + BarPerCentENDIF//ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profitENDIFENDIFIF y1 THEN //Place pending STOP order when y1 > 0 (LONG positions)SellPrice = Tradeprice + (y1 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - SellPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSE////sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//SELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y2 > 0 (SHORT positions)ExitPrice = Tradeprice - (y2 * pipsize) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - ExitPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSE////ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//EXITSHORT AT MarketENDIFENDIF//----------------------------------------------------------------------------//EXIT ZOMBIE TRADEEZT = 1if EZT thenIF (longonmarket and barindex-tradeindex(1)>= b1 and positionperf>0) or (longonmarket and barindex-tradeindex(1)>= b2 and positionperf<0) thensell at marketendifIF (shortonmarket and barindex-tradeindex(1)>= 4000 and positionperf>0) or (shortonmarket and barindex-tradeindex(1)>= 4000 and positionperf<0) thenexitshort at marketendifendif//----------------------------------------------------------------------------RSIexit = 1 // in profitif RSIexit thenmyrsi2=rsi[r](close)if myrsi2<rl and barindex-tradeindex>1 and longonmarket and positionperf>0 thensell at marketendifif myrsi2>70 and barindex-tradeindex>1 and shortonmarket and positionperf>0 thenexitshort at marketendifendif//----------------------------------------------------------------------------DSD = 1if DSD thenonce openStrongLong = 0once openStrongShort = 0if (time <= 120000 or time >= 170000) then // 070000, 100000openStrongLong = 0openStrongShort = 0endif//detect strong direction for market openonce rangeOK = rok // 30once tradeMin = tm // 1000IF (time >= 120500) AND (time <= 120500 + tradeMin) AND ABS(close - open) > rangeOK THENIF close > open and close > open[1] THENopenStrongLong = 1openStrongShort = 0ENDIFIF close < open and close < open[1] THENopenStrongLong = 0openStrongShort = 1ENDIFENDIFENDIF -
AuthorPosts
Find exclusive trading pro-tools on