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
-
-
04/11/2020 at 8:03 PM #125722
I figured it out, if I just put all my code and added variables to the imported GraHal “version” of my Ehler’s Univ Osc Supersmoother, I don’t need to rename any old systems that use the indicator. I’m still not sure why that new version of the indicator caused issues with renaming as described above considering as I can’t find any trace of it in the Bard itf !?
04/11/2020 at 8:22 PM #125724Cheers @GraHal, all sorted, I eventually decided to use your indicator as the template to put my old indicator and variables in to. Still unsure why there was an indicator name issue if the Bard.itf never had that Univ Osc code in it and your system only referenced the Ehler’s Univ Osc Supersmoother?
Been ML optimising both the long and short thresholds and the will start on the Bandedge too later and tomorrow. I found it better setting Reps1 and Reps2 to 10 instead of 3. How is 3 enough to determine that a parameter would even need adjusting?
I also changed the increments from 10 to 20 so it can go from -1 to 1 in increments of 0.1.
If we’re happy leaving the oscillator thresholds at -0.8 and 0.8 and want to self optimise the Bandedge how is that coded I wonder? I note the rem’d out 100 bandedge in the strategy. You’d need to have added it as a variable with the spanner in the Univ Osc indicator code. I think I would code it like this:
Long Entry12indicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueX]c1 = (indicator1 CROSSES OVER -0.8)but I am just not sure how the ML code handles added variables? I’ll try in a bit as I’m still looking at ML’ing the thresholds on different timeframes/instruments.
Great job! Cheers again @GraHal
04/11/2020 at 8:57 PM #125726I only have two words to say @Juanj, F%*$ Me!
Thank you so much for this Machine Learning code and thanks @GraHal, @Vonasi,This was my first test using ML. I double optimised the ML code to take care of both the Long and the Short side of Ehler’s Univ Osc Supersmoother oscillator thresholds (range from -1 to 1) and compared it to the basic non ML version using Buy at -0.8 and Sell at 0.8: Pls see image.
I upped the Reps from 3 to 5, and the MaxIncrements to 20 (from 10) to allow it to calculate from -1 to 1 on the oscillator in steps of 0.1 and choose a random date range.
Spread was 3.8 Daily Dow Jones. Note if anyone can figure out why, when set on all available data with 10,000 units, the ML version doesn’t trade between 1982 and 2003 that would be good to know?
(Don’t worry about the -£114k, it’s the demo which was up 60% to £160k… before the Covid19 market rout…Here’s the full system and indicator code for anyone how wants to experiment with it:
Ehler's Universal Oscillator System123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271//Ehler's Univ Osc SuperSmoother -- Machine Learning (ML)// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivated// Heuristics Algorithm 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) Thenoptimize = optimize + 1EndIfStartingValue = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement = 0.1//20MaxIncrement = 20 //4//Limit of no of increments either up or downReps = 5 //Number of trades to use for analysis //3MaxValue = 1 //270 //Maximum allowed valueMinValue = 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//EndIfonce 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 End// Heuristics Algorithm 2 Start ////////////////////////////////////////////////////If (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) Thenoptimize2 = optimize2 + 1EndIfStartingValue2 = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement2 = 0.1//20MaxIncrement2 = 20 //4//Limit of no of increments either up or downReps2 = 5 //Number of trades to use for analysis //3MaxValue2 = 1 //270 //Maximum allowed valueMinValue2 = increment //Minimum allowed value//once monthinit2 = month//once yearinit2 = year//If (year = yearinit2 and month = (monthinit2 + ResetPeriod2)) or (year = (yearinit2 + 1) and ((12 - monthinit2) + month = ResetPeriod2)) Then//ValueY = StartingValue2//WinCountB2 = 0//StratAvgB2 = 0//BestA2 = 0//BestB2 = 0//monthinit2 = month//yearinit2 = year//EndIfonce ValueY = StartingValue2once PIncPos2 = 1 //Positive increment2 Positiononce NIncPos2 = 1 //Neative increment2 Positiononce Optimize2 = 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 Optimize2 = Reps2 ThenWinCountA2 = 0 //Initialize current Win CountStratAvgA2 = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i2 = 1 to Reps2 DoIf positionperf(i2) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*100000)*-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 = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2EndIfIf NIncPos2 > MaxIncrement2 or PIncPos > MaxIncrement2 ThenIf BestA2 = BestB2 ThenValueY = BestA2ElseIf reps2 >= 10 ThenWeightedScore2 = 10ElseWeightedScore2 = round((reps2/100)*100)EndIfValueY = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos2 = 1PIncPos2 = 1ElsIf ValueY > MaxValue2 ThenValueY = MaxValue2ElsIf ValueY < MinValue2 ThenValueY = MinValue2EndIFOptimize2 = 0EndIf// Heuristics Algorithm 2 End//Note: Bandedge: 50 and crosses of 0.5 and -0.5 is good on daily indices.//Bandedge: 24 and crosses of 0.1 and -0.1 work, depending on asset class.//Bandedge Setting://Univ Osc Bandedge = 100 set in Variables// Conditions to enter long positionsindicator1, ignored = CALL "Ehler's Univ Osc SuperSm ORIG"[100]c1 = (indicator1 CROSSES OVER ValueX)IF c1 THENBUY 10 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator2, ignored = CALL "Ehler's Univ Osc SuperSm ORIG"[100]c2 = (indicator2 CROSSES UNDER 0.0)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator3, ignored = CALL "Ehler's Univ Osc SuperSm ORIG"[100]c3 = (indicator3 CROSSES UNDER ValueY)IF c3 THENSELLSHORT 10 PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator4, ignored = CALL "Ehler's Univ Osc SuperSm ORIG"[100]c4 = (indicator4 CROSSES OVER 0.0)IF c4 THENEXITSHORT AT MARKETENDIF// Stops and targetsSet stop trailing 100GRAPH ValueXGRAPH ValueYIndicator :
Ehler's Univ Osc SuperSmoother12345678910111213141516171819202122232425262728293031323334//bandedge= 100 //Default = 25whitenoise= (Close - Close[2])/2if barindex>bandedge then// super smoother filtera1= Exp(-1.414 * 3.14159 / bandedge)b1= 2*a1 * Cos(1.414*180 /bandedge)c2= b1c3= -a1 * a1c1= 1 - c2 - c3filt= c1 * (whitenoise + whitenoise[1])/2 + c2*filt[1] + c3*filt[1]filt1 = filtif ABS(filt1)>pk[1] thenpk = ABS(filt1)elsepk = 0.991 * pk[1]endifif pk=0 thendenom = -1elsedenom = pkendifif denom = -1 thenresult = result[1]elseresult = filt1/pkendifendifRETURN result COLOURED(0,0,0) style(dottedline,1) as "Universal Oscillator", 0 as "0"2 users thanked author for this post.
04/11/2020 at 11:27 PM #125735Here I’ve added 3 lots of Machine Learning Algos in the same System. (Please check coding, I wasn’t sure how to code graphs for Positionperf?). I’m still learning about the way this algo works and will probably be asking more questions soon, but I have to say this is a major breakthrough.
The first two identical setting ML algos (ValueX and ValueY) deal with the Ehler’s Universal Oscillator Supersmoother’s Long and Short Threshold entries, between -1 and +1. in steps of 0.1.
The added third ML algo (ValueZ) then looks at the Bandedge setting for the Oscillator (it’s like a sensitivity setting, we’ve all seen RSI’s in strong up moves where the RSI hogs the upper range and flatlines giving no useful info, this setting if set to lower form 100 down 25 will allow for more definition, if set to 100 it’ll look like that overloaded RSI but still be more accurate).I compared the standard Ehler’s Universal Oscillator Supersmoother system (last equity curve at the bottom), as a base test, compared to ML systems with one ML algo, two ML’s algos and finally three ML’s algos, see the very top equity chart.
The Bandedge from experience can be increased in increments of 25, but over 125 there’s not much difference in performance as I recall going much higher. The performance is reasonable (with 20% Drawdown) and I’m sure the Exits could be improved instead of using mean zero level or a trailing stop (set at a generic 100 point but not optimised or tested), maybe with a Kase Dev Stop or Kaufman Volatility Stop… but anyhow, the point of this post is to notice how the equity curve goes nicely from the bottom left to top right of the graph.Code below, (indicator code already been posted in comments before this one).
Blue Skies!! @Gabri! Lol.
Ehler's Univ Osc w. 3 x ML123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388// Ehler's Universal Oscillator Supersmoother Machine Learning (MLx3)// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivated// Heuristics Algorithm 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) Thenoptimize = optimize + 1EndIfStartingValue = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement = 0.1//20MaxIncrement = 20 //4//Limit of no of increments either up or downReps = 3 //Number of trades to use for analysis //3MaxValue = 1 //270 //Maximum allowed valueMinValue = 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//EndIfonce ValueX = StartingValue //LONG THRESHOLDonce 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 End// Heuristics Algorithm 2 Start ////////////////////////////////////////////////////If (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) Thenoptimize2 = optimize2 + 1EndIfStartingValue2 = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement2 = 0.1//20MaxIncrement2 = 20 //4//Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysis //3MaxValue2 = 1 //270 //Maximum allowed valueMinValue2 = increment2 //Minimum allowed value//once monthinit2 = month//once yearinit2 = year//If (year = yearinit2 and month = (monthinit2 + ResetPeriod2)) or (year = (yearinit2 + 1) and ((12 - monthinit2) + month = ResetPeriod2)) Then//ValueY = StartingValue2//WinCountB2 = 0//StratAvgB2 = 0//BestA2 = 0//BestB2 = 0//monthinit2 = month//yearinit2 = year//EndIfonce ValueY = StartingValue2 ///SHORT THRESHOLDonce PIncPos2 = 1 //Positive increment2 Positiononce NIncPos2 = 1 //Neative increment2 Positiononce Optimize2 = 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 Optimize2 = Reps2 ThenWinCountA2 = 0 //Initialize current Win CountStratAvgA2 = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i2 = 1 to Reps2 DoIf positionperf(i2) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*100000)*-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 = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2EndIfIf NIncPos2 > MaxIncrement2 or PIncPos > MaxIncrement2 ThenIf BestA2 = BestB2 ThenValueY = BestA2ElseIf reps2 >= 10 ThenWeightedScore2 = 10ElseWeightedScore2 = round((reps2/100)*100)EndIfValueY = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos2 = 1PIncPos2 = 1ElsIf ValueY > MaxValue2 ThenValueY = MaxValue2ElsIf ValueY < MinValue2 ThenValueY = MinValue2EndIFOptimize2 = 0EndIf// Heuristics Algorithm 2 End// Heuristics Algorithm 3 Start ////////////////////////////////////////////////////If (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) Thenoptimize3 = optimize3 + 1EndIfStartingValue3 = 25 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement3 = 5//20MaxIncrement3 = 20 //4//Limit of no of increments either up or downReps3 = 3 //Number of trades to use for analysis //3MaxValue3 = 125 //270 //Maximum allowed valueMinValue3 = increment3 //Minimum allowed value//once monthinit3 = month//once yearinit3 = year//If (year = yearinit3 and month = (monthinit3 + ResetPeriod3)) or (year = (yearinit3 + 1) and ((12 - monthinit3) + month = ResetPeriod3)) Then//ValueZ = StartingValue3//WinCountB3 = 0//StratAvgB3 = 0//BestA3 = 0//BestB3 = 0//monthinit3 = month//yearinit3 = year//EndIfonce ValueZ = StartingValue3 //BANDEDGEonce PIncPos3 = 1 //Positive increment2 Positiononce NIncPos3 = 1 //Neative increment2 Positiononce Optimize3 = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode2 = 1 //Switches between negative and positive increments//once WinCountB3 = 3 //Initialize Best Win Count//GRAPH WinCountB3 coloured (0,0,0) AS "WinCountB2"//once StratAvgB3 = 4353 //Initialize Best Avg St3ategy Profit//GRAPH StratAvgB3 coloured (0,0,0) AS "StratAvgB3"If Optimize3 = Reps3 ThenWinCountA3 = 0 //Initialize current Win CountStratAvgA3 = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i3 = 1 to Reps3 DoIf positionperf(i3) > 0 ThenWinCountA3 = WinCountA3 + 1 //Increment Current WinCountEndIfStratAvgA3 = StratAvgA3 + (((PositionPerf(i3)*countofposition[i3]*100000)*-1)*-1)NextStratAvgA3 = StratAvgA3/Reps3 //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"///////////// 3?//Graph StratAvgA3*-1 as "StratAvgA3"//once BestA3 = 300//GRAPH BestA3 coloured (0,0,0) AS "BestA3"If StratAvgA3 >= StratAvgB3 ThenStratAvgB3 = StratAvgA3 //Update Best Strategy ProfitBestA3 = ValueZEndIf//once BestB3 = 300//GRAPH BestB3 coloured (0,0,0) AS "BestB3"If WinCountA3 >= WinCountB3 ThenWinCountB3 = WinCountA3 //Update Best Win CountBestB3 = ValueZEndIfIf WinCountA3 > WinCountB3 and StratAvgA3 > StratAvgB3 ThenMode2 = 0ElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode2 = 1 ThenValueZ = ValueZ - (Increment3*NIncPos3)NIncPos3 = NIncPos3 + 1Mode2 = 2ElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode2 = 1 ThenValueZ = ValueZ + (Increment3*PIncPos3)PIncPos3 = PIncPos3 + 1Mode2 = 1ElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode2 = 2 ThenValueZ = ValueZ + (Increment3*PIncPos3)PIncPos3 = PIncPos3 + 1Mode2 = 1ElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode2 = 2 ThenValueZ = ValueZ - (Increment3*NIncPos3)NIncPos3 = NIncPos3 + 1Mode2 = 2EndIfIf NIncPos3 > MaxIncrement3 or PIncPos > MaxIncrement3 ThenIf BestA3 = BestB3 ThenValueZ = BestA3ElseIf reps3 >= 10 ThenWeightedScore3 = 10ElseWeightedScore3 = round((reps3/100)*100)EndIfValueZ = round(((BestA3*(20-WeightedScore3)) + (BestB3*WeightedScore3))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos3 = 1PIncPos3 = 1ElsIf ValueZ > MaxValue3 ThenValueZ = MaxValue3ElsIf ValueZ < MinValue3 ThenValueZ = MinValue3EndIFOptimize3 = 0EndIf// Heuristics Algorithm 3 End//Note: Bandedge: 50 and crosses of 0.5 and -0.5 is good on daily indices.//Bandedge: 24 and crosses of 0.1 and -0.1 work, depending on asset class.//Bandedge Setting://Univ Osc Bandedge = 25// Conditions to enter long positionsindicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ] // indicator1,2,3,4 = Univ Osc, ignored = Mid 0 Linec1 = (indicator1 CROSSES OVER ValueX)IF c1 THENBUY 10 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator2, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c2 = (indicator2 CROSSES UNDER 0.0)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator3, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c3 = (indicator3 CROSSES UNDER ValueY)IF c3 THENSELLSHORT 10 PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator4, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c4 = (indicator4 CROSSES OVER 0.0)IF c4 THENEXITSHORT AT MARKETENDIF// Stops and targetsSet stop trailing 100GRAPH ValueXGRAPH ValueYGRAPH ValueZ04/12/2020 at 10:24 AM #12576104/12/2020 at 11:36 AM #12576604/12/2020 at 1:38 PM #125787HELLO Bard and thank you for your work I tried today Sunday to make the code work, but I can’t do it
If I understood correctly, the code works with 1 indicator code and 1 strategy code, right? Maybe there is an error and sending two ITF files would be better? cordially04/13/2020 at 1:01 PM #125922Yeah, I kind of did @GraHal, so many things to look at and test! I know it’s not a “pancea” as you put it and in fact, one of my generic Univ Osc systems (set at -0.8/0.8, bandedge =100) performed far better than the one, two or three ML algo system versions, (I might post that example and see if anyone can figure out why), but it is definitely a highly useful addition to the existing PRC codes that are on this site.
I had a lot of thoughts about it, even as writing this now I just thought, what if it was applied to Money Management position sizing? Would anyone like to have a look at that?
So on Friday night, having run the ML system with two algos (for Universal Oscillator threshold, individual Long and Short entries (the Bandedge was static and set to 100)) and the ML system with 3 algos which also optimised the Bandedge too as well as the entry thresholds, and then tested them together on Coffee, pls see image, this time ML x2 performed far better that the ML x3.
So…. my thought was… @Juanj, is there a way to put both ML2 and ML3 codes in the same system and then have them “fight it out,” or self optimise and find the better of the two systems (ML2 and ML3)? Perhaps the two systems switch and alternate back and forth, much like the self optimised variables selected in these ML algos? It would kind of be like having a backup plan in case one of the two systems performs poorly. If Juanj is busy, can anyone else think of a way that could be done?
As for performance metrics that Juanj mentioned, can anyone code Sharp or Sortino Ratios to be included in the ML code? Here’s a copy and paste from Van Tharp’s page on he performance metrics subject:
System Performance, Part IV
A ratio I like to use is the average annual percentage gain divided by the maximum draw down. This gives us a ratio of how much we make per year divided by how much we would be down at any time during the year. Or in simple terms: How much will I have to risk losing in order to generate my average returns? Any ratio of that is less than 2:1 is suspect (do you really want to risk a 50 percent draw down to make a 50% gain?).
Industry standard performance measures. Let’s close by looking at two composite numbers that many money managers use to measure their performance:
1. Sharpe Ratio: (system rate of return – risk-free rate of return) / standard deviation of system returns.
The Sharp Ratio measures risk to reward by giving the returns of the system as a ratio to its standard deviation. If the system has very constant returns, it will have a high Sharpe Ratio. A system with returns that vary greatly period-to-period will have a lower Sharpe Ratio.
2. Sortino Ratio: One problem with the Sharpe Ratio is that it penalizes a system for a big up month or “good volatility”. The Sortino Ratio attempts to overcome this issue by dividing the same risk-adjusted rate of return used in the Sharpe Ratio by only the negative deviation or “bad volatility” (the downside semi-variance).
https://www.vantharp.com/trading/system-performance-2/
04/13/2020 at 1:09 PM #125926Sure @bertrandpinoy, the next time I launch PRT, which maybe later today or tomorrow.
04/13/2020 at 1:23 PM #125929I am commenting as I see them in your post … else I will forget! 🙂this time ML x2 performed far better that the ML x3.
Are you 100% sure HAlgo3 didn’t have any HAlgo 2 references remaining / cross referring?
have them “fight it out,” or self optimise
Re above … did you see / understand below? I never got it to work, but you may have more success??
The HeuristicsCycleLimit parameter will determine how many ‘cycles’ each algorithm gets.
04/13/2020 at 5:52 PM #125980Are you 100% sure HAlgo3 didn’t have any HAlgo 2 references remaining / cross referring?
ML 3 has the added self optimisation of the ValueZ bandedge setting as well as the original ValueX Long and ValueY Short thresholds (which is all ML 2 is determining, just thresholds). Is that what you mean?
Re above … did you see / understand below? I never got it to work, but you may have more success??
Sorry, not sure I’m following you? “understand below”? What didn’t you get to work?
So the ML2 “fighting it out” with ML3 (from the coffee trade image above), can be achieved with the HeuristicsCycleLimit code below: ?
Heuristics Algo 1 and 21234567891011121314151617HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIfSo, if my triple ML3 version above was to include this HeuristicsCycleLimit code are you’re saying that the system can then be self optimising the ML2 and ML3 separate systems but now all under the cover of one system? What would the code look like specifically relating to the parts concerning the Cycle Limit? I was looking at https://www.prorealcode.com/topic/machine-learning-in-proorder/page/5/#post-121436 for ideas:
123456789101112131415pp=positionperf(0)*100IF pp<-0.02 and HeuristicsAlgo2 and longonmarket thenHeuristicsAlgo1 = 1SELL AT MARKETelsif pp<-0.05 and HeuristicsAlgo1 and shortonmarket thenHeuristicsAlgo2 = 1EXITSHORT AT MARKETendifc1=average[ValueX](close)c2=average[ValueY](close)//condbuy = c1 crosses over c2 and rsi[14](close)<50condsell= c1 crosses under c2 and rsi[14](close)>40I can see that “Heuristics Algorithm 1″ and “Heuristics Algorithm 2” are used in the ML2 system and “Heuristics Algorithm 1,” “Heuristics Algorithm 2” and “Heuristics Algorithm 3” are used in the ML3 system, it’s just that I haven’t used the Heuristicyclelimit in either ML2 or ML3 and can’t quite figure the coding in my head to get the New System to self optimise between the ML2 and ML3 components? Hope that makes sense!
04/13/2020 at 6:44 PM #125984Is that what you mean?
No! 🙂
I was asking if you are 100% sure that your HAlgo 3 is 100% unique coded / separate from HAlgo 2 … no duplicated commands or variables?
not sure I’m following you? “understand below”?
Did you click on the link that was below the statement I made referring to ‘below’?
Here is the link again, it provides a code snippet that JuanJ provided for use when a System includes more than one HAlgo in the same System.
The HeuristicsCycleLimit parameter will determine how many ‘cycles’ each algorithm gets.
04/13/2020 at 6:57 PM #12598604/13/2020 at 10:47 PM #126005Ha ha, the “joys” of non verbal communication 😀 What is your concern with cross referencing?
If HAlgo 3, as you call the ML3 system is nothing but HAlgo2/ML2 but with an added Bandedge optimisation too — as described above and which can be seen by looking at the code and seeing the extra ValueZ (bandedge) optimisaton — the coffee example/image is still showing what happens when you set these two systems in a race with each other. ML2 wins. The outcome of ML2 and ML 3 are still independent.
Below, right I get you.
Three algos in one system… I just got really curious to see what would happen! I’d already read Juanj’s comment about optimising two variables and the potential issue of the algo not being able to determine which one (ValueX or ValueY) is causing the performance increase or decrease: (I copied and pasted all the best points from this thread into a text edit page, it makes getting to grips with the code easier if you can just scroll up and down fast using the highlight tool for bits of code or ideas/phrases like “cyclelimit”).Francesco asked: “Could this be applied to more then a value in the same system?”
Juanj replied: “Depends on what you mean. If it is the same target variable just used in different sections of the code then yes else no. The reason being that if you apply it to 2 or more different variables the algorithm will not be able to tell which one is causing the performance increase or decrease. I have experimented with literally duplicating the algorithm (slightly changing the name of each variable in the algorithm) and assigning it’s output to a second variable. And although this works to some extent it definitely reduces the accuracy and efficacy of the algorithm for the same reasons mentioned above.’
https://www.prorealcode.com/topic/machine-learning-in-proorder/page/2/#post-121090
Juan: “The HeuristicsCycleLimit parameter will determine how many ‘cycles’ each algorithm gets. “ and… “Best is to code it so that each algo gets it’s own evaluation period. Although it would require at least 2 evaluation periods to really know if performance is increasing or decreasing. So perhaps an additional ‘wait counter’ should be built into the strategy giving each algo 2 or more evaluation periods before giving the next algo a turn.”
https://www.prorealcode.com/topic/machine-learning-in-proorder/page/2/#post-121129
“We try and get ‘JuanJ Heuristic Cycle Limit’ code working in Systems using 2 or more HAlgos??“
It kind of already is, there is ValueX, ValueY and now ValueZ all in within one ML3 system (I put all the settings for each at the top of the code). It may not be optimal, but it does appear to be increasing performance, unless it’s coffee, which worked better with ML2, (the system with two algos, ValueX and ValueY for long and short entry)… which is why I thought why not have ML2 system and ML3 system, (with it’s long (ValueX) and short (ValueY) + Bandedge (ValueZ)) “fight it out” under one roof (in a new system).
My question is how to now code ML2 and ML3 – two formerly separate systems, one which just optimised the long and short entries and the other that did that and also the bandedge setting – to have them now housed under one roof and use the heuristiccyclelimit to let those two (soon to be, if we can code it) sub-systems compete with each other?
Do you or anyone else have any ideas how to code that heuristiccyclelimit for this to work under “one roof?”
04/14/2020 at 2:50 AM #126009“We try and get ‘JuanJ Heuristic Cycle Limit’ code working in Systems using 2 or more HAlgos??“
Sorry I see what you mean (I was only looking at the second half of your sentence). I’ve been looking at the Heuristic Cycle Limit code and wondered how to add it without getting floating code from the left margin?
Adding Juanj’s heuristic code from https://www.prorealcode.com/topic/machine-learning-in-proorder/page/3/#post-121130
(and including the heuristic initialisation code at the beginning_ also does the same, like the code isn’t syntax-ing correctly because of the float away from the left margin?
Pls see images. I’m sure it’s really a simple fix for a coder but closing open statements by adding Endif’s hasn’t fixed it.I also wondered if this is correct if using 3 algos in one system?:
Triple Heuristic1234567891011121314151617181920212223242526HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0once HeuristicsAlgo3 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo1 = 0HeuristicsAlgo2 = 1HeuristicsAlgo3 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0HeuristicsAlgo3 = 0ElsIf HeuristicsAlgo3 = 1 ThenHeuristicsAlgo1 = 0HeuristicsAlgo2 = 0HeuristicsAlgo3 = 1EndIfHeuristicsCycle = 0EndIfIf HeuristicsAlgo1 = 1 , then why doesn’t this need to be defined as to what the conditions for this algo is going to be to start its process?
This is the Ehler’s Universal Oscillator ML3 system now with Heuristics cycle code for ValueX and ValueY (Long/Short entry thresholds), but not for Value Z (bandedge) as I just need to confirm the Heuristic for 3 scenarios code (see my attempt above in this post) and it’s getting late..
Ehler's Univ Osc 3 x ML with Heuristics (ML3)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428//Ehler's Universal Oscillator Supersmoother Machine Learning (MLx3)// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivatedHeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIfIf 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) Thenoptimize = optimize + 1EndIfStartingValue = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement = 0.1//20MaxIncrement = 20 //4//Limit of no of increments either up or downReps = 3 //Number of trades to use for analysis //3MaxValue = 1 //270 //Maximum allowed valueMinValue = increment //Minimum allowed valueStartingValue2 = -1 //28 //24 //200//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement2 = 0.1//20MaxIncrement2 = 20 //4//Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysis //3MaxValue2 = 1 //270 //Maximum allowed valueMinValue2 = increment2 //Minimum allowed valueStartingValue3 = 25 //28 //24 //200 -- Bandedge 25//ResetPeriod = 8 //Specify no of months after which to reset optimizationIncrement3 = 5//20 // steps of 5 BandedgeMaxIncrement3 = 20 //4 Limit of no of increments either up or down //20 lots of 5Reps3 = 3 //Number of trades to use for analysis //3MaxValue3 = 125 //270 //Maximum allowed value -- Bandedge 125MinValue3 = increment3 //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//EndIfonce ValueX = StartingValue //LONG THRESHOLDonce 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 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 Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For 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 ThenMode1 = 0 //Strategy is performing well with current variable, do not optimiseElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode1 = 2 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode1 = 1 //For strategy performing worse Next cycle optimise with positive incrementsElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode1 = 1 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode1 = 2 //For strategy performing worse Next cycle optimise with negative incrementsElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode1 = 1 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode1 = 1 //For strategy performing better Next cycle again optimise with positive incrementsElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode1 = 2 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode1 = 2 //For strategy performing better Next cycle again optimise with negative incrementsEndIfIf 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 1 EndEndif// Heuristics Algorithm 2 Start ////////////////////////////////If HeuristicsAlgo2 = 1 ThenIf (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) Thenoptimize2 = optimize2 + 1EndIf//StartingValue2 = -1 //28 //24 //200//etc//etc//MinValue2 = increment2 //Minimum allowed value//once monthinit2 = month//once yearinit2 = year//If (year = yearinit2 and month = (monthinit2 + ResetPeriod2)) or (year = (yearinit2 + 1) and ((12 - monthinit2) + month = ResetPeriod2)) Then//ValueY = StartingValue2//WinCountB2 = 0//StratAvgB2 = 0//BestA2 = 0//BestB2 = 0//monthinit2 = month//yearinit2 = year//EndIfonce ValueY = StartingValue2 ///SHORT THRESHOLDonce PIncPos2 = 1 //Positive increment2 Positiononce NIncPos2 = 1 //Neative increment2 Positiononce Optimize2 = 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 Optimize2 = Reps2 ThenWinCountA2 = 0 //Initialize current Win CountStratAvgA2 = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i2 = 1 to Reps2 DoIf positionperf(i2) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*100000)*-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 = 0 //Strategy is performing well with current variable, do not optimiseElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1 //For strategy performing worse Next cycle optimise with positive incrementsElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 1 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2 //For strategy performing worse Next cycle optimise with negative incrementsElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 1 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1 //For strategy performing better Next cycle again optimise with positive incrementsElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2 //For strategy performing better Next cycle again optimise with negative incrementsEndIfIf NIncPos2 > MaxIncrement2 or PIncPos > MaxIncrement2 ThenIf BestA2 = BestB2 ThenValueY = BestA2ElseIf reps2 >= 10 ThenWeightedScore2 = 10ElseWeightedScore2 = round((reps2/100)*100)EndIfValueY = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos2 = 1PIncPos2 = 1ElsIf ValueY > MaxValue2 ThenValueY = MaxValue2ElsIf ValueY < MinValue2 ThenValueY = MinValue2EndIFOptimize2 = 0EndIf// Heuristics Algorithm 2 EndEndif// Heuristics Algorithm 3 Start /////////////////////////////////////////If HeuristicsAlgo3 = 1 ThenIf (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) Thenoptimize3 = optimize3 + 1EndIf//StartingValue3 = 25 //28 //24 //200 -- Bandedge 25//etc//etc//MinValue3 = increment3 //Minimum allowed value//once monthinit3 = month//once yearinit3 = year//If (year = yearinit3 and month = (monthinit3 + ResetPeriod3)) or (year = (yearinit3 + 1) and ((12 - monthinit3) + month = ResetPeriod3)) Then//ValueZ = StartingValue3//WinCountB3 = 0//StratAvgB3 = 0//BestA3 = 0//BestB3 = 0//monthinit3 = month//yearinit3 = year//EndIfonce ValueZ = StartingValue3 //BANDEDGEonce PIncPos3 = 1 //Positive increment2 Positiononce NIncPos3 = 1 //Neative increment2 Positiononce Optimize3 = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode2 = 1 //Switches between negative and positive increments//once WinCountB3 = 3 //Initialize Best Win Count//GRAPH WinCountB3 coloured (0,0,0) AS "WinCountB2"//once StratAvgB3 = 4353 //Initialize Best Avg St3ategy Profit//GRAPH StratAvgB3 coloured (0,0,0) AS "StratAvgB3"If Optimize3 = Reps3 ThenWinCountA3 = 0 //Initialize current Win CountStratAvgA3 = 0 //Initialize current Avg Strategy Profit//HeuristicsCycle = HeuristicsCycle + 1For i3 = 1 to Reps3 DoIf positionperf(i3) > 0 ThenWinCountA3 = WinCountA3 + 1 //Increment Current WinCountEndIfStratAvgA3 = StratAvgA3 + (((PositionPerf(i3)*countofposition[i3]*100000)*-1)*-1)NextStratAvgA3 = StratAvgA3/Reps3 //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"///////////// 3?//Graph StratAvgA3*-1 as "StratAvgA3"//once BestA3 = 300//GRAPH BestA3 coloured (0,0,0) AS "BestA3"If StratAvgA3 >= StratAvgB3 ThenStratAvgB3 = StratAvgA3 //Update Best Strategy ProfitBestA3 = ValueZEndIf//once BestB3 = 300//GRAPH BestB3 coloured (0,0,0) AS "BestB3"If WinCountA3 >= WinCountB3 ThenWinCountB3 = WinCountA3 //Update Best Win CountBestB3 = ValueZEndIfIf WinCountA3 > WinCountB3 and StratAvgA3 > StratAvgB3 ThenMode2 = 0 //Strategy is performing well with current variable, do not optimiseElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode2 = 2 ThenValueZ = ValueZ + (Increment3*PIncPos3)PIncPos3 = PIncPos3 + 1Mode2 = 1 //For strategy performing worse Next cycle optimise with positive incrementsElsIf WinCountA3 < WinCountB3 and StratAvgA3 < StratAvgB3 and Mode2 = 1 ThenValueZ = ValueZ - (Increment3*NIncPos3)NIncPos3 = NIncPos3 + 1Mode2 = 2 //For strategy performing worse Next cycle optimise with negative incrementsElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode2 = 1 ThenValueZ = ValueZ + (Increment3*PIncPos3)PIncPos3 = PIncPos3 + 1Mode2 = 1 //For strategy performing better Next cycle again optimise with positive incrementsElsIf WinCountA3 >= WinCountB3 or StratAvgA3 >= StratAvgB3 and Mode2 = 2 ThenValueZ = ValueZ - (Increment3*NIncPos3)NIncPos3 = NIncPos3 + 1Mode2 = 2 //For strategy performing better Next cycle again optimise with negative incrementsEndIfIf NIncPos3 > MaxIncrement3 or PIncPos > MaxIncrement3 ThenIf BestA3 = BestB3 ThenValueZ = BestA3ElseIf reps3 >= 10 ThenWeightedScore3 = 10ElseWeightedScore3 = round((reps3/100)*100)EndIfValueZ = round(((BestA3*(20-WeightedScore3)) + (BestB3*WeightedScore3))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos3 = 1PIncPos3 = 1ElsIf ValueZ > MaxValue3 ThenValueZ = MaxValue3ElsIf ValueZ < MinValue3 ThenValueZ = MinValue3EndIFOptimize3 = 0EndIf// Heuristics Algorithm 3 End// Conditions to enter long positionsindicator1, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]// indicator1,2,3,4 = Univ Osc, ignored = Mid 0 Linec1 = (indicator1 CROSSES OVER ValueX)IF c1 THENBUY 10 PERPOINT AT MARKETENDIF// Conditions to exit long positionsindicator2, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c2 = (indicator2 CROSSES UNDER 0.0)IF c2 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator3, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c3 = (indicator3 CROSSES UNDER ValueY)IF c3 THENSELLSHORT 10 PERPOINT AT MARKETENDIF// Conditions to exit short positionsindicator4, ignored = CALL "Ehler's Univ Osc SuperSmoother"[ValueZ]c4 = (indicator4 CROSSES OVER 0.0)IF c4 THENEXITSHORT AT MARKETENDIF// Stops and targetsSet stop trailing 100GRAPH ValueXGRAPH ValueYGRAPH ValueZPls see images for performance.
Thanks once again @Juanj, excellent job.
-
AuthorPosts
Find exclusive trading pro-tools on