Performance Issues lag with Position Sizer
I get performance issues when running Position Sizer. I've tester each indicator 1 by 1, and Position Sizer gets cycles to 2 trillion, bugging chart until restart MT5. This behaviour can be seen by pressing F2 on MT5.
When chatting with AI, it said:
Critical Performance Problems Found
- Timer Recalculation Every 200ms (Lines 1380-1390 in MQ5)
- RefreshValues() is MASSIVE (Lines 1949-2063 in MQH)
- RecalculatePositionSize() is a Monster (Lines 2517-2923 in MQH)
- DisplayValues() Updates Everything (Lines 1323-1556 in MQH)
The Solution: Smart Caching + Dirty Flags Step 1: Add Dirty Flags to Settings Class Step 2: Cache Heavy Calculations Step 3: Smart RefreshValues() Step 4: Optimize Timer Frequency Step 5: Mark Events as Dirty
Implementation Priority Do these in order: ✅ Timer frequency (line 1380 in MQ5) - 60% immediate gain ✅ Calculation cache (add before RefreshValues) - 70% gain when combined ✅ Smart RefreshValues (replace existing) - Prevents unnecessary work ⚠️ Dirty flags in event handlers - Do gradually as needed
This image shows the problems when Position Sizer is put in the chart
I'm not a programmer, nor I feel confortable editing the code with AI prompts...
I deeply thank the authors behind this EA; Because for free, it's a great piece of work, and i've been using it since ~2020, just wanted to contribute the way I can.
Thanks, best regards!
Hello!
- I don't see any problem in the attached screenshot. If anything it shows that the PS is taking very little of the CPU time and your entire MT5 isn't taking more than 2% of your CPU's total performance.
- Normally, the Position Sizer isn't causing any performance issues. I am running an MT5 with about 5-6 Position Sizers always on and it isn't causing any issues at all.
- The AI response is totally off the mark. There are things to optimize in the PS, but those aren't what the AI says.
- My first recommendation would be to re-compile the Position Sizer using the optimization mode based on your CPU. You can check your CPU architecture in the Journal tab when you just start the MT5. It will say something like this: 'Windows Server 2008 R2 Service Pack 1 build 7601 on VMware, 3 x Intel Xeon E5-2630 v4 @ 2.20GHz, AVX, 4 / 5 Gb memory, 2 / 44 Gb disk, RDP, admin, GMT+2.' That 'AVX' is your architecture - it can also be AVX2 or AVX512. Then you can select it for the compiler by clicking on a dropdown arrow near the Compile button in the MetaEditor.
I hope this helps.
Did this help?