Forums › ProRealTime English forum › ProOrder support › A trading system based on the indicator One More Average MACD › Reply To: A trading system based on the indicator One More Average MACD
01/02/2020 at 12:23 PM
#115752
Thank you both! I tried to implement both your suggestions, but I still fail, now with an error… Thanks for your time!
v1.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
//------------------------------------------------------------------------- defparam cumulateorders=false Defparam preloadbars=10000 amount = 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 parameters Sensibility = 1 Adaptive = 1 //>MACD periods FLength = 24 SLength = 52 //>signal line SigLength = 9 Sigma = 4 Offset = 0.85 //-------- if barindex > 129 then Speed = Sensibility Speed = Max(Speed,-1.5) price = average[1](customclose) tconst=Speed //--Fast moving average FLength = Max(FLength,1) //adaptive period averagePeriod = FLength if adaptive=1 and averagePeriod > 1 then minPeriod = averagePeriod/2.0 maxPeriod = minPeriod*5.0 endPeriod = round(maxPeriod) signal = Abs((price-stored[endPeriod])) noise = 0.00000000001 for k=1 to endPeriod do noise=noise+Abs(price-stored[k]) averagePeriod = round(((signal/noise)*(maxPeriod-minPeriod))+minPeriod) next endif alpha = (2.0+tconst)/(1.0+tconst+averagePeriod) e1 = e1 + alpha*(price-e1) e2 = e2 + alpha*(e1-e2) v1 = 1.5 * e1 - 0.5 * e2 e3 = e3 + alpha*(v1 -e3) e4 = e4 + alpha*(e3-e4) v2 = 1.5 * e3 - 0.5 * e4 e5 = e5 + alpha*(v2 -e5) e6 = e6 + alpha*(e5-e6) Fast = 1.5 * e5 - 0.5 * e6 //------------------------------------ //--Slow moving average SLength = Max(SLength,1) //adaptive period SaveragePeriod = SLength if adaptive=1 and SaveragePeriod > 1 then SminPeriod = SaveragePeriod/2.0 SmaxPeriod = SminPeriod*5.0 SendPeriod = round(maxPeriod) Ssignal = Abs((price-stored[SendPeriod])) Snoise = 0.00000000001 for k=1 to SendPeriod do Snoise=Snoise+Abs(price-stored[k]) SaveragePeriod = round(((Ssignal/Snoise)*(SmaxPeriod-SminPeriod))+SminPeriod) next endif Salpha = (2.0+tconst)/(1.0+tconst+SaveragePeriod) Se1 = Se1 + Salpha*(price-Se1) Se2 = Se2 + Salpha*(Se1-Se2) Sv1 = 1.5 * Se1 - 0.5 * Se2 Se3 = Se3 + Salpha*(Sv1 -Se3) Se4 = Se4 + Salpha*(Se3-Se4) Sv2 = 1.5 * Se3 - 0.5 * Se4 Se5 = Se5 + Salpha*(Sv2 -Se5) Se6 = Se6 + Salpha*(Se5-Se6) Slow = 1.5 * Se5 - 0.5 * Se6 //------------------------------------ //--Signal moving average OMAMACD = Slow-Fast SigLength = Max(SigLength,1) //---Signal MA n = (Offset * (SigLength - 1)) t = SigLength/Sigma SWtdSum = 0 SCumWt = 0 for k = 0 to SigLength - 1 do SWtd = Exp(-((k-n)*(k-n))/(2*t*t)) SWtdSum = SWtdSum + SWtd * OMAMACD[SigLength - 1 - k] SCumWt = SCumWt + SWtd next SIGMACD = SWtdSum / SCumWt //------------------------------------ stored=price //------------------------------------ BullSMA=(SIGMACD<OMAMACD) BearSMA=(SIGMACD>OMAMACD) //--------------------------------------------------------------------------------// //Conditions when to act if (not longonmarket and BullSMA)then buy amount shares at market endif if (longonmarket and BearSMA and positionperf>0) then sell at market endif |