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
Code artist, my biography is a blank page waiting to be scripted. Imagine a bio so awesome it hasn't been coded yet.
Author’s Profile

Comments

Search Snippets

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

Snippets Categories

global
35
indicator
135
strategy
171

Recent Snippets

A multi indicator Dashboard for ProRealTime
indicator
This snippet creates a compact on-chart dashboard that aggregates multiple indicator states into a single, readable [...]
How to Track Up/Down Cumulative Volume Inside Each Candle (Tick Volume Delta)
indicator
This snippet separates the real-time, intra-candle volume into up-volume and down-volume based on whether the last [...]
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 [...]
Logo Logo
Loading...