Weird results on end of day strategy with position sizing

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #106017 quote
    Vonasi
    Moderator
    Master

    I coded a simple strategy on the daily chart that buys or sells and then closes the position at the next open. All was looking good so I thought that I would just try a simple bit of position sizing adjustment to see how it effected performance. Quite simply if the day is a winning day then position size is the maximum allowed but if it is a losing day then position size is reduced by 1 down to a minimum of 1.

    All very simple but when I tested it suddenly I get a totally different number of trades and win rate depending on what the maximum allowed position size is. The trade count and win rate should not change as nothing but position size is different in the strategy! The first image is the results with a max starting position size from 1 to 14.

    So then I thought I’d throw in a DEFPARAM CUMULATEORDERS = FALSE and this fixed the problem but created another which has been highlighted before as it only allows trades in the same direction on every other day. Second image is the results table for that.

    So I went back to the first results and started looking at the charts and found that on anything above a maximum position size of 2 the equity curve was showing the strategy as having run out of money. How can it have run out of money having won so much and starting with a capital of 100k and having a maximum position size of only 3 at any time? It would seem to me that the back test is thinking that it has more positions open than it actually does. See third image.

    Or am I missing something?

    Here is the code but I have removed my ‘secret indicator’ – just replace it in line 24 with one of your choice. It simply has to be something that is rising or falling!

    //defparam cumulateorders = false
    
    x = 80
    positionsizing = 1 //positionsizing on or off
    
    if positionsizing then
    once ps = v
    
    //return to maximum stake if a win
    if longonmarket and positionperf > positionperf(1) or shortonmarket and positionperf > positionperf(1) then
    ps = v //reset to maximum size
    endif
    
    //reduce stake by 1 if a loss
    if longonmarket and positionperf < positionperf(1) or shortonmarket and positionperf < positionperf(1) then
    ps = max(1,ps - 1)//reduce stake size by 1 down to minimum 1
    endif
    else
    ps = 1//level stakes
    endif
    
    if barindex >= x then
    indicator = (rising or falling indicator of your choice)
    
    red = close < open
    green = close > open
    
    indicatorup = indicator > indicator[1] and green
    indicatordown = indicator < indicator[1] and red
    
    //close all trades at start of day
    if onmarket then
    sell at market
    exitshort at market
    endif
    
    //long entry
    if indicatordown then
    buy ps contract at market
    endif
    
    //short entry
    if indicatorup then
    sellshort ps contract at market
    endif
    endif
    
    //graph ps
    Screenshot_1-2.png Screenshot_1-2.png Screenshot_2-3.png Screenshot_2-3.png Screenshot_3-5.png Screenshot_3-5.png
    #106023 quote
    Vonasi
    Moderator
    Master

    If I increase my starting capital to 1000000 then I can get all optimisation tests to run through with out running out of money. It seems like the back test thinks it has positions on the market that it doesn’t when it comes to calculating available equity. A possible bug?

    I still don’t understand the trade count and win rate difference.

    Screenshot_7-3.png Screenshot_7-3.png
    #106025 quote
    GraHal
    Participant
    Master

    Mmm sounds worrying and as you say maybe another bug that had never shown itself due to not all conditions having been exhaustively tested.

    PRT would do well to get you on their UAT Team Vonasi … even if they only paid you with … mmm?? 🙂

    #106027 quote
    Vonasi
    Moderator
    Master

    How to make a million by trading – get paid a dollar for every bug you find!

    Jokes aside I think the reason for the different number of trades is that the back tests counts a change of position as a trade so if I place a 14 point bet and then conditions are still true but I am down then the strategy says sell 14 and buy 13 but in reality it sells 1 and calls it a trade. If however that happens thirteen times in a row then it says sell 1 and buy 1 but in reality does nothing and so that is not a trade. If you start with a max position of 2 then you get a lot more 1 to 1 non trades and a lot less 3 to 2  and 2 to 1 actual trades.

    I think that somewhere some of the trades are not getting closed out in the ‘you’ve gone bust’ calculation.

    #106028 quote
    Vonasi
    Moderator
    Master

    Topic moved to the Platform forum as I think this is now more of a platform issue rather than a ProOrder coding issue.

    GraHal thanked this post
    #106512 quote
    Nicolas
    Keymaster
    Master

    I just had a news about this, the problem is identified and should be quickly fixed (just wait for the next patch).

    Vonasi and GraHal thanked this post
    #109051 quote
    Nicolas
    Keymaster
    Master

    I dont know if it’s because of your birthday Vonasi, but this weird problem is now fixed in the actual version of the indicator 🙂

    Vonasi thanked this post
    #109053 quote
    GraHal
    Participant
    Master

    Happy Birthday Vonasi 🙂

    Vonasi thanked this post
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Weird results on end of day strategy with position sizing


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
Vonasi @vonasi Moderator
Summary

This topic contains 7 replies,
has 3 voices, and was last updated by GraHal
6 years, 4 months ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 08/31/2019
Status: Active
Attachments: 4 files
Logo Logo
Loading...