Portfolio Expert - Wish list

Hello Mr. Popov,
I would like to request a dynamic lot sizing feature (percentage of equity) be added to the auto-generated EA code.

I was able to add this to my Porfolio EA with the following MQL5 code. Feel free to adjust /change:

enum ENUM_MM_TYPE {
   MM_FIXED,      // Fixed Lots
   MM_PERCENT     // Risk Percent
};

input ENUM_MM_TYPE MM_Type = MM_FIXED; // Money Management Type
input double Risk_Percent  = 1.0;      // Risk Percentage (%)
static input double Entry_Amount = 0.01; // Entry lots (or fallback if SL is 0)
//+------------------------------------------------------------------+
//| Calculate Dynamic Lot Size based on Risk %                       |
//+------------------------------------------------------------------+
double GetDynamicLots(int slPips)
{
   // If Fixed mode is selected, or if the strategy has no Stop Loss (0), use fixed lots
   if(MM_Type == MM_FIXED || slPips <= 0) 
      return Entry_Amount;

   double equity = AccountInfoDouble(ACCOUNT_EQUITY);
   double riskAmount = equity * (Risk_Percent / 100.0);

   double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
   double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   
   // Safety check to prevent division by zero
   if(tickSize == 0 || tickValue == 0) return Entry_Amount;

   // Calculate the monetary loss per 1.00 lot if Stop Loss is hit
   // We use the global 'pip' variable already defined in your EA
   double slPriceDistance = slPips * pip; 
   double lossPerLot = (slPriceDistance / tickSize) * tickValue;

   if(lossPerLot <= 0) return Entry_Amount;

   double calculatedLots = riskAmount / lossPerLot;

   // Normalize lots to the broker's step (e.g., 0.01)
   calculatedLots = MathFloor(calculatedLots / lotStep) * lotStep;

   // Check Broker Limits
   double minVol = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   double maxVol = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);

   if(calculatedLots < minVol) calculatedLots = minVol;
   if(calculatedLots > maxVol) calculatedLots = maxVol;

   return calculatedLots;
}

Update the `OpenPosition` Function: change

const double posLots    = Entry_Amount;

...to this:

const double posLots    = GetDynamicLots(signal.StopLossPips);

Thank you

How does the "experts" avoid overfitting?

Hi,

I have two questions:
    1.    What exactly do you do when you say, “now suppose we run this portfolio live from 1 June 2025 to 5 Dec 2025”? Do you test the walk-forward in EA Studio, or do you test it in MT4/MT5? Or is there another process involved?
    2.    There is certainly some influence, but in my experience the IS–OOS split is not the primary driver of overfitting. Have you considered changing the way you generate strategies in EA Studio?

BR
Vincenzo

How does the "experts" avoid overfitting?

If that is your approach, why on Ea studio there is no way to see a chart where:

x-axis : indicator parameter
y-axis : balance

the idea is that a good parameter should be located on a zone where changing it a bit would not change drastically the outcome of the strategy. If the strategy performs good only on a certain parameter, then most likely overfit.

How does the "experts" avoid overfitting?

> Thanks, care to explain what you mean with that?

A) Let's run the generator with 30% OOS and generate 100 strategies. Then enable all data and validate the strategies again. Let's have 20 strategies show good performance.

B) Run the Generator on the complete data set and stop it when it finds 20 strategies.

Result: In both cases, we have 20 strategies that perform well on the complete data set.

Question: Are the A-strategies better than the B-strategies?

Let's assume A-strategies are better and think of the reasons for that:
- they are battle-scarred
- they are the best 25% and received after eliminating the failed
- we used more complex software to find them
- we worked more and used more knowledge to find them

What if it happens that we have the same strategies in both collections?
I'm pretty sure all the B-startegies will pass the OOS criteria (except if we have some "U" shaped curves smile )

...

What I do (not advice!)
- run the generator
- look at the strategies one by one to see if the indicator rules are in sync
- play with the numeric parameters with the mouse wheel to see how the balance changes
- test on data from a different broker
- put on MetaTrader to see what will happen without any expectations. If it works, well.

How does the "experts" avoid overfitting?

I wrote my opinion about OOS several years ago.  Basically, it only heats the universe.

Thanks, care to explain what you mean with that? Or maybe if you can point me to the post where you talked about it?

Thanks

MT4 Portfolio not detecting previous trades

> If that's the case, wouldn't it make sense to have SetPosStats inside OnInit?

It makes sense.

I'll check it and will update the code.

Thank you!

How does the "experts" avoid overfitting?

I wrote my opinion about OOS several years ago.  Basically, it only heats the universe.

Please test the strategies with the new "Max Spread Protection" option set to a meaningful value. Let's say about 30-50 points.

Then look at the strategies one by one and see if the logical rules are meaningful (which is subjective, of course).

Error message

footon wrote:

Most probably it is to do with one of the indicators, and again with high probability it is a custom one. Are you using custom indis?
If you remove it, it won't give an error no more. But you need to find it. If you can report it here, I can take a look and maybe fix it.
If you are able, then open the Indicators tab in the generator and test your custom indis by running a few of them at a time until you get that one causing the error.

I select all build in and all down loaded custom indicators. So, I may exclude all custom and remain the build in group of indicators to run generator.

Error message

Most probably it is to do with one of the indicators, and again with high probability it is a custom one. Are you using custom indis?
If you remove it, it won't give an error no more. But you need to find it. If you can report it here, I can take a look and maybe fix it.
If you are able, then open the Indicators tab in the generator and test your custom indis by running a few of them at a time until you get that one causing the error.

Error message

What happen when I run the generator on FSB Pro but some time the error dialog box occures as my attached picture. Any one who know how to solve this problem please inform me.