This code snippet demonstrates how to store and track the daily profit of a trading strategy in the ProBuilder language. The snippet specifically shows how to capture the strategy’s profit at the start of each day and calculate the daily profit by comparing it with the ongoing strategy profit.
ONCE MyStrategyProfit = 0
ONCE TempStrategyProfit = 0
IF IntraDayBarIndex = 0 THEN
MyStrategyProfit = StrategyProfit //StrategyProfit at the beginning of a new day
ENDIF
TempStrategyProfit = StrategyProfit - MyStrategyProfit//Daily StrategyProfit (that you can change at will)
Explanation of the Code:
ONCE keyword is used to initialize the variables MyStrategyProfit and TempStrategyProfit only once when the script starts running. Both variables are set to 0 initially.IF IntraDayBarIndex = 0 checks if the current bar is the first bar of the day. If true, it assigns the current total strategy profit (StrategyProfit) to MyStrategyProfit. This captures the strategy’s profit at the start of the day.TempStrategyProfit = StrategyProfit - MyStrategyProfit calculates the daily profit. It subtracts the profit at the start of the day from the current total strategy profit, resulting in the profit made during the current day.This approach allows traders and programmers to monitor and adjust their strategy’s performance on a daily basis, providing a clear view of how the strategy performs each day.