Machine Learning in ProOrder ProRealTime
Forums › ProRealTime English forum › ProOrder support › Machine Learning in ProOrder ProRealTime
- This topic has 454 replies, 32 voices, and was last updated 2 years ago by Khaled.
Tagged: machine learning
-
-
10/08/2020 at 6:07 PM #146782
Fantasio2020 whatever number of variables you prefer and works for you.
10/08/2020 at 6:07 PM #146783looks like I got the difference between 200k & 50k fixed on the same strategy. If reset is used, the cycle should restart again too.
One part will always be a bit doubtful, if reps 1 (ore more) is used, and in a backtest results is +0.01 and live -0.01 it can have on the impact on the rest of the strategy for value x & y.
That’s why it’s important I guess to have a reset, daily, weekly etc. depending on timeframe.
10/12/2020 at 3:36 PM #147174this is the code as I’ve it now.
Also interesting is to optimise the direction 1 to 6. The reset is set to daily here.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305once value1a=6 // 6once value2a=8 // 8once heuristicsengine=1// heuristics engineif heuristicsengine thenStartingValue = 4increment = 1 //5, 20, 10maxincrement = 2 //5, 10 limit of no of increments either up orreps = 1 //1 number of trades to use for analysis //2minvalue = 1 //5, minimum allowed valuemaxvalue = 10 //20, 300, 150 //maximum allowed 12StartingValue2 = 10increment2 = 1 //5, 10maxincrement2 = 2 //1, 30 limit of no of increments either up/down //4reps2 = 1 //1, 2 nos of trades to use for analysis //3minvalue2 = 1 //5, minimum allowed valuemaxvalue2 = 10 //20, 300, 200 maximum allowed valuereset = 1weighting = 1direction=1if direction=1 thena1=0a2=0a3=0a4=0elsif direction=2 thena1=1a2=0a3=1a4=0elsif direction=3 thena1=0a2=1a3=0a4=1elsif direction=4 thena1=1a2=0a3=0a4=1elsif direction=5 thena1=0a2=1a3=1a4=0elsif direction=6 thena1=1a2=1a3=1a4=1endifif reset=1 thenif intradaybarindex=0 thenValueX = StartingValueValuey = StartingValue2WinCountB = 0WinCountB2 = 0StratAvgB = 0StratAvgB2 = 0BestA = 0BestA2 = 0BestB = 0BestB2 = 0wincounta = 0 //initialize current win countstratavga = 0 //initialize current avg strategy profitwincounta2 = 0 //initialize current win countstratavga2 = 0 //initialize current avg strategy profitendifelseonce ValueX = StartingValueonce Valuey = StartingValue2once WinCountB = 0once WinCountB2 = 0once StratAvgB = 0once StratAvgB2 = 0once BestA = 0once BestA2 = 0once BestB = 0once BestB2 = 0endifheuristicscyclelimit = 2if reset=1 thenif intradaybarindex=0 thenheuristicscycle = 0endifelseonce heuristicscycle = 0endifonce heuristicsalgo1 = 1once heuristicsalgo2 = 0if heuristicscycle >= heuristicscyclelimit thenif heuristicsalgo1 = 1 thenheuristicsalgo2 = 1heuristicsalgo1 = 0elsif heuristicsalgo2 = 1 thenheuristicsalgo1 = 1heuristicsalgo2 = 0endifheuristicscycle = 0elseonce valuex = startingvalueonce valuey = startingvalue2endifif heuristicsalgo1 = 1 then//heuristics algorithm 1 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise = optimise + 1endifonce valuex = startingvalueonce pincpos = a1 //positive increment positiononce nincpos = a2 //negative increment positiononce optimise = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode1 = 0 //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 thenheuristicscycle = heuristicscycle + 1for i = 1 to reps doif positionperf(i) > 0 thenwincounta = wincounta + 1 //increment current wincountendifstratavga = stratavga + (((positionperf(i)*countofposition[i]*close)*-1)*-1)nextstratavga = 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 thenstratavgb = stratavga //update best strategy profitbesta = valuexendif//once bestb = 300//graph bestb coloured (0,0,0) as "bestb"if wincounta >= wincountb thenwincountb = wincounta //update best win countbestb = valuexendifif wincounta > wincountb and stratavga > stratavgb thenmode1 = 0elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 1 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 1 thenvaluex = min((valuex + (increment*pincpos)),maxvalue)pincpos = pincpos + 1mode1 = 1elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 2 thenvaluex = min((valuex + (increment*pincpos)),maxvalue)pincpos = pincpos + 1mode1 = 1elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 2 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2endifif nincpos > maxincrement or pincpos > maxincrement thenif besta = bestb thenvaluex = bestaElseif weighting=1 thenIf reps >= 10 ThenWeightedScore = 10ElseWeightedScore = round((reps/100)*100)EndIfValueX1 = min(round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20),maxvalue) //Lower Reps = Less weight assigned to Win%valuex=max(minvalue,valuex1)EndIfendifnincpos = 1pincpos = 1elsif valuex > maxvalue thenvaluex = maxvalueelsif valuex < minvalue thenvaluex = minvalueendifoptimise = 0endif// heuristics algorithm 1 endelsif heuristicsalgo2 = 1 then// heuristics algorithm 2 startif (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) thenoptimise2 = optimise2 + 1endifonce valuey = startingvalue2once pincpos2 = a3 //positive increment positiononce nincpos2 = a4 //negative increment positiononce optimise2 = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode2 = 0 //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 thenheuristicscycle = heuristicscycle + 1for i2 = 1 to reps2 doif positionperf(i2) > 0 thenwincounta2 = wincounta2 + 1 //increment current wincountendifstratavga2 = stratavga2 + (((positionperf(i2)*countofposition[i2]*close)*-1)*-1)nextstratavga2 = 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 thenstratavgb2 = stratavga2 //update best strategy profitbesta2 = valueyendif//once bestb2 = 300//graph bestb2 coloured (0,0,0) as "bestb2"if wincounta2 >= wincountb2 thenwincountb2 = wincounta2 //update best win countbestb2 = valueyendifif wincounta2 > wincountb2 and stratavga2 > stratavgb2 thenmode2 = 0elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 1 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 1 thenvaluey = min((valuey + (increment2*pincpos2)),maxvalue2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 < wincountb2 and stratavga2 < stratavgb2 and mode2 = 2 thenvaluey = min((valuey + (increment2*pincpos2)),maxvalue2)pincpos2 = pincpos2 + 1mode2 = 1elsif wincounta2 >= wincountb2 or stratavga2 >= stratavgb2 and mode2 = 2 thenvaluey = valuey - (increment2*nincpos2)nincpos2 = nincpos2 + 1mode2 = 2endifif nincpos2 > maxincrement2 or pincpos2 > maxincrement2 thenif besta2 = bestb2 thenvaluey = besta2Elseif weighting=1 thenIf reps2 >= 10 ThenWeightedScore2 = 10ElseWeightedScore2 = round((reps2/100)*100)EndIfValueY1 = min(round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20),maxvalue2)valuey=max(minvalue2,valuey1)//Lower Reps = Less weight assigned to Win%EndIfendifnincpos2 = 1pincpos2 = 1elsif valuey > maxvalue2 thenvaluey = maxvalue2elsif valuey < minvalue2 thenvaluey = minvalue2endifoptimise2 = 0endifendif// heuristics algorithm 2 endvalue1=valuexvalue2=valueyelsevalue1=value1avalue2=value2aendif1 user thanked author for this post.
10/12/2020 at 8:35 PM #14721610/12/2020 at 8:49 PM #14721810/26/2020 at 10:46 PM #148592Hi Juan, Hi All, I’m following your posts and grateful that you share a lot of fancy stuff here. Thanks. I’d like to better understand the operating mode of the so called ML and have a few questions:
1/ where does the programme store the various results learned from the past?
2/ what happen if the Algo is stopped for some reason? Are we starting again from scratch the “learning from the past” process? I noticed that even the Algo performance (calculated by PRT) are reset to zero when the same Algo is stopped and restarted, so I guess there is now way to capitalize on previous learning if the Algo is stopped, is that right? if so, is there a way to overcome this?
3/ have you been running “live” the same programme with and without ML module? Backtest seems to give better results? are you really getting better results in rel trading?
Facinating ML!!!
Thanks
10/27/2020 at 9:22 AM #148627Hi Khaled, I am unfortunately not very active on the forum lately as I am kept just way too busy between PRT development and my other work. But to briefly answer your questions:
1. It is stored locally in the respective variables defined in the code (WinCount, StratAvg, Best, etc.)
2. Yes unfortunately the variables are reset. Although they can be initialized using the commented out once code and using the graph command in backtest to find the latest values.
3. I use this successfully in most of my live strategies but only using a single heuristics set applied to a single variable not multiple ones as in the code aboveHope this helps
1 user thanked author for this post.
10/27/2020 at 4:17 PM #148681Hi Juan, Thank you for taking the time to answer my questions. I see in your ML Code that you don’t have CONDITIONS (IF C1 THEN..) before BUY and SHORTSELL instructions, which is not a problem in itself. However, in my case, the pending orders arenot cancelled automatically at the end of the candle, so I’m carying orders with irrelevant market conditions, which not only prevent other Orders with more “recent” conditions to come in but also sometimes stop the Algo…
Do you have a trick to make the pending orders cancel at the end of each candle?
Thanks
Khaled
123456789101112131415161718192021222324252627282930313233343536373839404142defparam cumulateorders = falsedefparam preloadbars = 2000TIMEFRAME (15 minutes)N = 1 //Number of ContractsCondition = 1/////////////////////////////////////////// CALCULATION OF VALUE X AND VALUE Y //////////////////////////////////////////boxsizeL = max ( ValueX , 20)boxsizeS = max ( ValueY , 10)renkomaxL = round(close / boxsizeL) * boxsizeLrenkominL = renkomaxL - boxsizeLrenkomaxS = round(close / boxsizeS) * boxsizeSrenkominS = renkomaxS - boxsizeSif high > renkomaxl + boxsizel thenrenkomaxl = renkomaxl + boxsizelrenkominl = renkominl + boxsizelendifif low < renkomins - boxsizes thenrenkomaxs = renkomaxs - boxsizesrenkomins = renkomins - boxsizesendifIF time>=133000 AND time>200000 thenspread = 0.5ELSIF time>=200000 AND time>220000 thenspread = 2.5ELSIF time>=220000 AND time>133000 thenspread = 1ENDIFIF CONDITION=1 THENBUY N CONTRACT at (renkoMaxL + boxSizeL + spread) STOPSELLSHORT N CONTRACT at (renkoMinS - boxSizeS - spread) STOPENDIFSET STOP pTRAILING 5SET TARGET pPROFIT 100011/01/2020 at 4:26 PM #149166I have a doubt, and I am not joking, nor hesitating.
You are dealing with a very interesting topic, but with so many explanations, so many codes, and so many posts it is impossible for me to know if there is something useful.
I don’t know, it would be interesting for someone to explain in a single post what the code is for and if there is any specific code that is really useful.
I have lost myself.
11/01/2020 at 5:31 PM #14917111/01/2020 at 6:44 PM #149190I was skeptical too and I’ve made a quick and dirty test. I’ve put together a simple LONG only code if SAR>Close and EMA21>EMA8 then buy 1 contract (Nasdaq cash 1€, 15 min TF) and exit if SAR<Close and Close<EMA8. This strategy run on a Tick by Tick mode over the period 10 Oct. 2018 to 30 Oct. 2020 (2 years) did generate a Win Rate 40.04%, Profit Ratio 1.09x and Capital gain 2048€ (attached results and ITF file).
I’ve added a simple ML code on 1 variable (courtesy of juanj) that you can find at (https://www.prorealcode.com/topic/machine-learning-in-proorder/), and the results are better: Win Rate 40.1%, Profit Ratio 1.2x and Capital gain 3057€ (attached results and ITF file). The increment in € absolute gain is +50%!
You can also note that the number of losing positions have been reduced from 950 to 814 and the Drawdown has been reduced from 1817€ to 1161€. The biggest loss went from -191€ to -113€.
So, even though I didn’t write the ML code and have nothing to sell 🙂 it seems like it’s working !
Others have had different experience?
1 user thanked author for this post.
11/01/2020 at 7:01 PM #149196And I thank you very sincerely Francesco, I learn a lot with all of you.But it is that in the meantime post and explanations I do not reach any conclusion.
Not only do I not know exactly how learning works, but I have also tried to include some algorithms in my strategies and, either I can’t, or the statistics come out exactly the same.I am not a professional programmer.
11/01/2020 at 7:03 PM #14919711/01/2020 at 7:09 PM #14919811/01/2020 at 7:16 PM #149203Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.
Thank you 🙂
-
AuthorPosts
Find exclusive trading pro-tools on