Sliding Window Winrate
Forums › ProRealTime English forum › ProOrder support › Sliding Window Winrate
- This topic has 4 replies, 3 voices, and was last updated 1 year ago by JS.
-
-
08/03/2023 at 11:51 PM #218567
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
ENDIFHowever, 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
ENDIFSo 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
08/04/2023 at 9:16 AM #218576For others who want to achieve the same :
123456789101112131415IF MyProfitSoFar > MyProfitSoFar[1] THENWinningTrades = WinningTrades + 1$SlidingWindowTrades[lastset($SlidingWindowTrades)+1] = 1ENDIFIF MyProfitSoFar < MyProfitSoFar[1] THEN$SlidingWindowTrades[lastset($SlidingWindowTrades)+1] = 0ENDIFwinningTradesVariable = 0FOR i = LASTSET($SlidingWindowTrades) DOWNTO LASTSET($SlidingWindowTrades)-SlidingWindowWinRate doIF $SlidingWindowTrades[i]THENwinningTradesVariable = winningTradesVariable + 1ENDIFNEXT08/04/2023 at 10:11 AM #218581looping 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”
1 user thanked author for this post.
08/04/2023 at 8:38 PM #218610Turns 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
08/05/2023 at 7:48 AM #218613 -
AuthorPosts