ProRealCode - Trading & Coding with ProRealTime™
but when there’s a drop it ends op with 23 which is not with factor 5 and after that everything is off.
Grahal: 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)? https://www.prorealcode.com/topic/machine-learning-in-proorder/page/5/#post-12143
Junaj: Correct, unless the increment limit value has been reached, after which ValueX will revert to the new Average best performing value.
Is there an advantage to having minvalue set to = 15 and not set to = increment. So it starts at 20, goes to 50 but also it can go from 15 also? From 15 also?Did you get this “can’t go live” warning with your v4 ts? (pls see image 2). How can I launch it on the Demo? It doesn’t like ValueX/Y?past this in a new blanco strategy, it should run. I removed the ts, that’s a worry less 🙂 Daily tf
//-------------------------------------------------------------------------
// Hoofd code : Renko D ML2 CycLimRes v4
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//main code : nneless renko dji 1month v3 machine learning (ml2)
//https://www.prorealcode.com/topic/machine-learning-in-proorder/page/3/#post-121130
//-------------------------------------------------------------------------
//https://www.prorealcode.com/topic/why-is-backtesting-so-unreliable/#post-110889
//definition of code parameters
defparam cumulateorders = false // cumulating positions deactivated
defparam preloadbars = 1000
once mode = 0 // [0] with minimum distance stop; [1] without
once minstopdistance = 20
positionsize = 1
startingvalue = 40 //5, 100, 10 boxsize
increment = 10 //5, 20, 10
maxincrement = 20 //5, 10 limit of no of increments either up or down
reps = 2 //1 number of trades to use for analysis //2
maxvalue = 50 //20, 300, 150 //maximum allowed value
minvalue = 15 //5, minimum allowed value
startingvalue2 = 40 //5, 100, 50 stop loss
increment2 = 10 //5, 10
maxincrement2 = 20 //1, 30 limit of no of increments either up/down //4
reps2 = 2 //1, 2 nos of trades to use for analysis //3
maxvalue2 = 50 //20, 300, 200 maximum allowed value
minvalue2 = 15 //5, minimum allowed value
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
else
once valuex = startingvalue
once valuey = startingvalue2
endif
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) then
optimise = optimise + 1
endif
once valuex = startingvalue
once pincpos = 1 //positive increment position
once nincpos = 1 //negative increment position
once optimise = 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 optimise = reps then
wincounta = 0 //initialize current win count
stratavga = 0 //initialize current avg strategy profit
heuristicscycle = heuristicscycle + 1
for i = 1 to reps do
if positionperf(i) > 0 then
wincounta = wincounta + 1 //increment current wincount
endif
stratavga = stratavga + (((positionperf(i)*countofposition[i]*close)*-1)*-1)
next
stratavga = 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 then
stratavgb = stratavga //update best strategy profit
besta = valuex
endif
//once bestb = 300
//graph bestb coloured (0,0,0) as "bestb"
if wincounta >= wincountb then
wincountb = wincounta //update best win count
bestb = valuex
endif
if wincounta > wincountb and stratavga > stratavgb then
mode1 = 0
elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 1 then
valuex = valuex - (increment*nincpos)
nincpos = nincpos + 1
mode1 = 2
elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 1 then
valuex = valuex + (increment*pincpos)
pincpos = pincpos + 1
mode1 = 1
elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 2 then
valuex = valuex + (increment*pincpos)
pincpos = pincpos + 1
mode1 = 1
elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 2 then
valuex = valuex - (increment*nincpos)
nincpos = nincpos + 1
mode1 = 2
endif
if nincpos > maxincrement or pincpos > maxincrement then
if besta = bestb then
valuex = besta
else
if reps >= 10 then
weightedscore = 10
else
weightedscore = round((reps/100)*100)
endif
valuex = round(((besta*(20-weightedscore)) + (bestb*weightedscore))/20) //lower reps = less weight assigned to win%
endif
nincpos = 1
pincpos = 1
elsif valuex > maxvalue then
valuex = maxvalue
elsif valuex < minvalue then
valuex = minvalue
endif
optimise = 0
endif
// 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
optimise2 = optimise2 + 1
endif
once valuey = startingvalue2
once pincpos2 = 1 //positive increment position
once nincpos2 = 1 //negative increment position
once optimise2 = 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 optimise2 = 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(i2) > 0 then
wincounta2 = wincounta2 + 1 //increment current wincount
endif
stratavga2 = stratavga2 + (((positionperf(i2)*countofposition[i2]*close)*-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
mode2 = 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
mode2 = 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 = besta2
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
optimise2 = 0
endif
// heuristics algorithm 2 end
endif
//
boxsizel = valuex
boxsizes = valuey
//
renkomaxl = round(close / boxsizel) * boxsizel
renkominl = renkomaxl - boxsizel
renkomaxs = round(close / boxsizes) * boxsizes
renkomins = renkomaxs - boxsizes
//
if high > renkomaxl + boxsizel then
renkomaxl = renkomaxl + boxsizel
renkominl = renkominl + boxsizel
endif
if low < renkomins - boxsizes then
renkomaxs = renkomaxs - boxsizes
renkomins = renkomins - boxsizes
endif
//
if mode then
buy positionsize contract at renkomaxl + boxsizel stop
sellshort positionsize contract at renkomins - boxsizes stop
else
if high > renkomaxl + boxsizel then
buy positionsize contract at renkomaxl + boxsizel + minstopdistance stop
endif
if low < renkomins - boxsizes then
sellshort positionsize contract at renkomins - boxsizes - minstopdistance stop
endif
endif
set stop ploss 50
set target pprofit 500
//
//graphonprice renkomaxl + boxsizel coloured(0,200,0) as "renkomax"
//graphonprice renkomins - boxsizes coloured(200,0,0) as "renkomin"
//graph valuex coloured(0,255,0)
//graph valuey coloured(255,0,0)
Junaj: Correct, unless the increment limit value has been reached, after which ValueX will revert to the new Average best performing value.Thanks didn’t now that. I want to stick to factor 5, so I will review the code if it can be changed.
ValueX = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20)
That’s the cause. Now how you you get to to stick to the incremental value ratio, in this case 5? But at the same-time make it flexible so if increment is 2, is sticks also to that factor?
Thanks for great code @Juanj, the Heuristic code @GraHal and help @Paul, @Nonetheless. It’s not been VRT’d yet, works on a few instruments like the Nikkei, the settings will need adjusting for others. Also can we trust the ValueZ / ML3 on a setting like the pLoss after the trailing stop tbt debacle? And would anyone like to try and get ValueZ / ML3 to work on N? (£/tick) instead of pLoss? I’ve tried! All I got “no trades” taken… I’m wondering if trade size can’t be governed by a ValueZ Machine Learning algo @Vonasi? The itf and screenshot is attached below.Juanj:
Also note that to set starting values to the algorithm all the commented out code which have a ‘once’ as well as a ‘Graph’ command on the line directly below it has to be activated. i.e. once BestA = 300 etc. I used it to graph and then set the final values generated by the algorithm as the starting values when using the strategy on a live system.
https://www.prorealcode.com/topic/machine-learning-in-proorder/page/24/#post-128685
Further than above I don’t what I can do??I don’t even know what the problem is? Brad was a mistake and misspelling of Bard and I thought that was sorted by Nicolas years ago. 🤷♂️ Turns out, looking into this it wasn’t and a Bard beat me to my nickname (of the last 2o yrs) by a month… so now what because I’m not answering to “Brad” and Bard is already taken?
My God, I’ve been an imposter for years? 😀Same here, ah well … an imposter I’ve been and an imposter I’ll stay!!! 🙂 Least the GraHal wrote link works now finally you’ve got the hang of it @Brad!!!! 🙂 Thank You @Noobywan for solving this 4 year old riddle! Have a virtual beer on me @Noobywan @Vonasi and @Brad! 🙂 Goodnight Each PS There’s an oddity … I put Caps for the V in Vonasi and B in Brad but they came up lower case!? Aha … I see why now … you have lower case on your Profile on the top line!
Machine Learning in ProOrder ProRealTime
This topic contains 454 replies,
has 32 voices, and was last updated by Khaled
4 years, 1 month ago.
| Forum: | ProOrder: Automated Strategies & Backtesting |
| Language: | English |
| Started: | 08/06/2017 |
| Status: | Active |
| Attachments: | 207 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.