This ProBuilder script demonstrates how to dynamically adjust the size of a trading position based on the profitability of the previous trade. The code snippet below shows how to increase the lot size by a percentage if the last trade was profitable.
ONCE LotSize = 1
ONCE PerCent = 1.2
ONCE TP = 30
ONCE SL = 100
IF StrategyProfit > StrategyProfit[1] THEN
LotSize = LotSize * PerCent
ENDIF
// Conditions to enter long positions
c1 = (RSIind < 30) //RSI upward momentum
// Conditions to enter long positions
IF NOT LongOnMarket AND c1 THEN
BUY LotSize CONTRACTS AT MARKET
Set target pprofit TP
SET STOP pLOSS SL
ENDIF
Explanation of the Code:
ONCE keyword, which ensures they are set only once and retain their values throughout the execution of the script.StrategyProfit) is greater than the strategy profit of the previous bar (StrategyProfit[1]). If true, it multiplies the LotSize by PerCent (1.2 in this case), effectively increasing the position size by 20%.c1, which checks if the RSI indicator value is below 30, suggesting potential upward momentum.NOT LongOnMarket) and condition c1 is true, the script executes a buy order with the adjusted LotSize. It also sets the take profit and stop loss levels as specified by TP and SL.This snippet is a practical example of how to implement a dynamic position sizing strategy based on the performance of previous trades, using basic trading indicators and profit tracking in ProBuilder.
Check out this related content for more information:
https://www.prorealcode.com/topic/increase-position-size-x-after-winning-trade/#post-132733
Visit Link