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
-
-
08/06/2017 at 7:29 PM #42568
I would like to start a discussion around the possibilities of making use of machine learning in ProRealTime. I have personally experimented with some heuristics algorithms in ProOrder but find it very limiting when having to optimize more than one variable. Here is an snippet of the code I use to optimize an variable called periods (i.e. Average[periods]):
12345678910111213141516171819202122232425262728293031323334// Heuristics Algorithmonce Periods = 42 //Variable to be optimizedonce Optimize = 0once Mode = 1 //switches between + and - incrementsonce Increment = 1 //initial increment valueonce StratAvgB = 0If Optimize = 10 Then //value is incremented by 1 at position entry or exitWinCount = 0 //Value used to determine minimum number of winning tradesStratAvgA = StratAvgBStratAvgB = 0For i = 1 to 10 Do //number of repittions to run past performance analysisIf positionperf(i) > 0 ThenWinCount = WinCount + 1EndIFStratAvgB = StratAvgB + StrategyProfit[i]NextStratAvgB = StratAvgB/10If (WinCount < 5 or StratAvgA > StratAvgB) and Mode = 1 ThenPeriods = Periods + (Increment+2)ElsIf (Winloss < 5 or StratAvgA > StratAvgB) and Mode = 2 ThenPeriods = Periods - (Increment*2) - 1mode = 1If Increment > 5 ThenPeriods = 42 //goes back to default valueIncrement = 1 //increment is resetElseIncrement = Increment + 1EndIFEndIFmode = 2Optimize = 0EndIfPlease share your own experience. @Wing @Nicolas I know you said you have also experimented with this, would you mind to share?
08/06/2017 at 8:06 PM #4257208/06/2017 at 9:38 PM #42579Will follow the thread. Have a lot of work deadlines to deal with but in 4-5 days I may be able to share something I have been working on previously.
Thank you @Noobywan for posting my thread. The project I plan to share is not related to that one.
08/07/2017 at 10:46 AM #42654Thanks for this code snippet about machine learning, it is inspiring! I’m currently on leave, so I can’t help a lot, I’m spending only 10 minutes on day on website 🙂
I made code indentation for a better comprehension of what you done, but I’m still thinking a part is missing? Sorry I’m confuse about it, but how do you know the “periods” you found with the code would have been better than the one used in the past? Would you mind adding comments starting from line 20?
08/07/2017 at 4:43 PM #42694Latest version of my Heuristics Algorithm (with comments):
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Heuristics Algorithm StartOnce Periods = 42 //Variable being optimized is initializedIncrement = 1MaxIncrement = 6Reps = 10 //Number of bars to use for analysisonce IncPos = 1 //Increment Positiononce Optimize = 0 //Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsonce WinCountB = 0 //Initialize Best Win Countonce StratAvgB = 0 //Initialize Best Avg Strategy ProfitIf Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinLossA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + StrategyProfit[i]NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = PeriodsElsIf WinCountA >= WinCountB ThenWinCountB = WinCountB //Update Best Win CountBestB = PeriodsEndIfIf WinCountA < WinCountB or StratAvgA < StratAvgB) and Mode = 1 ThenPeriods = Periods + (Increment*IncPos)ElsIf WinCountA < WinCountB or StratAvgA < StratAvgB) and Mode = 2 ThenPeriods = Periods - (Increment*IncPos)mode = 1If IncPos > MaxIncrement ThenIf BestA = BestB ThenPeriods = BestA //Periods is reset to best performing valueElsePeriods = (BestA+BestB)/2 //Periods is reset to best performing avg valueIncPos = 1EndIfIncPos = IncPos + IncrementEndIFEndIFmode = 2Optimize = 0EndIf// Heuristics Algorithm End1 user thanked author for this post.
08/07/2017 at 4:54 PM #42695There was an Syntax error in the above piece of code, here is the corrected and indented version:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// Heuristics Algorithm Startonce periods = 42 //Variable being optimized is initializedIncrement = 1MaxIncrement = 6Reps = 10 //Number of bars to use for analysisonce IncPos = 1 //Increment Positiononce Optimize = 0 //Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsonce WinCountB = 0 //Initialize Best Win Countonce StratAvgB = 0 //Initialize Best Avg Strategy ProfitIf Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + StrategyProfit[i]NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = PeriodsElsIf WinCountA >= WinCountB ThenWinCountB = WinCountB //Update Best Win CountBestB = PeriodsEndIfIf WinCountA < WinCountB or StratAvgA < StratAvgB and Mode = 1 ThenPeriods = Periods + (Increment*IncPos)ElsIf WinCountA < WinCountB or StratAvgA < StratAvgB and Mode = 2 ThenPeriods = Periods - (Increment*IncPos)mode = 1EndIfIf IncPos > MaxIncrement ThenIf BestA = BestB ThenPeriods = BestA //Periods is reset to best performing valueElsePeriods = (BestA+BestB)/2 //Periods is reset to best performing avg valueIncPos = 1EndIfIncPos = IncPos + IncrementEndIFmode = 2Optimize = 0EndIf// Heuristics Algorithm End1 user thanked author for this post.
08/10/2017 at 9:20 PM #4296908/11/2017 at 8:28 PM #43041Alright I have attached the code to this reply. It bears resemblance to the algorithm you showcase. This is a large piece of code, including a strategy, and an attached indicator which itself calls a whole bunch of indicators. Even though it relies on machine learning, I have optimized it previously and introduced time settings etc. to work on the DAX 30m timeframe. I think it has positive performance on higher timeframes too. I last worked on this in October or something, so everything after that is OOS. It has not performed good since then, but not bad either. Nevertheless the concept I want to showcase is explained by me in this thread: https://www.prorealcode.com/topic/code-correlation/
The system’s indicator calls a bunch of other indicators, and records the average value of these different indicators before a positive or negative move. Using this it constantly produces a prediction for future price. Since market regimes change, the history of indicator values is weighted to give more importance to recent market behvaiour.
You will find no comments in the code itself, but there is code in the link above you can view for better understanding.. This is experimental code I have not cleaned up, so there are features/stuff not currently in use still included. With what I know now I can improve on it a lot, maybe with the help of your ideas.
1 user thanked author for this post.
08/12/2017 at 7:32 AM #4305908/12/2017 at 12:27 PM #4307208/12/2017 at 1:09 PM #43080@wing thank you for your contribution, I haven’t gone through your code yet but looking forward to seeing what I can learn from it.
I’m very excited as to the potential of what we can achieve if we all collaborate.
As I read your post I was thinking of the concept of maybe using indicators as a form of dynamic array. Not sure yet how that will work but sure I will get some insights from your work.
Below is the latest version of my heuristics algorithm, it now has the ability to base it’s increments more towards the better performing side, but still switch if performance declines.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970// Heuristics Algorithm Startonce periods = 26 //initial value of the dynamic variable ('periods') to optimizeIncrement = 1 //Increment valueMaxIncrement = 7 //Maximum value to increment before updating initial valueReps = x //Number of trades to use for analysisonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce Optimize = 0 //Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsonce WinCountB = 0 //Initialize Best Win Count i.e. win rateonce StratAvgB = 0 //Initialize Best Avg Strategy Profit i.e. avg profit/tradeIf Optimize = Reps Then //Start heuristicsWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 Then //Determine win rate of current periodWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + StrategyProfit[i]NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = Periods //Update BestA with best performing valueEndIfIf WinCountA >= WinCountB ThenWinCountB = WinCountB //Update Best Win CountBestB = Periods //Update BestB with best performing valueEndIfIf WinCountA > WinCountB and StratAvgA > StratAvgB ThenMode = 0 //Strategy is performing well with current variable, do not optimizeElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenPeriods = Periods - (Increment*NIncPos)NIncPos = NIncPos + IncrementMode = 2 //Next cycle optimize with negative incrementsElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenPeriods = Periods + (Increment*PIncPos)PIncPos = PIncPos + IncrementMode = 1 //Next cycle again optimize with positive incrementsElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenPeriods = Periods + (Increment*PIncPos)PIncPos = PIncPos + IncrementMode = 1 //Next cycle optimize with positive incrementsElsIf WinCountA > WinCountB or StratAvgA > StratAvgB and Mode = 2 ThenPeriods = Periods - (Increment*NIncPos)NIncPos = NIncPos + IncrementMode = 2 //Next cycle again optimize with positive incrementsEndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement Then //Max increment value reachedIf BestA = BestB ThenPeriods = BestA //Update initial variable with the best performing valueElsePeriods = (BestA+BestB)/2 //Update initial variable with the average best performing valueEndIfNIncPos = 1 //reset increment valuesPIncPos = 1 //reset increment valuesEndIFOptimize = 0EndIf// Heuristics Algorithm End1 user thanked author for this post.
08/12/2017 at 1:13 PM #4308103/03/2020 at 12:50 PM #121059I am sharing this algorithm in the hopes that this community will help to improve it.
The algorithm can replace and dynamically adjust any variable set equal to it’s output variable called ‘ValueX’ (i.e. Average[Valuex](close)
The input and parameters to optimize are:
StartingValue //Initial or value used
ResetPeriod //Specify no of months after which to reset optimization Increment = 20
MaxIncrement //Limit of no of increments either up or down
Reps //Number of trades to use for analysis
MaxValue = //Maximum allowed value
MinValue = increment //Minimum allowed value123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105// Heuristics Algorithm StartIf onmarket[1] = 1 and onmarket = 0 Thenoptimize = optimize + 1EnDifStartingValue = 200ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement = 20MaxIncrement = 4 //Limit of no of increments either up or downReps = 3 //Number of trades to use for analysisMaxValue = 270 //Maximum allowed valueMinValue = increment //Minimum allowed valueonce monthinit = monthonce yearinit = yearIf (year = yearinit and month = (monthinit + ResetPeriod)) or (year = (yearinit + 1) and ((12 - monthinit) + month = ResetPeriod)) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0monthinit = monthyearinit = yearEndIfonce ValueX = StartingValueonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce 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 ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*100000)*-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 ThenMode = 0ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 2 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2EndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement ThenIf BestA = BestB ThenValueX = BestAElseIf reps >= 10 ThenWeightedScore = 10ElseWeightedScore = round((reps/100)*100)EndIfValueX = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos = 1PIncPos = 1ElsIf ValueX > MaxValue ThenValueX = MaxValueElsIf ValueX < MinValue ThenValueX = MinValueEndIFOptimize = 0EndIf// Heuristics Algorithm End4 users thanked author for this post.
03/03/2020 at 1:11 PM #12106403/03/2020 at 1:13 PM #121065 -
AuthorPosts
Find exclusive trading pro-tools on