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
-
-
03/06/2020 at 9:15 PM #121413123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303defparam cumulateorders = falsedefparam preloadbars = 10000//defparam flatbefore = 080000//defparam flatafter = 220000once period1=7once period2=14once ValueX =period1once Valuey =period2ONCE ResetPeriod = 25HeuristicsCycleLimit = 2// ONCE HeuristicsCycle=1If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 0HeuristicsAlgo1 = 1ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 0HeuristicsAlgo2 = 1EndIfHeuristicsCycle = 0EndIf//If HeuristicsAlgo1 = 1 Then//Heuristics Algorithm 1 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) Thenoptimize = optimize + 1EndIfStartingValue = period1//Specify no of months after which to reset optimizationIncrement = 1MaxIncrement = 7 //Limit of no of increments either up or downReps = 3 //Number of trades to use for analysisMinValue = 2 //Minimum allowed valueMaxValue = 14 //Maximum allowed valueIf monthinit = 1 or monthinit = 3 or monthinit = 5 or monthinit = 7 or monthinit = 8 or monthinit = 10 or monthinit = 12 ThenMonthDays = 31ElsIf monthinit = 4 or monthinit = 6 or monthinit = 9 or monthinit = 11 ThenMonthDays = 30ElsIf monthinit = 2 ThenIf (yearinit/4 = round(yearinit/4)) or (yearinit/400 = round(yearinit/400)) Then //haha not sure how exactly to do thisMonthDays = 29 //leap yearElseMonthDays = 28EndIfEndIfIf (month = monthinit and day = dayinit + ResetPeriod) or (month = monthinit + 1 and (day + (MonthDays - dayinit)) >= ResetPeriod) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0dayinit = daymonthinit = 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 incrementsonce WinCountB = 3 //Initialize Best Win CountGRAPH WinCountB coloured (0,0,0) AS "WinCountB"once StratAvgB = 4353 //Initialize Best Avg Strategy ProfitGRAPH 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 ProfitGraph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1"Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2"Graph StratAvgA*-1 as "StratAvgA"once BestA = 300GRAPH BestA coloured (0,0,0) AS "BestA"If StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = ValueXEndIfonce BestB = 300GRAPH 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 1 End//ElsIf HeuristicsAlgo2 = 1 Then////// 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) Then//optimize2 = optimize2 + 1//EndIf// StartingValue2 = period2//ResetPeriod2 = 3 //Specify no of months after which to reset optimization//Increment2 = 1//MaxIncrement2 = 7 //Limit of no of increments either up or down//Reps2 = 3 //Number of trades to use for analysis////MinValue2 = 15 //Minimum allowed value//MaxValue2 = 28 //Maximum allowed value////If monthinit2 = 1 or monthinit2 = 3 or monthinit2 = 5 or monthinit2 = 7 or monthinit2 = 8 or monthinit2 = 10 or monthinit2 = 12 Then//MonthDays2 = 31//ElsIf monthinit2 = 4 or monthinit2 = 6 or monthinit2 = 9 or monthinit2 = 11 Then//MonthDays2 = 30//ElsIf monthinit2 = 2 Then//If (yearinit2/4 = round(yearinit2/4)) or (yearinit2/400 = round(yearinit2/400)) Then //haha not sure how exactly to do this//MonthDays2 = 29 //leap year//Else//MonthDays2 = 28//EndIf//EndIf////If (month = monthinit2 and day = dayinit2 + ResetPeriod2) or (month = monthinit2 + 1 and (day + (MonthDays2 - dayinit2)) >= ResetPeriod2) Then//ValueY = StartingValue2//WinCountB2 = 0//StratAvgB2 = 0//BestA2 = 0//BestB2 = 0//dayinit2 = day//monthinit2 = month//yearinit2 = year//EndIf////once ValueY = StartingValue2//once PIncPos2 = 1 //Positive Increment Position//once NIncPos2 = 1 //Neative Increment Position//once 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 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(i) > 0 Then//WinCountA2 = WinCountA2 + 1 //Increment Current WinCount//EndIf//StratAvgA2 = StratAvgA2 + (((PositionPerf(i)*countofposition[i]*100000)*-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//Mode = 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//Mode = 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 = BestA//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////Optimize2 = 0//EndIf////// Heuristics Algorithm 2 End////EndIfc1=average[valuex](close)c2=average[valuey](close)//condbuy =c1 crosses over c2 and rsi[14](close)<70condsell=c1 crosses under c2 and rsi[14](close)>30//if condbuy thenbuy at marketendifif condsell thensellshort at marketendif//pp=positionperf(0)*100//if pp<-0.125 then//sell at market//exitshort at market//endifset stop %loss 0.5 // exit sooner on performance criteria aboveset target %profit 0.25//GRAPH OPTIMIZEgraph ValueX coloured(121,141,35,255) as "fastperiod1"graph ValueY coloured(255,0,0,255) as "slowperiod"GRAPH dayinit + ResetPeriodGRAPH ResetPeriodGRAPH monthinitgraph dayinit
Good evening,
Unable to initialize variables
Monthinit
Dayinit
removing some of the code works.1 user thanked author for this post.
03/06/2020 at 10:12 PM #12141603/06/2020 at 10:17 PM #12141703/06/2020 at 10:30 PM #12142003/06/2020 at 10:43 PM #12142203/07/2020 at 11:48 AM #121432only a single increment is made either up or down
Is the 1 x increment of the value set as increment?
So if I set increment = 2 then in any one bar, ValueX or Value Y should not change by more than ‘2’ (up or down)?
03/07/2020 at 1:06 PM #121435only a single increment is made either up or down
Is the 1 x increment of the value set as increment?
So if I set increment = 2 then in any one bar, ValueX or Value Y should not change by more than ‘2’ (up or down)?
Correct, unless the increment limit value has been reached, after which ValueX will revert to the new Average best performing value
03/07/2020 at 1:59 PM #121436for test :
Depending on the month it changes from HeuristicsAlgo1 to HeuristicsAlgo2
I moved valuey to line 40123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312defparam cumulateorders = falsedefparam preloadbars = 10000//defparam flatbefore = 080000//defparam flatafter = 220000period1=7period2=14if not onmarket thendayinit = daymonthinit = monthyearinit = yearendifHeuristicsCycleLimit = 2IF monthinit mod 2 = 1 thenHeuristicsAlgo1 = 1elsif monthinit mod 2 =0 thenHeuristicsAlgo2 = 1endifIf 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 = period1valuey= PERIOD2ResetPeriod = 3//Specify no of months after which to reset optimizationIncrement = 1MaxIncrement = 3//Limit of no of increments either up or downReps = 3 //Number of trades to use for analysisMinValue = 2 //Minimum allowed valueMaxValue = 14 //Maximum allowed valueIf monthinit = 1 or monthinit = 3 or monthinit = 5 or monthinit = 7 or monthinit = 8 or monthinit = 10 or monthinit = 12 ThenMonthDays = 31ElsIf monthinit = 4 or monthinit = 6 or monthinit = 9 or monthinit = 11 ThenMonthDays = 30ElsIf monthinit = 2 ThenIf (yearinit/4 = round(yearinit/4)) or (yearinit/400 = round(yearinit/400)) Then //haha not sure how exactly to do thisMonthDays = 29 //leap yearElseMonthDays = 28EndIfEndIfIf (month = monthinit and day = dayinit + ResetPeriod) or (month = monthinit + 1 and (day + (MonthDays - dayinit)) >= ResetPeriod) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0dayinit = daymonthinit = monthyearinit = yearEndIfonce ValueX = StartingValueonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce Optimize = 1 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive incrementsonce WinCountB = 3 //Initialize Best Win Count//GRAPH WinCountB coloured (0,0,0) AS "WinCountB"//once StratAvgB = 0 //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 ProfitGraph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1"Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2"Graph StratAvgA*-1 as "StratAvgA"once BestA = 0GRAPH BestA coloured (0,0,0) AS "BestA"If StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = ValueXEndIfonce BestB = 0GRAPH 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 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) Thenoptimize2 = optimize2 + 1EndIfStartingValue2 = period2valuex=period1ResetPeriod2 = 3//Specify no of months after which to reset optimizationIncrement2 = 1MaxIncrement2 = 5//Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysisMinValue2 = 15 //Minimum allowed valueMaxValue2 = 30 //Maximum allowed valueIf monthinit2 = 1 or monthinit2 = 3 or monthinit2 = 5 or monthinit2 = 7 or monthinit2 = 8 or monthinit2 = 10 or monthinit2 = 12 ThenMonthDays2 = 31ElsIf monthinit2 = 4 or monthinit2 = 6 or monthinit2 = 9 or monthinit2 = 11 ThenMonthDays2 = 30ElsIf monthinit2 = 2 ThenIf (yearinit2/4 = round(yearinit2/4)) or (yearinit2/400 = round(yearinit2/400)) Then //haha not sure how exactly to do thisMonthDays2 = 29 //leap yearElseMonthDays2 = 28EndIfEndIfIf (month = monthinit2 and day = dayinit2 + ResetPeriod2) or (month = monthinit2 + 1 and (day + (MonthDays2 - dayinit2)) >= ResetPeriod2) ThenValueY = StartingValue2WinCountB2 = 0StratAvgB2 = 0BestA2 = 0BestB2 = 0dayinit2 = daymonthinit2 = monthyearinit2 = yearEndIfonce ValueY = StartingValue2once PIncPos2 = 1 //Positive Increment Positiononce NIncPos2 = 1 //Neative Increment Positiononce Optimize2 = 1 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode2 = 1 //Switches between negative and positive incrementsonce WinCountB2 = 3 //Initialize Best Win CountGRAPH WinCountB2 coloured (0,0,0) AS "WinCountB2"once StratAvgB2 = 0 //Initialize Best Avg Strategy ProfitGRAPH 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(i) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i)*countofposition[i]*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 = 0GRAPH BestA2 coloured (0,0,0) AS "BestA2"If StratAvgA2 >= StratAvgB2 ThenStratAvgB2 = StratAvgA2 //Update Best Strategy ProfitBestA2 = ValueYEndIfonce BestB2 = 0GRAPH BestB2 coloured (0,0,0) AS "BestB2"If WinCountA2 >= WinCountB2 ThenWinCountB2 = WinCountA2 //Update Best Win CountBestB2 = ValueYEndIfIf WinCountA2 > WinCountB2 and StratAvgA2 > StratAvgB2 ThenMode = 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 + 1Mode = 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 PIncPos2 > MaxIncrement2 ThenIf BestA2 = BestB2 ThenValueY = BestAElseIf 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 EndEndIfpp=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)>40//if condbuy thenbuy at marketendifif condsell thensellshort at marketendif////if pp<-0.125 then//sell at market//exitshort at market//endifset stop %loss 0.5 // exit sooner on performance criteria aboveset target %profit 3graph ppgraph valuex coloured(121,141,35,255) as "fastperiod1"graph valuey coloured(255,0,0,255) as "slowperiod"1 user thanked author for this post.
03/07/2020 at 4:48 PM #121443I just had a little play with the first code that Juanj posted and I noticed that I could sometimes get the ‘Periods’ variable to go negative. You might want to add a minimum value allowed to prevent this as it could cause a strategy to be stopped.
03/08/2020 at 12:56 PM #12148003/09/2020 at 11:32 AM #121546Attached results using Paul’s System.
- Top Curve WITHOUT Heuristics (code is bare System / Paul’s original code only).
- Bottom Curve WITH Heuristics.
Bottom Curve … Heuristic Algo1 and Algo2 are both working at the same time.
I found that it is not a case of adding Heuristics on top of a best effort bare code.
I am going to start my version on Forward Test now to establish that my version is not just a massive curve fit of the Heuristics!? 🙂
I am posting my results as encouragement / to show that JuanJ code does work.
Maybe you can get JuanJ code to work with even better results on Paul’s System than attached?
03/10/2020 at 3:07 PM #121716Hi Juan,
I try to understand the concepts of what you are trying to obtain with this machine learning, could you explain this ?
Normally you develop a strategy with fixed settings (eg like a Macd crossing strategy) based upon past data, and assuming the future movements of price are relatively similar, and you let run your trading-algo.
With this machine learning concept, are you trying to further optimize the following of past changes in price movements, then with those optimized findings approaching the future price movements with the new strategy ?
Or when running a algo-strategy, with this machine learning concept, it adjust the setting of the variables automatically given the structure of price movements ?
(I hope my question is clear, in this case it would be great to discuss this kind of topics face to face in a meeting with others, to avoid misunderstandings)
03/11/2020 at 2:06 PM #121819Hi Grahal or others,
Could you be so kind to spend a few words to explain the concepts of the “Heuristics” ? Is it daily optimising of a fixed setting, and yes, what is the base of the adjustment, how many bars backwards ?
I am sorry, but I missed that out of lots of interesting code.
Thanks in advance for your help !
Your comment “Attached results using Paul’s System.
- Top Curve WITHOUT Heuristics (code is bare System / Paul’s original code only).
- Bottom Curve WITH Heuristics. “
03/12/2020 at 10:09 AM #121909when running a algo-strategy, with this machine learning concept, it adjust the setting of the variables automatically given the structure of price movements ?
It is above. (I am commenting as JuanJ is probably busy trading or mentoring etc)
I have found though that the starting value for ValueX is important to get good results.
Also a few other variables in the Heuristics are important re initialisation value. This is understandable else the Heuristics would be the panacea for all!? 🙂
03/12/2020 at 10:26 AM #121910how many bars backwards ?
This is a setting in the Heuristics Algo (Halgo), but it is set by number of Trades backwards.
So to use an example … the results of the last 3 Trades Trades 1, 2 and 3 are used to vary the Halgo variables in order to produce an optimum ValueX to go forward with for the next Trade (4).
Then it is my understanding that … Trade4 would be used together with Trade3 and Trade 2 to repeat above.
I will try and decide … from the code … if it is above or is it … the Halgo variables are next optimised after Trade 6 using Trade 4, 5 and 6??
@Jan you are far better at coding than I so maybe you can read JuanJ code and decide??Whoever finds out first, post on here, unless JuanJ passes by and tells us first?
-
AuthorPosts
Find exclusive trading pro-tools on