Calculating win percentage
Forums › ProRealTime English forum › ProOrder support › Calculating win percentage
- This topic has 2 replies, 2 voices, and was last updated 1 month ago by Leo440.
-
-
10/24/2024 at 2:58 PM #239420
Hello everyone,
This afternoon I’ve been trying to calculate the win percentage of a strategy, with the idea being that when performance is poor a smaller position size can be taken. My graph is showing 0 or 10 rather than the expected 0-100 range. Any comments or ideas greatly appreciated!
Leo
ProRealTrend with win% graph1234567891011121314151617181920212223242526272829303132333435363738394041DEFPARAM CumulateOrders=FalseREM Buyindicator1 = closeindicator2 = SuperTrend[7,67]c1 = (indicator1 >= indicator2)IF c1 THENBUY 1 SHARES AT MARKETENDIFREM Sellindicator3 = closeindicator4 = SuperTrend[7,67]c2 = (indicator3 <= indicator4)IF c2 THENSELLSHORT AT MARKETENDIF// Initialize variableswins = 0totalTrades = 10// Loop through the last 10 tradesfor value1 = 1 to totalTradesnextIf strategyprofit[value1] > strategyprofit[value1 + 1] thenwins = wins + 1endif// Calculate the win percentagevalue2 = ((wins / totalTrades) * 100)// Output the win percentageGRAPH value2 as "Win %"10/24/2024 at 6:55 PM #239428You shoukd move NEXT from line 31 to line 36, to make the code in between to be part of the iteration.
Do not use REM as it may conflict with the keyword REMark. Use double slashes (“//”), instead.
You are not summing up the last 10 trades, but the trades in the last 10 bars. If you are using a 1-hour TF, then you will only scan what happened in the last 10 hours.
Arrays are needed to do what you want:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950DEFPARAM CumulateOrders=False// initialize the array on the very first barONCE Elements = 10IF BarIndex = 0 THENFOR i = 1 TO Elements$WinningTrade[i] = 0NEXTENDIF/*UPDATE the array everytime a trade is a winnerShift Elements-1 elemnts to the left, to drop the leftmost (oldest) trade andmake room for the current trade to be stored in element 1 (the rightmost element)*/IF StrategyProfit <> StrategyProfit[1] THENFOR i = Elements DOWNTO 2$WinningTrade[i] = $WinningTrade[i - 1]NEXT$WinningTrade[1] = (StrategyProfit > StrategyProfit[1]) //assign 1 for a winning// trade, 0 otherwise// Initialize variableswins = 0// Loop through the last 10 tradesfor i = 1 to Elementswins = wins + $WinningTrade[i]next// Calculate the win percentagevalue2 = ((wins / Elements) * 100)ENDIF// Buyindicator1 = closeindicator2 = SuperTrend[7,67]c1 = (indicator1 >= indicator2)IF c1 THENBUY 1 SHARES AT MARKETENDIF// Sellindicator3 = closeindicator4 = SuperTrend[7,67]c2 = (indicator3 <= indicator4)IF c2 THENSELLSHORT AT MARKETENDIF// Output the win percentageGRAPH value2 as "Win %"10/24/2024 at 8:31 PM #239433ALL HAIL ROBERTO
You legend! Thank you so much, I would never have got that.
Leo
1 user thanked author for this post.
-
AuthorPosts