This code snippet demonstrates how to track the highest equity reached over all trades and within a specified number of recent trades using the ProBuilder language. Equity is calculated as the sum of the initial capital and the strategy’s profit. The code is divided into two parts: one for tracking the highest equity over all trades and another for tracking the highest equity over the last 100 trades.
// Highest Equity in ALL trades
once capital = 10000
once maxcapital = capital
equity = capital + strategyprofit
maxcapital = max(maxcapital,equity)
// Conditions based on equity comparison
IF equity < maxcapital then
condition1 = x
Elsif equity > maxcapital then
condition2 = y
Endif
// Highest Equity in the last 100 trades
once capital = 10000
once maxcapital = capital
once equity = capital
once Trades = 100
IF StrategyProfit <> StrategyProfit[1] THEN
TradeCount = lastset($myEquity) + 1
equity = capital + strategyprofit
$myEquity[TradeCount] = equity
N = 1
IF TradeCount >= Trades THEN
N = TradeCount - (Trades - 1)
ENDIF
maxcapital = capital
FOR i = TradeCount downto N
maxcapital = max(maxcapital,$myEquity[i])
NEXT
ENDIF
// Conditions based on equity comparison
IF equity < maxcapital then
condition1 = x
Elsif equity > maxcapital then
condition2 = y
Endif
Explanation of the code:
This snippet is useful for tracking performance in trading strategies, allowing developers to implement features based on historical and recent trading data.
Check out this related content for more information:
https://www.prorealcode.com/topic/capital-curve-as-an-indicator/#post-222482
Visit Link