A trading system based on the indicator One More Average MACD
Forums › ProRealTime English forum › ProOrder support › A trading system based on the indicator One More Average MACD
- This topic has 20 replies, 6 voices, and was last updated 4 years ago by GraHal.
-
-
01/02/2020 at 7:52 AM #115728
Good morning and a Happy New Year!
I am trying to create a trading system based on the indicator posted by Nicolas, One More Average MACD, but I fail. I tried to tweak the different parameters but without any results. Any ideas why?
Thanks!!
Auto trading with indicator OneMoreAverage MACD123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130//-------------------------------------------------------------------------defparam cumulateorders=falseDefparam preloadbars=10000amount = 10 //quantity of shares/contracts to open for each new order//--------------------------------------------------------------------------------////Indicators//Indicator: PRC_OneMoreAverage MACD//Release date: 23.11.2016//Web: https://www.prorealcode.com/prorealtime-indicators/one-more-average-macd///Coded by: Nicolas @ www.prorealcode.com//--parameters//>OMA parametersSensibility = 1Adaptive = 1//>MACD periodsFLength = 24SLength = 52//>signal lineSigLength = 9Sigma = 4Offset = 0.85//--------Speed = SensibilitySpeed = Max(Speed,-1.5)price = average[1](customclose)tconst=Speed//--Fast moving averageFLength = Max(FLength,1)//adaptive periodaveragePeriod = FLengthif adaptive=1 and averagePeriod > 1 thenminPeriod = averagePeriod/2.0maxPeriod = minPeriod*5.0endPeriod = round(maxPeriod)signal = Abs((price-stored[endPeriod]))noise = 0.00000000001for k=1 to endPeriod donoise=noise+Abs(price-stored[k])averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)nextendifalpha = (2.0+tconst)/(1.0+tconst+averagePeriod)e1 = e1 + alpha*(price-e1)e2 = e2 + alpha*(e1-e2)v1 = 1.5 * e1 - 0.5 * e2e3 = e3 + alpha*(v1 -e3)e4 = e4 + alpha*(e3-e4)v2 = 1.5 * e3 - 0.5 * e4e5 = e5 + alpha*(v2 -e5)e6 = e6 + alpha*(e5-e6)Fast = 1.5 * e5 - 0.5 * e6//------------------------------------//--Slow moving averageSLength = Max(SLength,1)//adaptive periodaveragePeriod = SLengthif adaptive=1 and averagePeriod > 1 thenminPeriod = averagePeriod/2.0maxPeriod = minPeriod*5.0endPeriod = round(maxPeriod)signal = Abs((price-stored[endPeriod]))noise = 0.00000000001for k=1 to endPeriod donoise=noise+Abs(price-stored[k])averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)nextendifalpha = (2.0+tconst)/(1.0+tconst+averagePeriod)e1 = e1 + alpha*(price-e1)e2 = e2 + alpha*(e1-e2)v1 = 1.5 * e1 - 0.5 * e2e3 = e3 + alpha*(v1 -e3)e4 = e4 + alpha*(e3-e4)v2 = 1.5 * e3 - 0.5 * e4e5 = e5 + alpha*(v2 -e5)e6 = e6 + alpha*(e5-e6)Slow = 1.5 * e5 - 0.5 * e6//------------------------------------//--Signal moving averageOMAMACD = Slow-FastSigLength = Max(SigLength,1)//---Signal MAn = (Offset * (SigLength - 1))t = SigLength/SigmaSWtdSum = 0SCumWt = 0for k = 0 to SigLength - 1 doSWtd = Exp(-((k-n)*(k-n))/(2*t*t))SWtdSum = SWtdSum + SWtd * OMAMACD[SigLength - 1 - k]SCumWt = SCumWt + SWtdnextSIGMACD = SWtdSum / SCumWt//------------------------------------stored=price//------------------------------------BullSMA=(SIGMACD<OMAMACD)BearSMA=(SIGMACD>OMAMACD)//--------------------------------------------------------------------------------////Conditions when to actif (not longonmarket and BullSMA)thenbuy amount shares at marketendifif (longonmarket and BearSMA and positionperf>0) thensell at marketendif01/02/2020 at 9:36 AM #115730Vous utilisez le même nom pour 2 variables différentes.
Il faut un nom différent pour chaque nouvelle variable.1 user thanked author for this post.
01/02/2020 at 9:36 AM #11573101/02/2020 at 10:29 AM #115734Merci pour votre réponse rapide! Cependant, je ne comprends pas ce que vous voulez dire. OMAMACD et SIGMACD sont des variables différentes, ou voulez-vous dire quelques autres? Merci de votre patience!
Thanks for your quick answer! However, I do not understand what you mean. OMAMACD and SIGMACD are different variables, or do you mean some others? Thanks for your patience!
01/02/2020 at 11:18 AM #115739Like for example “averagePeriod” in the “Fast moving average”.
“AveragePeriod” in the “Slow moving average” must be renamed differently as “SaveragePeriod” and so on for all the variables written in black color.1 user thanked author for this post.
01/02/2020 at 11:32 AM #115745You need to ensure that there are enough bars before starting the calculations. With the standard settings it seems a minimum of 129 bars are required.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127//-------------------------------------------------------------------------defparam cumulateorders=falseDefparam preloadbars=10000amount = 1 //quantity of shares/contracts to open for each new order///PRC_OneMoreAverage MACD | indicator//23.11.2016//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledge//--parameters//>OMA parametersSensibility = 1Adaptive = 1//>MACD periodsFLength = 24SLength = 52//>signal lineSigLength = 9Sigma = 4Offset = 0.85//--------if barindex > 129 thenSpeed = SensibilitySpeed = Max(Speed,-1.5)price = average[1](customclose)tconst=Speed//--Fast moving averageFLength = Max(FLength,1)//adaptive periodaveragePeriod = FLengthif adaptive=1 and averagePeriod > 1 thenminPeriod = averagePeriod/2.0maxPeriod = minPeriod*5.0endPeriod = round(maxPeriod)signal = Abs((price-stored[endPeriod]))noise = 0.00000000001for k=1 to endPeriod donoise=noise+Abs(price-stored[k])averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)nextendifalpha = (2.0+tconst)/(1.0+tconst+averagePeriod)e1 = e1 + alpha*(price-e1)e2 = e2 + alpha*(e1-e2)v1 = 1.5 * e1 - 0.5 * e2e3 = e3 + alpha*(v1 -e3)e4 = e4 + alpha*(e3-e4)v2 = 1.5 * e3 - 0.5 * e4e5 = e5 + alpha*(v2 -e5)e6 = e6 + alpha*(e5-e6)Fast = 1.5 * e5 - 0.5 * e6//------------------------------------//--Slow moving averageSLength = Max(SLength,1)//adaptive periodaveragePeriod = SLengthif adaptive=1 and averagePeriod > 1 thenminPeriod = averagePeriod/2.0maxPeriod = minPeriod*5.0endPeriod = round(maxPeriod)signal = Abs((price-stored[endPeriod]))noise = 0.00000000001for k=1 to endPeriod donoise=noise+Abs(price-stored[k])averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)nextendifalpha = (2.0+tconst)/(1.0+tconst+averagePeriod)e1 = e1 + alpha*(price-e1)e2 = e2 + alpha*(e1-e2)v1 = 1.5 * e1 - 0.5 * e2e3 = e3 + alpha*(v1 -e3)e4 = e4 + alpha*(e3-e4)v2 = 1.5 * e3 - 0.5 * e4e5 = e5 + alpha*(v2 -e5)e6 = e6 + alpha*(e5-e6)Slow = 1.5 * e5 - 0.5 * e6//------------------------------------//--Signal moving averageOMAMACD = Slow-FastSigLength = Max(SigLength,1)//---Signal MAn = (Offset * (SigLength - 1))t = SigLength/SigmaSWtdSum = 0SCumWt = 0for k = 0 to SigLength - 1 doSWtd = Exp(-((k-n)*(k-n))/(2*t*t))SWtdSum = SWtdSum + SWtd * OMAMACD[SigLength - 1 - k]SCumWt = SCumWt + SWtdnextSIGMACD = SWtdSum / SCumWt//------------------------------------stored=price//Conditions when to actBullSMA=(SIGMACD<OMAMACD)BearSMA=(SIGMACD>OMAMACD)if (not longonmarket and BullSMA)thenbuy amount shares at marketendifif (longonmarket and BearSMA and positionperf>0) thensell at marketendifendifgraph sigmacdgraph omamacd1 user thanked author for this post.
01/02/2020 at 11:55 AM #115747Matriciel – Please only use English in the English speaking forums. Using two languages just bloats the topics.
In the code it is OK to use the same variable name several times in different calculations as its new value for it is calculated prior to its use each time. Its previous value is not part of the calculation so that is fine.
I just checked my code from my last post and it seems that the values of SIGMACD and OMAMACD are not calculated the same as the indicator returned values. Not sure why – might need to spend a little more time on this!
1 user thanked author for this post.
01/02/2020 at 12:23 PM #115752Thank you both! I tried to implement both your suggestions, but I still fail, now with an error… Thanks for your time!
v1.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130//-------------------------------------------------------------------------defparam cumulateorders=falseDefparam preloadbars=10000amount = 10 //quantity of shares/contracts to open for each new order//--------------------------------------------------------------------------------////Indicators//Indicator: PRC_OneMoreAverage MACD//Release date: 23.11.2016//Web: https://www.prorealcode.com/prorealtime-indicators/one-more-average-macd///Code translator: Nicolas @ www.prorealcode.com//--parameters//>OMA parametersSensibility = 1Adaptive = 1//>MACD periodsFLength = 24SLength = 52//>signal lineSigLength = 9Sigma = 4Offset = 0.85//--------if barindex > 129 thenSpeed = SensibilitySpeed = Max(Speed,-1.5)price = average[1](customclose)tconst=Speed//--Fast moving averageFLength = Max(FLength,1)//adaptive periodaveragePeriod = FLengthif adaptive=1 and averagePeriod > 1 thenminPeriod = averagePeriod/2.0maxPeriod = minPeriod*5.0endPeriod = round(maxPeriod)signal = Abs((price-stored[endPeriod]))noise = 0.00000000001for k=1 to endPeriod donoise=noise+Abs(price-stored[k])averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod)nextendifalpha = (2.0+tconst)/(1.0+tconst+averagePeriod)e1 = e1 + alpha*(price-e1)e2 = e2 + alpha*(e1-e2)v1 = 1.5 * e1 - 0.5 * e2e3 = e3 + alpha*(v1 -e3)e4 = e4 + alpha*(e3-e4)v2 = 1.5 * e3 - 0.5 * e4e5 = e5 + alpha*(v2 -e5)e6 = e6 + alpha*(e5-e6)Fast = 1.5 * e5 - 0.5 * e6//------------------------------------//--Slow moving averageSLength = Max(SLength,1)//adaptive periodSaveragePeriod = SLengthif adaptive=1 and SaveragePeriod > 1 thenSminPeriod = SaveragePeriod/2.0SmaxPeriod = SminPeriod*5.0SendPeriod = round(maxPeriod)Ssignal = Abs((price-stored[SendPeriod]))Snoise = 0.00000000001for k=1 to SendPeriod doSnoise=Snoise+Abs(price-stored[k])SaveragePeriod = round(((Ssignal/Snoise)*(SmaxPeriod-SminPeriod))+SminPeriod)nextendifSalpha = (2.0+tconst)/(1.0+tconst+SaveragePeriod)Se1 = Se1 + Salpha*(price-Se1)Se2 = Se2 + Salpha*(Se1-Se2)Sv1 = 1.5 * Se1 - 0.5 * Se2Se3 = Se3 + Salpha*(Sv1 -Se3)Se4 = Se4 + Salpha*(Se3-Se4)Sv2 = 1.5 * Se3 - 0.5 * Se4Se5 = Se5 + Salpha*(Sv2 -Se5)Se6 = Se6 + Salpha*(Se5-Se6)Slow = 1.5 * Se5 - 0.5 * Se6//------------------------------------//--Signal moving averageOMAMACD = Slow-FastSigLength = Max(SigLength,1)//---Signal MAn = (Offset * (SigLength - 1))t = SigLength/SigmaSWtdSum = 0SCumWt = 0for k = 0 to SigLength - 1 doSWtd = Exp(-((k-n)*(k-n))/(2*t*t))SWtdSum = SWtdSum + SWtd * OMAMACD[SigLength - 1 - k]SCumWt = SCumWt + SWtdnextSIGMACD = SWtdSum / SCumWt//------------------------------------stored=price//------------------------------------BullSMA=(SIGMACD<OMAMACD)BearSMA=(SIGMACD>OMAMACD)//--------------------------------------------------------------------------------////Conditions when to actif (not longonmarket and BullSMA)thenbuy amount shares at marketendifif (longonmarket and BearSMA and positionperf>0) thensell at marketendif01/02/2020 at 2:25 PM #115764I used Vonasi version and got attached … no error messages.
Ain’t never seen a Gain to Loss ratio as high as attached!!
1 user thanked author for this post.
01/02/2020 at 2:47 PM #115767but I still fail, now with an error
Your version just needs an extra endif adding at line 131
1 user thanked author for this post.
01/02/2020 at 3:03 PM #11576901/02/2020 at 4:28 PM #11577201/02/2020 at 4:34 PM #115776Ain’t never seen a Gain to Loss ratio as high as attached!!
That’s what happens if you never close any losing positions! The strategy does not exit unless it is profit. At some point you will find drawdown to be as impressive as gain/loss ratio!
2 users thanked author for this post.
01/02/2020 at 5:17 PM #115782Thank you for all your help. Truly appreciated! Take care and have a great start of 2020!
01/02/2020 at 5:28 PM #115784You too soulintact … keep on doing more of the same!!
I wish I had put both versions Live … they’ve made nearly £80 over 3 trades in the last 3 hours!!!! hahahahaha
-
AuthorPosts
Find exclusive trading pro-tools on