Set position size depending on profitability of the strategy query

Forums ProRealTime English forum ProOrder support Set position size depending on profitability of the strategy query

  • This topic has 12 replies, 3 voices, and was last updated 4 months ago by avatarJS.
Viewing 13 posts - 1 through 13 (of 13 total)
  • #225252

    Hi All

    I have been going through the Advanced programming courses, and I am unsure about the code that is used in the “Set position size depending on profitability of the strategy” lesson.

    The way I understand it, the code starts with a trade size of 5 contracts. Each time there is a loss, the code reduces the contract size by 1, and after a win, the size moves back to 5 contracts.

    I have completed a backtest and gone through the first 20 trades. Because the system uses a loop of i = 1 TO 10, I am assuming that is why the first ten trades remain at 5 contracts.

    When trade 10 is a loss, trade 11 is set to 4 contracts. Trade 11 is also a loss, so trade 12 should be set using 3 contracts. Yet, trade 12 uses 5 contracts in the backtest. Is someone able to explain to me why this happens, please? It is very possible that I am misunderstanding the code logic.

     

    These are the results from the first 20 trades in my backtest:
    The first number is the trade number: 1 to 20
    L = Loss   W = Win
    The last number is the contract size: 1, 2, 3, 4 or 5

    1.    L      5
    2.    W    5
    3.    W    5
    4.    W    5
    5.    L     5
    6.    W   5
    7.    L    5
    8.    L    5
    9.    W   5
    10.  L    5
    11. L     4
    12. W   5
    13. L    5
    14. L    5
    15. L    4
    16. L    5
    17. W   3
    18. L    4
    19. L    5
    20. L   3

     

    Thanks, Brad

    #225255

    Hi there Brad – You best show your code, as we don’t know it …

    #225258

    Hi Peter
    It is the code used in the Advanced Programming Course, so I wasn’t sure if I could share it. If it’s not an issue, I’ll post it?

    #225265

    I think it is allowed to post it as it will be out of context of the course. And if not, a moderator may remove it again, say tomorrow. But post your code (the .itf) The mere reason would be that at this moment, to me the code seems to do wrong things. And in any event just helping you. 🙂

    I think it is also necessary to copy the given description, as mis-interpretation could be in order. For example :

    and gone through the first 20 trades. Because the system uses a loop of i = 1 TO 10, I am assuming that is why the first ten trades remain at 5 contracts.

    That is too much “off” from any normal reality. Thus, would this assumption be correct, then it has to be in the description. Also, it easily can be in “the small print” or the context of the assignment, which may tell that it is not allowed to go under water. Read : first build up some cash before “money management” jumps in, which would include that the system must be profitable to begin with. You could go all directions with it; actually I think it will be fun, also for others to read the workout (with a couple of judgments of other community members too).

    Regards,
    Peter

    1 user thanked author for this post.
    #225287

     

    #225300

    Hi Brad,

    I looked very very briefly before opening a couple of beers over here, but this :

    is as far as I know not proper ProRealCode syntax. The Editor / Interpreter does not reject it, and to my belief (without really checking) the result of this will be 0 (false). You could compare it to

    which never will be true.

    I can’t guess what the intentions are here, so maybe you can try to figure out the (most probably) two commands on separate lines you (or the book) intend(s).
    And possibly – when you solved that – it already runs as expected ?

    Otherwise it would be good if you tell on what instrument you test it, and in what TimeFrame of the chart (1 minute, 5 minute, 1 hour, etc.). Then we would all be able to communicate over it.

    1 user thanked author for this post.
    #225320

    I used Dax [Germany 40 Cash] on IG for the backtesting.

    As you will see in the code below, I added a daily timeframe condition, but the code is implemented on the 1-hour timeframe. (Not the TP & SL have also been changed).

    Following the  Win/Loss sequence for the first 20 trades, the first trade was placed on 16 February 2023.

     

    Regarding:

    The following explanation was given in a previous video:

    // Boolean test: Test is true (equal to one) when the highest value of increase over the last 5 periods is zero. This means the MACD has not increased at all over the last 5 consecutive periods.

     

     

     

     

    #225321

    OK, I will follow a course myself. Haha.

    But why did I ask to post the .itf ? (which emerges on disk when you Export the strategy) … because then all would be clear how you set things. So in this case this can be about the Tick by Tick mode, and the Spread which I don’t know (can look it up, but you must apply this correctly just the same).
    And also : it is always good to add a screenshot from the result you get. This allows us to compare and see whether our bases match.

    Below you see what I get with a Spread of 4. First trade is indeed at Feb 16 with 5K bars of 1 hour data.

    1 user thanked author for this post.
    #225332

    Here you go. ITF file and screenshots are attached.

    Needless to say, I’m not trying to make this a profitable strategy; I’m simply applying what I am learning as I progress through the programming course.

    Brad.

    #225338

    Brad, I think you did a great job.
    Look below what I made of it, which is a 10 minute attempt. IOW, there is potential.

    Notice that you need to use the wrench you see in the 3rd attachment to proceed (and load the .itf attached first). The SL Parameter in there is not used by me. I only added it so it can be used by you if you want.
    Further, all I changed really was this line :

    which is totally unrelated to the program logic. N.b.: That “ratio” naming is a bit besides the truth, but you can name it as you want.

    If you like, you could have a next assignment from me :

    • You don’t know which Parameter combination I used, so you must find one yourself which will be able to compete with the future (you should soon see what I mean).
    • The combination you finally chose, should be accompanied by your description why it is the best for you. Hint : you don’t want to lose your money.
    • Of course you are going to show the results and post the .itf again. 🙂

    Mind the Graph command I added and which you can do yourself just the same for any variable you like. GraphOnPrice also exists. And Print in V12.

    Again, very well done.
    Peter

    PS: Is that Spread of 2 something you dug up from IG web pages ? And does it count for the whole day ?

     

     

    1 user thanked author for this post.
    #225342

    But I have also another small assignment for you (if you like) :

    As you can see below, Size can become Negative and this is not intentional for this Short-only strategy (SellShort -1 will not work). So you should fine the culprit in this, or else at least prevent it (backdoor solution). The former is the way to go of course (solve it in the base).

    1 user thanked author for this post.
    #225367

    Hi Peter

    Thanks for your feedback and assistance.

    • It looks like you used a TP of 180 and a ‘ratio’ setting of 0.3. This creates a 1:3.33 RR Ratio.
    • I don’t want a ratio of zero; a SL won’t be set. Trades will continue until the TP is reached or my account goes bust. (The drawdown is bigger than the set account size).
    • When looking at the results, setting a TP of 180 with a SL ratio of 0.3 or 0.4 gives the best return with the lowest drawdown. Ideally, the win rate needs work.
    • Thanks for the graph command. That is going to help going forward.
    • Regarding the spread, I didn’t put much thought into that. I’m more concerned about understanding the coding. I will focus on the finer details once I am more comfortable with the coding logic.

     

    Response to your next post:

    • The “MAX(1, Size)” part of the code is supposed to prevent negative contract size. The video also explained this: When selling short, the maximum size will be used (Size = 5), but not below 1.

    I’m keen to hear your comments on the coding video once you have viewed them. The code that determines the contract size vs. the backtest results still baffles me.

     

    Regards

    Brad

    #225382
    JS

    Hi @Brad

    I wouldn’t spend any more time on it because the code of the example is very illogical and full of errors…

    For example, when I look at the “SignalBar” it becomes the same as the “BarIndex” when the conditions are true for the first time, but… this “SignalBar” is never reset…

    I think the example is more something to highlight certain parts, but as a whole there is no logic to it…

    2 users thanked author for this post.
Viewing 13 posts - 1 through 13 (of 13 total)

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