Implementing Dynamic Lot Size Adjustment Based on Strategy Profit

07 Mar 2019
0 comment
0 attachment

This ProBuilder code snippet demonstrates how to dynamically adjust the trading lot size based on the accumulated strategy profit. The lot size increases when the profit reaches a certain threshold, promoting a compounding effect in profitable scenarios.

// RISK CONTROL IF THINGS ARE GOING WONDERFULL
n = 1 + (strategyprofit / (17*pipvalue))
n = SQRT(n)
n = round(n * 100)
n = n / 100
n = max(1,n)
// When the code wins 17*4=68 pips then it duplicates the size of lot.

Explanation of the code:

  • Initial Calculation: The variable n is initially set to 1 plus the ratio of strategyprofit to the product of 17 and pipvalue. This formula adjusts n based on the profit earned relative to a baseline of 17 pips.
  • Square Root Transformation: The square root of n is then calculated, which moderates the growth rate of the lot size, preventing it from increasing too rapidly.
  • Rounding: The value of n is multiplied by 100, rounded to the nearest whole number, and then divided by 100. This step ensures that n is expressed with a precision of two decimal places.
  • Ensuring Minimum Value: The max function is used to ensure that n does not fall below 1. This means that the lot size will never be less than the base lot size, maintaining a minimum trading volume.
  • Lot Size Doubling Condition: The comment indicates that when the cumulative profit equals 68 pips (17 pips × 4), the lot size is intended to double, aligning with the calculated value of n.

This snippet is a practical example of how to implement risk control and lot size management in algorithmic trading strategies using ProBuilder language.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/compounding-2/#post-69954

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
leo New
Currently debugging life, so my bio is on hold. Check back after the next commit for an update.
Author’s Profile

Comments

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
35
indicator
133
strategy
171

Recent Snippets

How to Create a Simple MTF Trend Dashboard with EMA and SMA
indicator
This indicator builds a compact multi-timeframe (MTF) dashboard that shows whether price is trading above or below a [...]
How to Display Per-Bar Volume Accumulation in Real Time (Intrabar Updates)
global
This snippet tracks and displays the current bar’s accumulated volume while the bar is still forming, instead of only [...]
Ticks Counter: Count Tick Updates Per Bar on Tick or Time Charts
global
This snippet counts how many tick updates have occurred for the current bar by incrementing a per-bar counter on each [...]
How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Logo Logo
Loading...