random value

Viewing 11 posts - 1 through 11 (of 11 total)
  • #11751

    Hi,

    How can I generate random values in PRT code? I would like to test random exit conditions; e.g. exit after 1 to 5 bars. Is there a random function in PRT, or another way to do this?

    Thanks

     

    #11775

    There is no built-in function that I know of. I tried making a ‘random’ number generator quickly:

    This will return a pseudo-random integer between 0 and 9 for each bar. I checked the distribution of integers, and it will generate roughly the same amount of each integer. Since it is not truly random and a very simple algorithm, remember that it will return the same numbers every time unless you change CFD/timeframe/startdate. If you use it as an indicator, you will see the distribution is a bit affected by certain patterns. Using it for the purpose you describe is no problem though.

    #11776

    I have spent many hours thinking of ways to generate a pseudo random number in PRT.

    My ideas were to “fool” my Auto strategy onto a Monte Carlo walk forward. However, haven’t had much luck as the PRT platform is fairly basic programming.

    Ives tried using time , trigonometry (cosine, some) , RSI , but these  all have a oscillating commonality that creates a pattern sooner or later.

    Grizzly

     

     

    #11777

    Hi Wing,

    Thanks for the code. I get the following error when trying to add it as an indicator:

     

    #11780

    Here is the code I meant to post:

     

    return MyNumber as “PseudoRandom”

    2 users thanked author for this post.
    #11793

    Thanks Wing, smart and reliable idea. Well done. 👏

    1 user thanked author for this post.
    #84887
    Leo

    Base in your idea I made an indicator to show values from 1 to 0.

    Cheers

     

     

    #160569

    Is this still the best way to generate a random value in PRT? No built-in functions in v.11?

    A bit irritating when testing on weekends and it generates the same value each time…

    #160585

    There is still no random number generation available in PRT although I do believe it is on the list of things to be added. At the moment PRT are still ironing out bugs in v11 so I imagine it is rather low priority right now.

    1 user thanked author for this post.
    #160609

    Another one:

     

    1 user thanked author for this post.
    #160944

    After a little bit of testing I have concluded that unfortunately none of these code examples are truly random number generators because they are based on other indicators that will always return the same values. So for example run the random number generator on the DJI daily chart and every single time you run it you will get the same sequence of numbers because the data for the other indicators is the same every single time.

    So if you use them to add some sort of random element to strategy testing then you will just end up with a curve fit to the (not at all) random numbers generated.

    1 user thanked author for this post.
Viewing 11 posts - 1 through 11 (of 11 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login