Optimization moving average crossing strategy
Forums › ProRealTime English forum › ProOrder support › Optimization moving average crossing strategy
- This topic has 185 replies, 11 voices, and was last updated 2 years ago by
slevinkelevra.
-
-
05/19/2020 at 11:53 AM #132260
I’ve been trying to amalgamate the codes I posted here #130635 as one itf, with cumulateorders =true and without the OTD condition, something like this:
12345678910111213141516171819If time >=143000 and time <160500 thenMAType = 54MATypeV2 = 14elseif time >=160500 and time <174500 thenMAType = 7MATypeV2 = 36elseif time >=174500 and time <192000 thenMAType = 2MATypeV2 = 63elseif time >=192000 and time <210000 thenMAType = 69MATypeV2 = 7endifendifendifendifResults are mixed, mainly because without the OTD (one trade per day) it allows multiple positions to be opened in each time slot. Is there a way to code this so as to have multiple positions, but max one from each time slot?
1 user thanked author for this post.
05/19/2020 at 1:09 PM #132273Hi, not sure but maybe something like this ?
123456789101112131415161718if time=000000 thencount1=0count2=0count3=0count4=0endifIf time >=143000 and time <160500 thenMAType = 54MATypeV2 = 14condbuy1=... and count1=0if condbuy1 thenbuy at marketcount1=count1+1endifelse...1 user thanked author for this post.
05/19/2020 at 2:29 PM #132280Hi @Roger, is this what you meant?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980if time=000000 thencount1=0count2=0count3=0count4=0endif//conditions to enter longIf time >=143000 and time <160500 thenMAType = 54MATypeV2 = 14if wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] and CndB and count1=0 thenbuy positionsize shares AT MARKETcount1=count1+1endifelseIf time >=160500 and time <174500 thenMAType = 7MATypeV2 = 36if wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] and CndB and count2=0 thenbuy positionsize shares AT MARKETcount2=count2+1endifelseIf time >=174500 and time <192000 thenMAType = 2MATypeV2 = 63if wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] and CndB and count3=0 thenbuy positionsize shares AT MARKETcount3=count3+1endifelseIf time >=192000 and time <210000 thenMAType = 69MATypeV2 = 7if wAFR > wAFRv2 and wAFR[1] < wAFRv2[1] and CndB and count4=0 thenbuy positionsize shares AT MARKETcount4=count4+1endifendifendifendifendif//conditions to enter shortIf time >=143000 and time <160500 thenMAType = 54MATypeV2 = 14if wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] and CndS and count1=0 thensellshort positionsize shares AT MARKETcount1=count1+1endifelseIf time >=160500 and time <174500 thenMAType = 7MATypeV2 = 36if wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] and CndS and count2=0 thensellshort positionsize shares AT MARKETcount2=count2+1endifelseIf time >=174500 and time <192000 thenMAType = 2MATypeV2 = 63if wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] and CndS and count3=0 thensellshort positionsize shares AT MARKETcount3=count3+1endifelseIf time >=192000 and time <210000 thenMAType = 69MATypeV2 = 7if wAFR < wAFRv2 and wAFR[1] > wAFRv2[1] and CndS and count4=0 thensellshort positionsize shares AT MARKETcount4=count4+1endifendifendifendifendifThat doesn’t actually help … but probably I’ve made mistakes?
05/19/2020 at 2:58 PM #13228505/19/2020 at 5:08 PM #132304Well, I think that the problem is that PRC does not allow to manage each trade independently (partial closure is not allowed)
1 user thanked author for this post.
05/19/2020 at 6:09 PM #132307Yes, I think you’re right. Even if we could get the opening right, the aggregate of positions would all be subject to the same stop loss, which won’t work.
Never mind, they work perfectly well separately. Thanks for your help.
05/20/2020 at 11:27 AM #132393This is the 2m version of my ongoing Corona project. Like the 5m it works as one basic strategy divided into 4 separate time slots. All values are identical except for a different pair of crossing averages as thrown up by @jan’s cross-finding engine. There is no other optimisation. The 4 need to be viewed together as 1 strategy; for example the results for (3) look poor but those months are balanced by stronger performance by 1,2 and 4.
These work with a small SL of just .6% and a healthy risk/reward ratio. Unlike the 5m version, I’ve used @Paul’s ATR trail, but with a conventional break even at .1% This can be switched off, and in some cases that improves profit but with a lower Win%.
Beware that the back test here is only about 13 months. WF results were very good as you’d expect with no optimisation. There is however the possibility of a sort of reverse curve-fit, ie not that the values are adjusted to fit a particular curve but that the cross-finding engine finds a curve to fit the values you give it. No idea whether that’s better or worse ??? but for my money it seems to be worth a punt. A starting position of €.2pp means a max single loss of around €30
This can also be used as a template for other instruments, you just have to re-run the cross-finding engine for MAType
1 user thanked author for this post.
05/20/2020 at 11:35 AM #132396This is the code I added to @jan’s
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849TIMEFRAME(10 minutes)Perioda= 20innera = 2*weightedaverage[round( Perioda/2)](typicalprice)-weightedaverage[Perioda](typicalprice)HULLa = weightedaverage[round(sqrt(Perioda))](innera)cnd1 = HULLa > HULLa[1]cnd2 = HULLa < HULLa[1]TIMEFRAME(6 minutes)// typically 2x or 3x default TFST1 = SuperTrend[3,10]cnd3 = (close > ST1)cnd4 = (close < ST1)Periodb= 20innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)HULLb = weightedaverage[round(sqrt(Periodb))](innerb)cnd5 = HULLb > HULLb[1]cnd6 = HULLb < HULLb[1]TIMEFRAME(default)ST2 = SuperTrend[3,10]cnd7 = (close > ST2)cnd8 = (close < ST2)//Stochastic RSI | indicatorlengthRSI = 14 //RSI periodlengthStoch = 14 //Stochastic periodsmoothK = 10 //Smooth signal of stochastic RSIsmoothD = 3 //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K2 = average[smoothK](stochrsi)*100D2 = average[smoothD](K2)cnd9 = K2>D2cnd10 = K2<D2Periodc= 20innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)HULLc = weightedaverage[round(sqrt(Periodc))](innerc)cnd11 = HULLc > HULLc[1]cnd12 = HULLc < HULLc[1]CndB = cnd1 and cnd3 and cnd5 and cnd7 and cnd9 and cnd11CndS = cnd2 and cnd4 and cnd6 and cnd8 and cnd10 and cnd12//Profit and LossSL = .6 // % STOP LOSSTP = 1.6 //% TARGET PROFIT3 users thanked author for this post.
05/20/2020 at 12:39 PM #132405Hello,
@Nonetheless, I have been trying to setup your 5m-Corona code on the Wall Street Cash (thanks for sharing!) but for some reasons my Probacktest are giving me no value. I think there might be some reasons to that:- Based in Hong Kong so I changed the time for version “a” to: Ctime = time >=213000 and time <230000
- The minimum order quantity I can set is 0.5, so I changed: ONCE startpositionsize = 0.5, ONCE minpositionsize = 0.5
- I don’t have access to Wall Street Cash €1 but I have either Wall Street Cash £1 or Wall Street Cash $10. Not sure if you have anything in your code that specifies this market.
So I don’t see where the problem might be coming from, and I wouldn’t mind some help 🙂
Thanks
05/20/2020 at 1:19 PM #132410The instrument (Wall St Cash £1 or $10) is not determined in the code, it will run on any chart you launch it from. For me it runs fine with your other settings so not sure where the problem is ???
05/20/2020 at 1:28 PM #132413minimum order quantity I can set is 0.5
Are you sure this is the min position? If I run mine with position size €.1 then I get the same result as you (my minimum is €.2)
Try it with startpositionsize = 1
05/20/2020 at 2:09 PM #132416The instrument (Wall St Cash £1 or $10) is not determined in the code, it will run on any chart you launch it from. For me it runs fine with your other settings so not sure where the problem is ???
Yes that’s what I thought so all good.
minimum order quantity I can set is 0.5
Are you sure this is the min position? If I run mine with position size €.1 then I get the same result as you (my minimum is €.2)
Try it with startpositionsize = 1
Yes, I am sure about the minimum position, I have attached a screenshot for the sake of being 100% sure.
I did some further test and weirdly if I change the time constraint and replace the “AND” by “OR”, I have a result.
Ctime = time >=213000 OR time <230000
But I am concerned that it may affect the results…
05/20/2020 at 2:35 PM #132422I am sure about the minimum position
your screenshot is the PRT chart, but the minimum position will be set by your broker. If you’re with IG, you have to go to their web platform and click on the info button, see attached image.
My first thought about the time was to change AND to OR, but that wouldn’t be right as you’re still in the same day. OR would only be used if it were
Ctime = time >=213000 OR time <010000
ie the second time is less than the first.
05/20/2020 at 2:54 PM #132424Yes, I understand and I assumed the OR would not be the solution.
I am with IG and the minimum position is 0.25 but it does not work with the “OR” if I use anything less than 0.5
May I attach the code “A” in here, maybe I am missing something…thanks for the help here!
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485DEFPARAM cumulateOrders = False // Cumulating positions deactivateDEFPARAM preloadbars = 1000//Money ManagementMM = 0 // = 0 for optimizationif MM = 0 thenpositionsize=0.5ENDIFif MM = 1 thenONCE startpositionsize = 0.5ONCE factor = 10 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etcONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverageONCE tier1 = 55 // IG first tier margin limitONCE maxpositionsize = 550 // IG tier 2 margin limitONCE minpositionsize = 0.5 // enter minimum position allowedIF Not OnMarket THENpositionsize = startpositionsize + Strategyprofit/(factor*margin)ENDIFIF Not OnMarket THENIF startpositionsize + Strategyprofit/(factor*margin) > tier1 thenpositionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 marginENDIFIF Not OnMarket THENif startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THENpositionsize = minpositionsize //keeps positionsize from going below allowed minimumENDIFIF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize thenpositionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limitENDIFENDIFENDIFENDIFCtime = time >=213000 and time <230000ONCE MAType = 54ONCE MATypeV2 = 14once Period = 15 //period1 // // set fixed to limit possible combinations of optimisationsonce Period2 = 15 // period2 second set of 69 averages // // set fixed to limit possible combinations of optimisationsSeries = (open+high+low+Close)/4 // kind of close of a barSeriesv2 = (open+high+low+Close)/4 // kind of close of a barOTD = Barindex - TradeIndex(1) > IntradayBarIndex // limits the (opening) trades till 1 per day (OTD One Trade per Day)TIMEFRAME(15 minutes)ST1 = SAR[.015,.01,.15]cnd1 = (close > ST1)cnd2 = (close < ST1)mx1 = average[60,3](close)cnd3 = mx1 > mx1[1]cnd4 = mx1 < mx1[1]TIMEFRAME(default)ST2 = SuperTrend[3,10]cnd5 = (close > ST2)cnd6 = (close < ST2)//Stochastic RSI | indicatorlengthRSI = 14 //RSI periodlengthStoch = 14 //Stochastic periodsmoothK = 10 //Smooth signal of stochastic RSIsmoothD = 3 //Smooth signal of smoothed stochastic RSImyRSI = RSI[lengthRSI](close)MinRSI = lowest[lengthStoch](myrsi)MaxRSI = highest[lengthStoch](myrsi)StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)K2 = average[smoothK](stochrsi)*100D2 = average[smoothD](K2)cnd7 = K2>D2cnd8 = K2<D2PeriodH2= 22innerH2 = 2*weightedaverage[round( PeriodH2/2)](typicalprice)-weightedaverage[PeriodH2](typicalprice)HULLb = weightedaverage[round(sqrt(PeriodH2))](innerH2)cnd9 = HULLb > HULLb[1]cnd10 = HULLb < HULLb[1]CndB = cnd1 and cnd3 and cnd5 and cnd7 and cnd9CndS = cnd2 and cnd4 and cnd6 and cnd8 and cnd10//Profit and LossSL = 1 // % STOP LOSSTP = 2 //% TARGET PROFITTST = .1//%trailing startST = .001 //% trailing step05/20/2020 at 3:48 PM #132433 -
AuthorPosts
Find exclusive trading pro-tools on