Re: Requests & Ideas (MT5)

721
qwepoi123 wrote: Tue Jun 17, 2025 11:20 am @mrtools ,Dear friend, I'm sorry but for some reason, all of my messages from yesterday have disappeared. It may be a violation of the forum's rules. Due to changing my trading platform, I need your help because of these reasons
The original author of these indicators is you, so I need your help to convert them into the EX5 version? Thank you, my English is not very good. I hope you can understand the trouble caused by this. Thank you! Thank you for your great contributions!
Posted a converted Arsi here.


Re: Requests & Ideas (MT5)

722
qwepoi123 wrote: Tue Jun 17, 2025 11:20 am @mrtools ,Dear friend, I'm sorry but for some reason, all of my messages from yesterday have disappeared. It may be a violation of the forum's rules. Due to changing my trading platform, I need your help because of these reasons
The original author of these indicators is you, so I need your help to convert them into the EX5 version? Thank you, my English is not very good. I hope you can understand the trouble caused by this. Thank you! Thank you for your great contributions!
Posted an osma averages here to check out.
These users thanked the author mrtools for the post:
alexm


Re: Requests & Ideas (MT5)

726
try this

a couple of note:

-About the lag: The indicator lags by HalfLength bars, not specifically 10. With the default HalfLength=12, it lags 12 bars. If you set HalfLength=10, then yes, it would lag 10 bars.

-About recalculation: The last HalfLength bars ALWAYS recalculate internally, regardless of the DrawExtrapolatedPart setting. DrawExtrapolatedPart only controls the VISUALIZATION, not the calculation itself. So it doesn't actually prevent recalculation, it just hides the recalculating portion from the chart

+C+
These users thanked the author Cagliostro for the post (total 5):
mrtools, davidpont, eduarescobar, uncle wong, Eis
"I conjure from shadows and shape fortunes from the unseen. The treasure lies hidden in plain sight, beneath the sunlight." - Cagliostro

Re: Requests & Ideas (MT5)

727
Thank you interesting remarks....

I should have said HalfLength bars,I was not carefull enough.
You said DrawExtrapolatedPart only controls the VISUALIZATION, not the calculation itself. The last HalfLength bars ALWAYS recalculate internally,Can you explain the '' internally'' ?

Because the idea derived from FIR MA and AFIRMA indicators from Vladimir aka ''gpwr'' and coded by Mladen.

AFIRMA extrapolates the last 10 bars with spline and FIR MA indicator have no extrapolator in it but it lags 10 bar. According to several discussions in old form that Mladen said FIR MA indicator doesnt recalculate.It is easy to test it.We can actually put it on 1 minute bars see it ourselves.

Excellent explanation by Vladimir why he did not code fast fourrier transform instead of AFIRMA and FIR MA indicators ;

Frankly speaking, I don't advocate application of FFT (full or cosine) for construction of moving averages for the reason that FFT breaks prices series by frequencies 2*pi*k*l/N, i.e. frequencies are known in advance though prices series can have stronger harmonics at adjacent frequencies different from 2*pi*k*l/N. The FFT idea is based on fitting a trigonometric series to a real series using the method of least squares. This way any orthogonal functions (orthogonal polynomials, in the simplest case) can be fitted. The advantage of the FFT is that the amplitudes of the trigonometric functions are samples of the frequency response of the process with a constant step of 2*pi/N. By using FFT it is possible to reject high frequency harmonics and thus construct a moving average. But such filtering is much more complicated than digital filtering such as simple moving average or FIR filter. Take a look at my moving average indicators based on FIR filter:

'FIR MA'.
AFIRMA'.

Re: Requests & Ideas (MT5)

728
You're right about FIR MA - it doesn't recalculate because it's causal (uses only past data).
By "internally" I meant: the TMA centered always computes values for the last HalfLength bars using future data, but when DrawExtrapolatedPart=false, these values are stored in buffer2 without being displayed.
Key difference:

FIR MA: Causal filter, no future data → no recalculation, true lag
TMA Centered: Non-causal, uses future data → must recalculate when new bars arrive

You can verify: put TMA centered on M1 chart - the last HalfLength values will change with each new bar, while FIR MA values remain fixed once calculated.
FIR/AFIRMA is indeed more robust for real-time trading. The TMA centered is more of a visual analysis tool due to its non-causal nature.
These users thanked the author Cagliostro for the post:
uncle wong
"I conjure from shadows and shape fortunes from the unseen. The treasure lies hidden in plain sight, beneath the sunlight." - Cagliostro

Re: MQL5 Promt

729
What do the yellow bars signify?
ZigZag wrote: Thu Jun 12, 2025 8:26 pm If you are working with non-native code editor (like me), use this prompt for editor AI agent and feel free to suggest something else too if you found critical issues.

This is before you will start adding more complexity & bridges & features for your existing tools.

