Forums › ProRealTime English forum › ProOrder support › Machine Learning in ProOrder ProRealTime › Reply To: Machine Learning in ProOrder ProRealTime
I’m not sure ValueY is “broken” when it flatlines, I think it’s more to do with the settings that the code. Let me take a look at the code above.
Meanwhile can you please check the logic of your Long/Short BoxSize idea with my very simple entry conditions in Renko ML2 v3 below because the results are good not just on the Dow and £/$ but also on other instruments. I like to think a system is robust if it’s simple and can be applied to other markets particularly when you don’t have to alter settings to adjust for volatility. Great job.
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
//------------------------------------------------------------------------- // Main code : Nneless Renko DJI 1Month v3 Machine Learning (ML2) //https://www.prorealcode.com/topic/machine-learning-in-proorder/page/3/#post-121130 //------------------------------------------------------------------------- //https://www.prorealcode.com/topic/why-is-backtesting-so-unreliable/#post-110889 // Definition of code parameters //DEFPARAM CumulateOrders = False // Cumulating positions deactivated //defparam preloadbars = 1000 //defparam flatbefore = 080000 //defparam flatafter = 215500 // //once tradetype = 1 // [1]long&short;[2]long;[3]short // //once reenter = 1 //once positionperftype = 1 // [0] reenter always; [1] reenter positionperf < 0 //ctime=time>=080000 and time<180000 n=1 HeuristicsCycleLimit = 2 once HeuristicsCycle = 0 once HeuristicsAlgo1 = 1 once HeuristicsAlgo2 = 0 If HeuristicsCycle >= HeuristicsCycleLimit Then If HeuristicsAlgo1 = 1 Then HeuristicsAlgo2 = 1 HeuristicsAlgo1 = 0 ElsIf HeuristicsAlgo2 = 1 Then HeuristicsAlgo1 = 1 HeuristicsAlgo2 = 0 EndIf HeuristicsCycle = 0 EndIf If HeuristicsAlgo1 = 1 then //Heuristics Algorithm 1 Start If onmarket[1] = 1 and onmarket = 0 Then optimise = optimise + 1 Endif //Settings 1 & 2 StartingValue = 40 //5, 100, 10 Boxsize Increment = 10 //5, 20, 10 MaxIncrement = 10 //5, 10 Limit of no of increments either up or down Reps = 2 //1 Number of trades to use for analysis //2 MaxValue = 200 //20, 300, 150 //Maximum allowed value MinValue = 5 //5, Minimum allowed value StartingValue2= 40 //5, 100, 50 Stop Loss Increment2 = 10 //5, 10 MaxIncrement2 = 10 //1, 30 Limit of no of increments either up/down //4 Reps2 = 2 //1, 2 Nos of trades to use for analysis //3 MaxValue2 = 200 //20, 300, 200 Maximum allowed value MinValue2 = 5 //5, Minimum allowed value once ValueX = StartingValue once PIncPos = 1 //Positive Increment Position once NIncPos = 1 //Negative Increment Position once optimise = 0 //Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit) once Mode1 = 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 optimise = Reps Then WinCountA = 0 //Initialize current Win Count StratAvgA = 0 //Initialize current Avg Strategy Profit HeuristicsCycle = HeuristicsCycle + 1 For i = 1 to Reps Do If positionperf(i) > 0 Then WinCountA = WinCountA + 1 //Increment Current WinCount EndIf StratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*Close)*-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 Mode1 = 0 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode1 = 1 Then ValueX = ValueX - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode1 = 2 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode1 = 1 Then ValueX = ValueX + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode1 = 1 ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode1 = 2 Then ValueX = ValueX + (Increment*PIncPos) PIncPos = PIncPos + 1 Mode1 = 1 ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode1 = 2 Then ValueX = ValueX - (Increment*NIncPos) NIncPos = NIncPos + 1 Mode1 = 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 optimise = 0 EndIf // Heuristics Algorithm 1 End ElsIf HeuristicsAlgo2 = 1 Then // Heuristics Algorithm 2 Start If onmarket[1] = 1 and onmarket = 0 Then optimise2 = optimise2 + 1 Endif //Settings 2 once ValueY = StartingValue2 once PIncPos2 = 1 //Positive Increment Position once NIncPos2 = 1 //Negative Increment Position once optimise2 = 0 //Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit) once Mode2 = 1 //Switches between negative and positive increments //once WinCountB2 = 3 //Initialize Best Win Count //GRAPH WinCountB2 coloured (0,0,0) AS "WinCountB2" //once StratAvgB2 = 4353 //Initialize Best Avg Strategy Profit //GRAPH StratAvgB2 coloured (0,0,0) AS "StratAvgB2" If optimise2 = Reps2 Then WinCountA2 = 0 //Initialize current Win Count StratAvgA2 = 0 //Initialize current Avg Strategy Profit HeuristicsCycle = HeuristicsCycle + 1 For i2 = 1 to Reps2 Do If positionperf(i2) > 0 Then WinCountA2 = WinCountA2 + 1 //Increment Current WinCount EndIf StratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*Close)*-1)*-1) Next StratAvgA2 = StratAvgA2/Reps2 //Calculate Current Avg Strategy Profit //Graph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1-2" //Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2-2" //Graph StratAvgA2*-1 as "StratAvgA2" //once BestA2 = 300 //GRAPH BestA2 coloured (0,0,0) AS "BestA2" If StratAvgA2 >= StratAvgB2 Then StratAvgB2 = StratAvgA2 //Update Best Strategy Profit BestA2 = ValueY EndIf //once BestB2 = 300 //GRAPH BestB2 coloured (0,0,0) AS "BestB2" If WinCountA2 >= WinCountB2 Then WinCountB2 = WinCountA2 //Update Best Win Count BestB2 = ValueY EndIf If WinCountA2 > WinCountB2 and StratAvgA2 > StratAvgB2 Then Mode2 = 0 ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 1 Then ValueY = ValueY - (Increment2*NIncPos2) NIncPos2 = NIncPos2 + 1 Mode2 = 2 ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 1 Then ValueY = ValueY + (Increment2*PIncPos2) PIncPos2 = PIncPos2 + 1 Mode2 = 1 ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 Then ValueY = ValueY + (Increment2*PIncPos2) PIncPos2 = PIncPos2 + 1 Mode2 = 1 ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 Then ValueY = ValueY - (Increment2*NIncPos2) NIncPos2 = NIncPos2 + 1 Mode2 = 2 EndIf If NIncPos2 > MaxIncrement2 or PIncPos2 > MaxIncrement2 Then If BestA2 = BestB2 Then ValueY = BestA2 Else If reps2 >= 10 Then WeightedScore2 = 10 Else WeightedScore2 = round((reps2/100)*100) EndIf ValueY = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win% EndIf NIncPos2 = 1 PIncPos2 = 1 ElsIf ValueY > MaxValue2 Then ValueY = MaxValue2 ElsIf ValueY < MinValue2 Then ValueY = MinValue2 EndIF optimise2 = 0 EndIf // Heuristics Algorithm 2 End Endif boxSizeL = ValueX boxSizeS = ValueY renkoMaxL = ROUND(close / boxSizeL) * boxSizeL renkoMinL = renkoMaxL - boxSizeL renkoMaxS = ROUND(close / boxSizeS) * boxSizeS renkoMinS = renkoMaxS - boxSizeS IF high > renkoMaxL + boxSizeL THEN renkoMaxL = renkoMaxL + boxSizeL renkoMinL = renkoMinL + boxSizeL endif if low < renkoMinS - boxSizeS THEN renkoMaxS = renkoMaxS - boxSizeS renkoMinS = renkoMinS - boxSizeS ENDIF // //c1 = renkoMaxL + boxSizeL //c2 = renkoMinS - boxSizeS // Conditions to enter long positions //If c1 then Buy N CONTRACT at renkoMaxL + boxSizeL stop //EndIf // Conditions to enter short positions //If c2 then Sellshort N CONTRACT at renkoMinS - boxSizeS stop //EndIf // Stops and targets //SET STOP %loss 0.5 Set stop ptrailing 50 //100 SET TARGET PPROFIT 500 //Orig 150 //Best 500 graphonprice renkomaxl + boxsizel coloured(0,200,0) as "renkomax" graphonprice renkomins - boxsizes coloured(200,0,0) as "renkomin" GRAPH ValueX coloured(0,255,0) GRAPH ValueY coloured(255,0,0) //graphonprice newsl coloured(0,0,255,255) as "trailingstop atr" |
Edit: What does adding once ValueX = StartingValue etc, do that it wasn’t doing before that code was added? Cheers.