Adaptive-Trend-And-Fib-Levels
21 $
14 $
This is an MQL4 custom indicator named "Adaptive Trend & Fib Levels", designed to display adaptive trends and Fibonacci levels on a chart.
Adaptive Trend & Fib Levels Indicator, Forex indicators
This MQL4 custom indicator is designed to calculate and display adaptive trends and Fibonacci levels on a trading chart. Below are the detailed functionalities and structure of the indicator.
1. Properties and Buffers
Indicator Properties:
#property indicator_chart_window
: The indicator operates in the main chart window.- Four color-coded buffers are defined for drawing lines on the chart:
- Buffer 1:
Silver
(Fibonacci Level) - Buffer 2:
Yellow
(100% Level) - Buffer 3:
Red
(First EMA) - Buffer 4:
Blue
(Second EMA)
Indicator Buffers:
Fib1Buffer
: Stores the Fibonacci level values.L100Buffer
: Stores the 100% level (trailing value).Ema6Buffer
andEma18Buffer
: Intended for EMA calculations (currently commented out).
2. Inputs and Parameters
Inputs:
ATRFactor
: Multiplier for ATR-based trailing stop calculations.ATRPeriod
: Period for ATR calculations.trailtype
: Determines the trailing type (Modified or Unmodified).EmaPriod1
andEmaPriod2
: Periods for EMA calculations (currently unused).
3. Initialization Function (OnInit()
)
The OnInit()
function maps the indicator buffers to their respective styles and labels:
- Buffer 1:
Fibo
(Silver line). - Buffer 2:
L100
(Yellow line). - Buffer 3:
First EMA
(Red line). - Buffer 4:
Second EMA
(Blue line).
4. Main Calculation Function (OnCalculate()
)
This function computes the trend, Fibonacci levels, and ATR-based trailing stops:
- Calculates ATR using a modified or unmodified method based on the
trailtype
input. - Computes the Fibonacci level (
Fib1Buffer
) and trailing stop level (L100Buffer
). - Updates trend direction based on the trailing stop values:
- If the price is above the trailing stop, the trend is upward.
- If the price is below the trailing stop, the trend is downward.
5. Helper Functions
max2(v1, v2)
: Returns the maximum of two values.max3(v1, v2, v3)
: Returns the maximum of three values.Wild_ma(index, length)
: Computes a Wilder's Moving Average for the given index and length.
6. Outputs
The indicator displays the following on the chart:
- A Fibonacci level line (
Fib1Buffer
). - A 100% trailing stop line (
L100Buffer
). - Placeholder for EMA lines (
Ema6Buffer
andEma18Buffer
).