Maximum number of iterations in a loop?
Forums › ProRealTime English forum › ProBuilder support › Maximum number of iterations in a loop?
- This topic has 17 replies, 5 voices, and was last updated 5 years ago by Leo.
-
-
02/07/2019 at 3:56 PM #90751
I’m trying to code an indicator that simulates a strategy and calculates which values for three variables have been the most profitable recently. I then hope to CALL these values from a strategy and so create a sort of self optimizing strtaegy. To try to achieve this I have in the indicator a loop with two other loops within it to get all the possible combinations of the three variable values. When I try to run the indicator I get the following message:
If I reduce the quantity in each loop then I am able to get the indicator to run but then the total number of possible combinations is massively reduced. I want to test something like 320000 combinations but it will only let me test 480.
If I know what the maximum quantity of loops is then maybe I can do repeats of the code and test different blocks of combinations each time and compare the output to the previous block tested. All a bit messy but possibly do-able.
Does anyone know what the maximum quantity of loops is and why it is so low?
The code is something like this:
12345678910111213141516171819202122232425262728293031323334bestsim = 0psim = 0xsim = 0ysim = 0for xsimstart = 1 to 20xsim = xsimstart * 10for ysimstart = 1 to 20ysim = ysimstart * 10for psim = 1 to 200(my conditions using the 3 values)if (my long conditions) thentotalsim = totalsim + (close[psim] - open[psim])endifif (my short conditions) thentotalsim = totalsim + (open[psim] - close[psim])endifif totalsim > bestsim thenbestsim = totalsimp = psimx = xsimy = ysimendifnextnextnextreturn x coloured(128,0,0) as "x", y coloured(0,128,0) as "y", p coloured(0,0,128) as "p"02/07/2019 at 3:58 PM #90754200x200x200 = 8 million!!!
Try 20x20x20, but it’s likely to be still too much!
02/07/2019 at 4:05 PM #9075502/07/2019 at 4:12 PM #90757There is no real limitations, I have never been able to know how many iterations a loop could handle, I think that is it only a memory limitation of the ProBuilder engine. Since we don’t have data arrays, no dynamic variables are possible and we only have loops to recreate them on the fly..
Nested loops are the worse!
A good practice is to break the loop once you have found what you want, when it’s possible.
02/07/2019 at 4:25 PM #90758I tested the max by setting the first two loops with values from 1 to 1 and then slowly changed the third loops value until the indicator ran. Strangely at 695 it started to run but then crashed out with the error after a while. So I then decided to remove most of the indicator code and see what happened and I was able to get it to run with larger quantities of loops – up to 6650 loops. Clearly the number of loops is not a fixed number as my original indicator would not run with more than 480 loops but a simpler indicator would run with 6650.
This is the test code I used:
12345678910111213141516171819defparam calculateonlastbars = 201psim = 0xsim = 0ysim = 0for xsimstart = 1 to 1for ysimstart = 1 to 1for psim = 1 to 6650p = psimx = xsimy = ysimnextnextnextreturn x coloured(128,0,0) as "x", y coloured(0,128,0) as "y", p coloured(0,0,128) as "p"02/07/2019 at 4:30 PM #90760I think we were typing at the same time Nicolas. My test seems to agree with what you have described.
Unfortunately every combination needs to be examined and tested in my indicator to find the best performing combination and so using BREAK is not an option.
It seems that loops are not going to necessarily work even if I break the combinations down in to smaller chunks. At just 480 iterations per loop I would need 667 chunks to cover 320000 combinations!
02/07/2019 at 4:38 PM #9076102/07/2019 at 4:54 PM #9076402/07/2019 at 5:03 PM #90766I have even started coding a strategy that stores 1600 simulated strategy results in my desperation to build a self optimizing strategy – but after completing just 80 strategy simulation coding blocks it felt like I was writing ‘War and Peace’ so I stopped. I think I need to revisit it to improve the way I use ‘find and replace’ to deal with the code so that I can create bigger blocks at a time.
02/08/2019 at 9:28 PM #90907improve the way I use ‘find and replace’ to deal with the code so that I can create bigger blocks at a time.
I’m sure you’ve thought of it, but how about a 3rd party application / sw and then copy and paste back into PRT?
02/08/2019 at 10:04 PM #90909Thanks for that suggestion GraHal. I was thinking something similar myself earlier today when I did a find and replace that just went on for hours – right up to the point where I did a task manager stop of the platform and lost hours of work but at least I was able to get back and start doing it all again!
Strangely since I’ve been messing with these massive strategies I’ve had PRT crash shut down quite a few times on me too. It is all making the end goal feel a very long way away but I will persevere!
02/09/2019 at 12:17 PM #90924Strangely since I’ve been messing with these massive strategies I’ve had PRT crash shut down quite a few times on me too.
PRT hogging / not releasing RAM issues again I reckon?
Since I got down to zero Systems stored in the backtest screen and also zero Systems stored in the non-running auto-trading screen and also shutting down PRT after a heavy session I haven’t had a crash.
I’ll probably get one now!!! 🙂
02/09/2019 at 3:25 PM #90935PRT hogging / not releasing RAM issues again I reckon?
Very likely as this idea is giving the RAM a real bashing. At the moment I am running a back test on 10000 bars that basically runs 320000 simulated strategies at each bar close and then one real strategy!
02/11/2019 at 1:11 PM #91047Hi Vonasi…
I don’t want to disapoint you but this Problem of max Memory for the Loop of ProRealCode, seem to be something serious…
In my neural Network the “descent Gradient” algorith take 10 values of data (Batch) makes som Magic (calculate Derivate, save some values average others, etc) and recalculate the 43 values of the neural Network-… and when I say recalculate is modify a Little bit the values for improve the neural Network ( the learning process)…
The more time you repeated this process (epchos)… the more acurate the Network is…
Do you know how many times I am able to repeat the “descent Gradient” adgorithm…
5 times!!! only 5 times!!!! with a Loop of for i=1 to 6… i get the Infinitive Loop issue….
What I have done… is to make 5 per bar… the next bar makes another 5 Loops and so on….
… i am feeling very frustrated with ProRealCode lately.
02/11/2019 at 1:18 PM #91050have even started coding a strategy that stores 1600 simulated strategy results in my desperation to build a self optimizing strategy
I felt desperate too, so I change to Machine Learning…
Maybe you can open a new Forum Topic… and I can help you… but you Need to be more willing to share your codes…
for example I will Need:
–> Classifier: a code to look in the past and detects a succesful trade your are willing to achive
—> variables: 5 variables ( I am working currently in a Network with 5 Inputs) that the Network evaluate to make the trade.
Then the Network predict the best Setting of thos 5 variables to make a prediction.
… Maybe is not what you are searching for… but we can having a try.
-
AuthorPosts
Find exclusive trading pro-tools on