Forums › ProRealTime English forum › ProOrder support › Machine Learning in ProOrder ProRealTime › Reply To: Machine Learning in ProOrder ProRealTime
04/16/2020 at 4:24 PM
#126419
Machine learning implemented in a simple AUDCAD system, robustness test included.
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
defparam cumulateorders = false once longtrading= 1 once shorttrading= 1 n = 1 m = 3 l = 90 //Robustness Tester once j = 0 once flag = 1 if flag = 1 then j = j + 1 if j > 1 then flag = -1 j = j - 1 endif endif if flag = -1 then j = j - 1 if j = 0 then j = j + 1 flag = 1 endif endif tradeon = 1 if opendate >= 20000101 then if barindex mod 1 = 0 or barindex mod 1 = j then tradeon = 1 endif endif // Heuristics Algorithm Start If onmarket[1] = 1 and onmarket = 0 Then optimize = optimize + 1 EnDif StartingValue = 140 ResetPeriod = 26 //Specify no of months after which to reset optimization Increment = 20 MaxIncrement = 3 //Limit of no of increments either up or down Reps = 22 //Number of trades to use for analysis MaxValue = 320 //Maximum allowed value MinValue = increment //Minimum allowed value once monthinit = month once yearinit = year If (year = yearinit and month = (monthinit + ResetPeriod)) or (year = (yearinit + 1) and ((12 - monthinit) + month = ResetPeriod)) Then ValueX = StartingValue WinCountB = 0 StratAvgB = 0 BestA = 0 BestB = 0 monthinit = month yearinit = year EndIf once ValueX = StartingValue once PIncPos = 1 //Positive Increment Position once NIncPos = 1 //Neative Increment Position once Optimize = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit) once Mode = 1 //Switches between negative and positive increments //once WinCountB = 3 //Initialize Best Win Count //GRAPH WinCountB coloured (0,0,0) AS "WinCountB" //once StratAvgB = 4353 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB coloured (0,0,0) AS "StratAvgB" If Optimize = Reps Then WinCountA = 0 //Initialize current Win Count StratAvgA = 0 //Initialize current Avg Strategy Profit For i = 1 to Reps Do If positionperf(i) > 0 Then WinCountA = WinCountA + 1 //Increment Current WinCount EndIf StratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*100000)*-1)*-1) Next StratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1" //Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2" //Graph StratAvgA*-1 as "StratAvgA" //once BestA = 300 //GRAPH BestA coloured (0,0,0) AS "BestA" If StratAvgA >= StratAvgB Then StratAvgB = StratAvgA //Update Best Strategy Profit BestA = ValueX EndIf //once BestB = 300 //GRAPH BestB coloured (0,0,0) AS "BestB" If WinCountA >= WinCountB Then WinCountB = WinCountA //Update Best Win Count BestB = ValueX EndIf If WinCountA > WinCountB and StratAvgA > StratAvgB Then Mode = 0 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 Then ValueX = ValueX - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode = 2 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 Then ValueX = ValueX + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode = 1 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 Then ValueX = ValueX + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode = 1 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 2 Then ValueX = ValueX - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode = 2 EndIf If NIncPos > MaxIncrement or PIncPos > MaxIncrement Then If BestA = BestB Then ValueX = BestA Else If reps >= 10 Then WeightedScore = 10 Else WeightedScore = round((reps/100)*100) EndIf ValueX = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20) //Lower Reps = Less weight assigned to Win% EndIf NIncPos = 1 PIncPos = 1 ElsIf ValueX > MaxValue Then ValueX = MaxValue ElsIf ValueX < MinValue Then ValueX = MinValue EndIF Optimize = 0 EndIf // Heuristics Algorithm End cs= summation[n](close>open) = n cs = cs and close>bollingerup[valuex](close) and close>dlow(2) cl= summation[m](close<open) = m cl = cl and close<bollingerdown[valuex](close) and close<Dhigh(2) size = 2 //entry conditions if shorttrading then if cs and tradeon then sellshort size contract at market endif endif if longtrading then if cl and tradeon then buy size contract at market endif endif //exit conditions if shortonmarket and close<average[l](close) then exitshort at market endif if longonmarket and close>average[l](close) then sell at market endif // Stop and target SET TARGET pPROFIT 50 StartBreakeven = 30 // How much pips/points in gain to activate the Breakeven function? PointsToKeep = 0 // How much pips/points to keep in profit above of below our entry price when the Breakeven is activated (beware of spread) // Reset the BreakevenLevel when no trade are on market IF NOT ONMARKET THEN BreakevenLevel=0 ENDIF // Test if the price have moved favourably of "startBreakeven" points already IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN //Calculate the BreakevenLevel BreakevenLevel = tradeprice(1)+PointsToKeep*pipsize ENDIF // Place the new stop orders on market at BreakevenLevel IF BreakevenLevel>0 THEN SELL AT BreakevenLevel STOP ENDIF IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN //Calculate the BreakevenLevel BreakevenLevel = tradeprice(1)-PointsToKeep*pipsize ENDIF //Place the new stop orders on market at BreakevenLevel IF BreakevenLevel>0 THEN EXITSHORT AT BreakevenLevel STOP ENDIF |