Best Way to Generate Random Entry/Exits

Forums ProRealTime English forum ProOrder support Best Way to Generate Random Entry/Exits

  • This topic has 8 replies, 3 voices, and was last updated 5 years ago by avatarBard.
Viewing 9 posts - 1 through 9 (of 9 total)
  • #83460

    I was interested in generating a random entry code to test an optimised version of the Kase Dev Stop (KDS) exits and see if my entries on a system I have (that uses the KDS for exits) are better than random or as Trading World Cup champion Kevin Davey succinctly put it: better than a monkey throwing darts at a dart board!
    (See page 109 of Building Winning Algorithmic Trading Systems by Kevin J Davey).

    I used a random date generator:  https://www.random.org/calendar-dates
    I wanted to match the 19 trades my system took (7 long and 12 shorts) and randomly assigned some of these dates to go long so I have 7 long positions and the rest going short.

    I need to code the entries correctly so it takes the trades on the dates provided by the random date generator. I used this code below but it’s not taking the 19 trades I need.

    I also tried changing the AND to OR (between the StartDate code) without it working and also using conditionals like: “If date = StartDate3 AND StartDate6 then TradeLONG =1 and then using If TradeLONG =1 then Buy 10 etc but that didn’t work either? 

    Obviously you could write separate Buy and Sell lines with the specific StartDate code but that’s clumsy and time consuming, so any help appreciated.

    I used the £/$ Daily between 22/10/2012 and 24/10/2018. It produced 51 trades, but on what criteria are all these 51 entries being made because it certainly isn’t the StartDates!?

    Also is there a better way of generating random entry/exits because I didn’t understand this RSI based generator: https://www.prorealcode.com/topic/random-value/

    Cheers
    Bard

     

    #83699

    Your trading conditions are wrongly syntaxed, you should test them like this:

    and make another variable but for TradingShort and the others StartDateX, like you did.

    1 user thanked author for this post.
    #83880

    Cheers @nicolas, I’ve amended the code yet it takes positions on dates that don’t respect the opendate = StartDates as seen in these two screenshots below. The purpose of the code is to enter on random dates and ascertain the effectiveness of different exit strategies, in this case the Kase Dev Stops and the amount of standard deviations needed.

    (The reason the Startdates are out of order in the TradeLONG / SHORT code is because I determined whether to go long or short by using a random number generator for the 25 trade dates: http://numbergenerator.org/randomnumberpicker#!numbers=25&low=1&high=25&unique=true&start=true)

    Can you think of a better way to code random entries (or exits) particularly if you needed eg a 120 trades to match the amount of trades taken by a system so as to check the effectiveness of it’s exit strategy? Thanks.

    #84861

    Why has this code traded on the 17th Jan 2018 @Nicolas? (Pls see first image above). My random dates don’t include this date? They don’t even include January! Is there a better way to generate random trades?

    Cheers
    Bard

    #85431

    This code isn’t working, it’s not only trading on non specified days it’s trading on the wrong month?

    #85432
    Leo

    Hi.
    You are creating a code for evaluate the performance in entries at random dates.

    Then what?  You create a system that entry in the market one of those days in the future?

    For me it doesn’t have sense at all.

    Just pick whatever strategy and then make an extra condition with a random value from 1 to 5 an add trade if dayofweek = randomvalue.

    In any case you can not perform any Evaluation of your code in the past.

    We have a thead somewhere that we were trying to make a code for trade totally random. There were many interesting conclusions

    #85505

    Hi @Leo, I want to compare my system that has an entry that uses an oscillator entry (the Kase Peak Osc. — used in conjunction with the Kase Dev Stop (KDS exit) with a random entry. Note: Entries can be tested in the similar way.

    Is my entry using the Kase Peak Osc (KPO) in my system really better than random? (I’m doing this a the KPO is meant to be used with a Kase Convergence Divergence indicator which  I posted on these forums and which gives 75+% accuracy according to Cynthia Kase, in entry timing, but which has not be coded yet). So now I want to see how well my KPO entry performs when I use and compare it to a random entry instead of a oscillator type entry (and use the same exit, the KDS) and so I need to generate approximately the same number of entry trades and similar ratio of longs to shorts.

    Here is an extract from the book I referenced to explain in detail:

    Kevin Davey: (Testing entries) “The first thing I usually want to know when testing a trading system is whether the entry has any usefulness. Many times, what looks like a good entry appears that way only because of the exits. Frequently it is difficult to know the true impact of entries when tested as a whole system. When I evaluate entries by themselves, I typically perform the analysis three ways:

    • Fixed‐stop and target exit
    • Fixed‐bar exit
    • Random exit

    Davey then describes these three.. etc etc…

    Exit Testing

    In a similar fashion to entry testing, there are a few different ways to test an exit. Where it gets complicated is when the exit is tied to the entry is some fashion. An example of this might be using support lines for entries, and resistance lines for exits. It is hard to separate the two. In these cases, I might choose not to even test exits by themselves, and rather proceed to a complete system test, discussed later.

    When I do evaluate exits by themselves, I typically perform the analysis two ways:

    • Similar‐approach entry
    • Random entry

    Similar‐Approach Entry

    The core idea behind testing exits by themselves is to see if they can help give you an edge. Most people see edges as being applicable only when you enter, but really, exits have just as much, if not more, impact on the bottom line. A carefully designed exit, it has been shown, can make even bad entry systems profitable!

    Since I will be testing the actual entry with the actual exit a bit later, at this point I want to see how the exit performs. To do this, I create an entry similar to the entry I want to use. This usually falls in one of two primary categories: trend following and countertrend following. Since I know what type of entry I have, I just create a generic one similar to it. For a trend‐following approach, for example, I may just employ an X‐bar breakout strategy. For a countertrend strategy, maybe I will use a relative strength index (RSI)‐based entry. In either case, I create an entry that is comparable to my actual entry. Then I test it with my exit strategy. A robust exit strategy that is profitable to my similar‐approach entries will likely also be profitable with my actual entry. This is a way to test an exit without involving the entry.

    Random Entry

    Discussed in a later section, if you have an exit strategy that works well with a random entry, you might have a really good system when you combine it with a solid entry technique. I do not use this approach as much as I used to, but occasionally I do like to see how a new exit technique works with random, no‐edge entries… etc etc..

    ■ Monkey See, Monkey Do

    One of the last tests I like to run is what I call “Monkey See, Monkey Do.” The essence of the test is to see if my strategy does better than a dart‐throwing monkey.

    Test 1: “Monkey Entry”

    The first test I run is to see if the entry I developed is better than random. I simply replace the entry in my strategy with an entry than creates a randomly generated entry. I run the random entry, with the rest of my strategy intact, 8,000 times. This generates 8,000 unique performance reports, since each run will have different randomly generated entries. By adjusting the frequency of the entry signals, I ensure that I get close to the same number of trades as my walk‐forward history. Also, I try to match the percentage of long and short trades. These two conditions mean that the “monkey” trades as often as my system does, and in roughly the same proportion of long and short trades.

    Typically, a good strategy will beat the monkey 9 times out of 10 in net profit and in maximum drawdown. For my 8,000 monkey trials, that means approximately 7,200 must have net profit worse than my results, and the same number of runs with higher maximum drawdown than my walk‐forward results. If I don’t reach these goals, I really have to wonder if my entry is truly better than random.

    Test 2: “Monkey Exit”

    The second test I run is to see if the exit I developed is better than random. It is much like the entry test, obviously, except in this case the monkey randomly exits the position. I control the random exit primarily by keeping the number of bars in a trade the same as my walk‐forward history. For example, if my walk‐forward history has an average of four bars per trade and always exits at the end of the day, I will tune the random exit to be on average the same. Also, it will always exit at the end of the day, if that is my criterion.

    As with the monkey entry, I look for my walk‐forward results to be better than 90 percent of the monkey exits.

    Test 3: “Monkey Entry, Monkey Exit”

    After determining that my strategy is better than both a monkey entry and a monkey exit, I like to see that my strategy is better than a monkey entry and exit. I do this because sometimes my edge is in the interaction of the entry and exit. For example, it might be that my entry is valid only because I set the exit near a support or re- sistance zone. It might be that the entry, taken alone, or the exit, taken alone, isn’t enough without the other.

    In this test, I replace all entry and exit code with random monkey code. I adjust the parameters of the random entry and exit to match my strategy in the following ways:

    • Number of trades
    • Ratio of long trades to short trades
    • Average bars spent in a trade

    Note that these conditions are the same I apply to the other monkey tests.Then I run the monkey entry, monkey exit strategy 8,000 times, just like the other tests, and compare results the same way.”

    “make an extra condition with a random value from 1 to 5 an add trade if dayofweek = randomvalue.” Do you have a code snippet for that?

    Also any link of random entries would be great – the ones I saw so far didn’t make any sense to me!

    Cheers
    Bard

    #85588
    Leo

    I posted a pseudo ramdom value from 1 to 10. Although the median is near 5. I Don like that it produces a lot of 10 and 1.

    I read your article.

    Still not having sense for me. I always test different Strategies for entry and exits and several combinations of them. I compared them between themself… Still not see the point of random dates in this ecuations… Something totally different is to find a seasonality pattern. That’s totally different.

    By the way, I never compare my codes with monkeys trowing dards.

    Maybe you can train infinity number of monkeys, one of them will write the code you need in prorealtime and another one will write a copy of a Shakespeare.

    1 user thanked author for this post.
    #92732

    Can anyone fix this random entry code so it trades on the days it’s actually coded to trade on? (Instead of trading on dates that bare no relation to the dates coded?

    Much appreciated,
    Thanks

     

Viewing 9 posts - 1 through 9 (of 9 total)

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