This code snippet demonstrates how to set and enforce a weekly profit limit in a trading strategy using the ProBuilder language. The strategy resets the profit calculation at the beginning of each week and disables trading once the profit exceeds a predefined limit.
ONCE MyProfit = 0 //Use this variable to tell when your profit exceeds X
ONCE TradeON = 1 //1=trading enabled, 0=trading disabled
ONCE X = 500 //500 € max weekly profit
IF OpenDayOfWeek = 1 AND OpenDayOfWeek[1] <> 1 THEN //at week start
MyProfit = StrategyProfit //save the total profit at the start of the week
TradeON = 1 //re-enable trading
ENDIF
IF (StrategyProfit - MyProfit) >= X THEN
TradeON = 0 //disable trading after X € gained
ENDIF
IF MyLongConditions AND Not OnMarket ANd TradeON THEN //add TradeON as an additional condition to enter a trade
BUY 1 Contract AT Market
ENDIF
The code snippet above is structured to manage trading based on weekly profit limits:
ONCE keyword. MyProfit tracks the profit at the start of the week, TradeON is a flag to enable or disable trading, and X sets the maximum weekly profit limit.OpenDayOfWeek equals 1 and the previous day’s OpenDayOfWeek was not 1), the script resets MyProfit to the current StrategyProfit and re-enables trading by setting TradeON to 1.StrategyProfit - MyProfit) has reached or exceeded the limit X. If it has, trading is disabled by setting TradeON to 0.MyLongConditions are met, the strategy is not currently in the market (Not OnMarket), and trading is enabled (TradeON).This approach helps in managing risk and ensuring that the trading strategy adheres to specific financial goals or constraints.
Check out this related content for more information:
https://www.prorealcode.com/topic/how-to-set-a-weekly-profit/#post-141701
Visit Link