Sliding Window Winrate

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #218567 quote
    taklause
    Participant
    New

    Hello altogether,

    for my strategy I want to reward the position size if the current winrate is above a certain value and punish otherwise.

    I have found the code to implement it over all trades that have been done so far with this:

    IF STRATEGYPROFIT> STRATEGYPROFIT[1] THEN
    WinningTrades = WinningTrades + 1
    ENDIF

    However, there are some bad “times” in the strategy which go unheard due to the bigger amount of positive trades. This is why I wanted to implement the sliding window approach.

     

    IF AllTrades > SlidingWindowWinRate THEN
    FOR runner = 1 TO SlidingWindowWinRate DO
    IF STRATEGYPROFIT[runner] < STRATEGYPROFIT[1 + runner] THEN
    WinningTradesSlidingWindow = WinningTradesSlidingWindow + 1
    ENDIF
    NEXT
    ENDIF

    So far I have learned that looping over STRATEGYPROFIT does not work due to obvious reasons ;). Has someone done that so far?

    Thanks in advance,

    Daniel

    #218576 quote
    taklause
    Participant
    New

    For others who want to achieve the same :

     

    IF MyProfitSoFar > MyProfitSoFar[1] THEN
    WinningTrades = WinningTrades + 1
    $SlidingWindowTrades[lastset($SlidingWindowTrades)+1] = 1
    ENDIF
    
    IF MyProfitSoFar < MyProfitSoFar[1] THEN
    $SlidingWindowTrades[lastset($SlidingWindowTrades)+1] = 0
    ENDIF
    
    winningTradesVariable = 0
    FOR i = LASTSET($SlidingWindowTrades) DOWNTO LASTSET($SlidingWindowTrades)-SlidingWindowWinRate do
    IF $SlidingWindowTrades[i]THEN
    winningTradesVariable = winningTradesVariable + 1
    ENDIF
    NEXT
    #218581 quote
    Nicolas
    Keymaster
    Master

    looping over STRATEGYPROFIT does not work due to obvious reasons

    You can loop over STRATEGYPROFIT values, just like a price consant or any other variables, but since it updates only when it has changes, the offset in brackets correspond to the bars offset from now, so there is no way to know how to get the last 10 changes just by making a loop “FOR I = 1 TO 10”

    taklause thanked this post
    #218610 quote
    taklause
    Participant
    New

    Turns out that with my solution that I posted above,  I receive the following error if I want to run it in production/demo (not in backtest).

    … exceeds the limit of 1,000,000 in an array

    So I guess I start at square 1.

    How to either fix the broken array?

    How to calculate the sliding window winrate otherwise?

    Regards

    #218613 quote
    JS
    Participant
    Senior

    Hi,

    You can try to start the code with resetting the array…

    UnSet($SlidingWindowTrades)

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

Sliding Window Winrate


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
taklause @taklause Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/03/2023
Status: Active
Attachments: No files
Logo Logo
Loading...