Also, run this prompt to every indicator you actuall use just like this !

You will be surprised.

If you are bulding new one add this one too "This code is built in accordance with the "Anti-Corruption Blueprint" architecture. It isolates the core signal computation, stores it in a "pristine" state, and applies all additional features modularly without feedback loops. Each feature is independent, user-configurable, and adheres to MQL5 standards and the strict constraints you have set.

Context: The following rules and prohibitions must be followed precisely when adding new features to an existing, functioning MQL5 indicator. The goal is to preserve the indicator’s stability, non-repainting nature, and compatibility, while adding new functionality in a modular way. All rules are critical, and violating them may break the functionality of the indicator."

đź”’ Part 1: Context and Fundamental Rules

The “Engine” is Locked
â—¦ All existing calculation functions (e.g., ApplyAdaptiveFilter, CalculateAdaptiveNormalization, SetSignalVisualization) and their internal logic are untouchable.
â—¦ These functions must not be altered in any way, as they are proven stable and non-repainting.

OnCalculate() is Sacred
â—¦ The structure or calculation loop of the existing OnCalculate() function must not be modified.
â—¦ The only allowed change is appending an independent function call for a new feature at the end of the loop.

OnInit() is Sacred
â—¦ The content of OnInit() must not be modified unless a new feature explicitly requires the initialization of a new buffer or plot.
â—¦ In such a case, the change must be minimal and appended only at the end of the existing structure.

No Feedback Loops
â—¦ A new feature may only read from existing buffers (e.g., main_signal[], upper_zone[]).
â—¦ It must not write to or influence the calculation of these buffers in any way.
◦ New features must act as “readers,” not “writers” to the engine.

No Heavy Operations in OnCalculate Loop
â—¦ The OnCalculate() loop must not include heavy operations, such as:
â–Ş ObjectCreate
â–Ş File handling
â–Ş Loops iterating over historical data

Preserve Original Style
â—¦ The original formatting, indentation, and commenting style must be preserved.

â›” Part 2: Additional Areas and Prohibitions

Data Type and Precision Rules
â—¦ Always use the double type for price and calculated values. Never use float.
â—¦ Never use NormalizeDouble() during calculations. Only use it for final output (e.g., Print(), Comment()).
◦ Remember, color is a distinct type – use ColorToARGB() or equivalent correctly.

Built-in Indicator Rules
â—¦ Indicator handles are to be created only in OnInit() and stored in global variables.
â—¦ CopyBuffer() is only allowed in OnCalculate() for fetching data.
â—¦ Do not call functions like iMA, iRSI, iATR inside the OnCalculate() loop.

Code Clarity Rules
â—¦ Do not use magic numbers (e.g., if(value > 1.5)) without defining them.
â—¦ New thresholds must be defined using input variables or #define macros.

Error Handling Rules
â—¦ Always check if function calls like SetIndexBuffer, CopyBuffer succeed.
â—¦ If CopyBuffer fails, skip the calculation for that candle.

Variable Management Rules
â—¦ Do not use existing global or static variables in new feature logic.
â—¦ Create clearly named, dedicated variables for each new feature.
â—¦ Do not recycle existing variables, even to save space.

Structural Compatibility
◦ New features must not alter the indicator’s existing visual or computational behavior unless explicitly requested.
â—¦ New visual elements (e.g., PlotIndexSetInteger, ObjectCreate) must be controlled via input booleans.

Compatibility Across Timeframes and Symbols
â—¦ Do not hardcode Symbol() or Period() comparisons.
â—¦ All features must function correctly across all symbols and timeframes.

Modularity and Removability
â—¦ Each feature must be implemented modularly so it can be removed without affecting others.
â—¦ All names (variables, functions) must be clearly tied to the feature name (e.g., ZeroCross_AlertFired).

No Assumptions
â—¦ Do not add logic or default behavior unless explicitly requested (e.g., ObjectDeleteAll()).
â—¦ All operations must be based on input values or existing code.

Use Only MQL5 Syntax – No MQL4
â—¦ Do not use MQL4 syntax (e.g., IndicatorBuffers(), SetIndexStyle(), ArraySetAsSeries()).

No PlotIndexSet... Calls in OnCalculate()
â—¦ Drawing is controlled by writing values (or EMPTY_VALUE) to buffers.

Technical Requirements and Best Practices
â—¦ Stable Drawing:
â–Ş All plot properties (PlotIndexSetInteger, PlotIndexSetString, PlotIndexSetDouble) must be set only in OnInit().
â–Ş Do not change plot types or persistent visual settings inside OnCalculate().

â—¦ Visibility Dynamics via EMPTY_VALUE:
â–Ş Drawing visibility is managed by writing EMPTY_VALUE to the buffer to hide plots for specific candles, without changing visual properties on the fly.

