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 10:40 AM #121321
@Paul … comment out Line 144. Also then … 1 less endif should be needed?
My ‘sweating over it’ time may be a benefit to others as I tried just about every conceivable thing possible to get mine to work. Then – when I got it working – I went back over some things I tried to see what difference they should have made! 🙂
Let us know if it works?
03/06/2020 at 10:57 AM #12132403/06/2020 at 11:07 AM #12132903/06/2020 at 11:25 AM #121331Success … see attached!
I looked at my working System and the only way I got mine to fully spark into life (with ValueX and ValueY changing) … was to NOT include the code below … so there must be something wrong with below or the concept of below does not work??
I guess JuanJ will have to help us with below?
12345678910111213141516HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIfIf HeuristicsAlgo1 = 1 Then03/06/2020 at 11:35 AM #121333Aha … I just looked at my other fully working working System including the above code … but we do NOT need either lines of code below …
So that’s saved JuanJ a bit more time! 🙂
123If HeuristicsAlgo1 = 1 ThenIf HeuristicsAlgo2 = 1 ThenEDIT / PS
Comparing results of both my 2 fully functional Systems and Paul’s System with and without the HeuristicsCycle Code above … the results are the same both with and without!
Maybe there could be instances where the HeuristicsCycle Code makes a difference?
Thoughts:
JuanJ noted cross-errors when he tried 2 x Algos together (some time ago) so he kindly provided the HeuristicsCycle Code as a solution.These cross-errors may have been due to the cross-use (between the 2 x Algos) of certain settings due to the missing ‘2’ from certain settings (of Algo2) which I highlighted and corrected in an earlier post.
03/06/2020 at 11:40 AM #12133403/06/2020 at 1:42 PM #121350we do NOT need either lines of code below …
Away from the screen my brain cleared! 🙂
Without the lines of code below, we have nothing that is controlling / defining Algo1 and Algo2 and so the HeuristicsCycle code is not doing anything? (This is why both sets of results are the same!).
So I am now back to my earlier assertion that HeuristicsCycle code is not working for some reason?
123If HeuristicsAlgo1 = 1 ThenIf HeuristicsAlgo2 = 1 Then03/06/2020 at 2:00 PM #121356Francesco did it before ….. he had two different results, but without code we don’t know how he did it.
03/06/2020 at 2:33 PM #121363he had two different results, but without code we don’t know how he did it.
Francesco results were before (without JuanJ code) and after (with JunanJ code).
I have my Systems (and Paul’s) working – with the JuanJ Algo1 and Algo2 – but seemingly not using the code below.
12345678910111213141516HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIfIf HeuristicsAlgo1 = 1 Then03/06/2020 at 2:42 PM #121364If you remove this part of code, I seem to have understood that the results will not change you …. so there is something else different ….
03/06/2020 at 2:55 PM #121367Either …
- The Cycle code above is not working and therefore achieving no change in the results?
This scenario means that Algo1 and Algo2 are both working at the same time (on the same bar).
OR
2. The Cycle code above is working as designed to do, but the results are the same as without the Cycle code above.
This scenario means that Algo1 and Algo2 are working separately every 2 Cycles (on different bars).
Item 2. is why I think that the Cycle code is not working as the results would not be identical??
03/06/2020 at 3:04 PM #12136903/06/2020 at 6:00 PM #12139303/06/2020 at 7:47 PM #121406If someone got it to a working version, then please post the whole code.
Below is your code working and the results attached … you can see Valuex and ValueY as variables changing … under the equity curve.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301defparam cumulateorders = falsedefparam preloadbars = 10000defparam flatbefore = 080000defparam flatafter = 220000//period1=7//period2=14HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIf////If 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 = 6ResetPeriod = 3 //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 = 1 //Minimum allowed valueMaxValue = 12 //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 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 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 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 = 16ResetPeriod2 = 3 //Specify no of months after which to reset optimizationIncrement2 = 1MaxIncrement2 = 7 //Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysisMinValue2 = 14 //Minimum allowed valueMaxValue2 = 28 //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 = 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(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 = 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 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 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 marketendifpp=positionperf(0)*100if pp<-0.125 thensell at marketexitshort at marketendifset stop %loss 0.5 // exit sooner on performance criteria aboveset target %profit 0.25graph valuex coloured(121,141,35,255) as "fastperiod1"graph valuey coloured(255,0,0,255) as "slowperiod"//endif//endifGRAPH HeuristicsAlgo1 coloured(121,141,35,255)//GRAPH HeuristicsAlgo2 coloured(255,0,0,255)1 user thanked author for this post.
03/06/2020 at 7:59 PM #121408And here is Paul’s code with the HeuristicsCycle all Rem’d out … results on the top equity curve.
Notice the top equity curve (rem’d out HeuristicsCycle code) results are the same bottom equity curve (included HeuristicsCycle code ). Note: included = opposite of rem’d out.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302defparam cumulateorders = falsedefparam preloadbars = 10000defparam flatbefore = 080000defparam flatafter = 220000//period1=7//period2=14//HeuristicsCycleLimit = 2//once HeuristicsCycle = 0//once HeuristicsAlgo1 = 1//once HeuristicsAlgo2 = 0//If HeuristicsCycle >= HeuristicsCycleLimit Then//If HeuristicsAlgo1 = 1 Then//HeuristicsAlgo2 = 1//HeuristicsAlgo1 = 0//ElsIf HeuristicsAlgo2 = 1 Then//HeuristicsAlgo1 = 1//HeuristicsAlgo2 = 0//EndIf//HeuristicsCycle = 0//EndIf//////If HeuristicsAlgo1 = 1 Then//Heuristics Algorithm 1 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 = 6ResetPeriod = 3 //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 = 1 //Minimum allowed valueMaxValue = 12 //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 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 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 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 = 16ResetPeriod2 = 3 //Specify no of months after which to reset optimizationIncrement2 = 1MaxIncrement2 = 7 //Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysisMinValue2 = 14 //Minimum allowed valueMaxValue2 = 28 //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 = 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(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 = 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 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 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 marketendifpp=positionperf(0)*100if pp<-0.125 thensell at marketexitshort at marketendifset stop %loss 0.5 // exit sooner on performance criteria aboveset target %profit 0.25graph valuex coloured(121,141,35,255) as "fastperiod1"graph valuey coloured(255,0,0,255) as "slowperiod"//endif//endif//GRAPH HeuristicsAlgo1 coloured(121,141,35,255)//GRAPH HeuristicsAlgo2 coloured(255,0,0,255)//endif1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on