User Customizability
â—¦ All new features must be user-configurable, including line widths, colors, and thresholds.
â—¦ Each feature must have on/off switches grouped in the indicator settings.

MQL5 Standard Compliance
â—¦ All syntax, functions, and structures must follow the MetaTrader 5 MQL5 standard.
â—¦ Use SetIndexBuffer() for data binding (e.g., SetIndexBuffer(0, main_signal, INDICATOR_DATA);).
â—¦ Use only PlotIndexSetInteger(), PlotIndexSetDouble(), PlotIndexSetString() for visual settings.
â—¦ Do not invent functions like PlotIndexSetBuffer. Data binding and visual formatting are separate processes.

OnInit() Rules
â—¦ Use OnInit() for setting all visual properties of plots:
â–Ş For data binding: SetIndexBuffer()
â–Ş For visuals: Only PlotIndexSetInteger(), PlotIndexSetDouble(), PlotIndexSetString()
â–Ş Do not merge these processes. Keep binding and styling separate.

No Shared Global Variables (Shared State Ban)
â—¦ Do not use global or static variables to store intermediate results inside OnCalculate().
â—¦ Globals are only allowed for storing input values from OnInit() (e.g., MarketSensitivity = InpMarketSensitivity;).
â—¦ Previous candle values must always be read from buffers (e.g., GetSafeValue(volatility_buffer, shift + 1)), not globals.
â—¦ Violating this rule breaks multi-instance functionality; each instance must run independently in its own sandbox.

Global Filters are Untouchable
â—¦ Do not modify existing global filters.

🛑 Part 3: New Prohibitions and Clarifications

No Dynamic Re-definition of Buffers
â—¦ Do not attempt to change the type (INDICATOR_DATA, INDICATOR_COLOR_INDEX, etc.) or size of existing buffers at any point during execution.
◦ New buffers must be declared in OnInit() and remain unchanged throughout the indicator’s lifecycle.

No Iterative Calculation Attempts
◦ Do not add logic that tries to “fix” or iterate calculations inside OnCalculate() if the result is unexpected (e.g., repeated attempts with different parameters).
â—¦ This could cause instability and violate the non-repainting rule.

No External Dependencies Without Permission
â—¦ Do not add dependencies on external libraries, files, or resources unless explicitly requested.
â—¦ All logic required for a new feature must be self-contained within the code.

No Optimization Attempts Without Documentation
â—¦ Do not try to optimize existing code (e.g., simplify calculation functions) unless explicitly requested.
â—¦ Optimizations may silently break sensitive logic, especially in adaptive filters.

No Default Activations for New Features
â—¦ New feature parameters must not have default values that affect behavior without user intent.
â—¦ For example, a new alert must default to off (false), not on.

No Global State Variables for Temporary Use
◦ Do not use global variables to store temporary states (e.g., “was alert triggered on this candle”).
â—¦ Use clearly named local variables or buffers specific to the feature (e.g., new_feature_state_buffer[]).

No Hidden Functions or Background Calculations
â—¦ Do not add any logic that runs calculations or actions in the background without being visible or user-controlled.
â—¦ All actions must be tied to input parameters.

No Dynamic Time Interval Checks
â—¦ Do not add logic that checks candle time intervals (e.g., if(Time - Time[i-1] > some_value)) unless explicitly requested.
â—¦ This can lead to inconsistent behavior across timeframes.

No Overwriting Global Buffers
â—¦ Do not use existing global buffers as temporary storage in new feature logic.
â—¦ Always create new buffers for new features.

No Google-AI Style Logic Overwrites
◦ Do not replace or restructure existing logic even if it seems “better” or “simpler.”
◦ Google-style AI overwrites are dangerous—small changes may silently break non-repainting behavior or cause unexpected output.
â—¦ Example: Do not modify the function that calculates an adaptive average, even to add a new parameter. Instead, create a separate function.

Do Not Reduce Line Spacing or Compress Existing Code
â—¦ Do not reduce line spacing or compress code unless excess blank lines are truly unnecessary.
â—¦ Long and tightly packed lines make manual debugging significantly harder.

No Hardcoded MTF Values
â—¦ Do not hardcode any Multi-Timeframe (MTF) values, such as timeframes, data sync methods, or buffer sizes.
â—¦ All MTF features must be implemented dynamically using input ENUM_TIMEFRAMES parameters.
â—¦ Examples of prohibited practices:
â–Ş Hardcoded timeframe list (e.g., if(timeframe == PERIOD_H1))
â–Ş Hardcoded assumption of MTF data availability (e.g., CopyBuffer(handle, 0, 0, 100, buffer) without dynamic sizing)
â–Ş Hardcoded sync logic (e.g., assuming MTF data always aligns with current candle index)
â—¦ MTF functionality must be fully configurable via input parameters and work seamlessly across all timeframes without manual code adjustments.