Files
mql5/Indicators/MyIndicators/UltimateOscillator_Pro.mq5
T

137 lines
5.2 KiB
Plaintext
Raw Normal View History

2025-10-01 13:22:49 +02:00
//+------------------------------------------------------------------+
//| UltimateOscillator_Pro.mq5 |
//| Copyright 2025, xxxxxxxx|
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, xxxxxxxx"
#property link ""
2025-10-04 15:14:53 +02:00
#property version "2.10" // Added optional signal line
#property description "Professional Ultimate Oscillator with an optional signal line and"
#property description "selectable candle source (Standard or Heikin Ashi)."
2025-10-01 13:22:49 +02:00
//--- Indicator Window and Plot Properties ---
#property indicator_separate_window
2025-10-04 15:14:53 +02:00
#property indicator_buffers 2 // UO and Signal Line
#property indicator_plots 2
2025-10-01 13:22:49 +02:00
#property indicator_maximum 100.0
#property indicator_minimum 0.0
#property indicator_level1 30.0
#property indicator_level2 50.0
#property indicator_level3 70.0
#property indicator_levelstyle STYLE_DOT
2025-10-04 15:14:53 +02:00
//--- Plot 1: UO Line
#property indicator_label1 "UO"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDodgerBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- Plot 2: Signal Line
#property indicator_label2 "Signal"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrOrangeRed
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
2025-10-01 13:22:49 +02:00
//--- Include the calculator engine ---
#include <MyIncludes\UltimateOscillator_Calculator.mqh>
2025-10-04 15:14:53 +02:00
//--- Enum for Display Mode ---
enum ENUM_DISPLAY_MODE
{
DISPLAY_UO_ONLY, // Display only the UO line
DISPLAY_UO_AND_SIGNAL // Display UO and its signal line
};
2025-10-01 13:22:49 +02:00
//--- Enum for selecting the candle source for calculation ---
enum ENUM_CANDLE_SOURCE
{
CANDLE_STANDARD, // Use standard OHLC data
CANDLE_HEIKIN_ASHI // Use Heikin Ashi smoothed data
};
//--- Input Parameters ---
2025-10-04 15:14:53 +02:00
input group "Oscillator Settings"
input int InpPeriod1 = 7;
input int InpPeriod2 = 14;
input int InpPeriod3 = 28;
2025-10-01 13:22:49 +02:00
input ENUM_CANDLE_SOURCE InpCandleSource = CANDLE_STANDARD;
2025-10-04 15:14:53 +02:00
input group "Signal Line Settings"
input ENUM_DISPLAY_MODE InpDisplayMode = DISPLAY_UO_AND_SIGNAL;
input int InpSignalPeriod = 9;
input ENUM_MA_METHOD InpSignalMAType = MODE_SMA;
2025-10-01 13:22:49 +02:00
//--- Indicator Buffers ---
double BufferUO[];
2025-10-04 15:14:53 +02:00
double BufferSignal[];
2025-10-01 13:22:49 +02:00
//--- Global calculator object (as a base class pointer) ---
CUltimateOscillatorCalculator *g_calculator;
//+------------------------------------------------------------------+
//| Custom indicator initialization function. |
//+------------------------------------------------------------------+
int OnInit()
{
2025-10-04 15:14:53 +02:00
SetIndexBuffer(0, BufferUO, INDICATOR_DATA);
SetIndexBuffer(1, BufferSignal, INDICATOR_DATA);
ArraySetAsSeries(BufferUO, false);
ArraySetAsSeries(BufferSignal, false);
2025-10-01 13:22:49 +02:00
switch(InpCandleSource)
{
case CANDLE_HEIKIN_ASHI:
g_calculator = new CUltimateOscillatorCalculator_HA();
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("UO HA(%d,%d,%d)", InpPeriod1, InpPeriod2, InpPeriod3));
break;
default: // CANDLE_STANDARD
g_calculator = new CUltimateOscillatorCalculator();
IndicatorSetString(INDICATOR_SHORTNAME, StringFormat("UO(%d,%d,%d)", InpPeriod1, InpPeriod2, InpPeriod3));
break;
}
2025-10-04 15:14:53 +02:00
if(CheckPointer(g_calculator) == POINTER_INVALID || !g_calculator.Init(InpPeriod1, InpPeriod2, InpPeriod3, InpSignalPeriod, InpSignalMAType))
2025-10-01 13:22:49 +02:00
{
Print("Failed to create or initialize Ultimate Oscillator Calculator object.");
return(INIT_FAILED);
}
2025-10-04 15:14:53 +02:00
int uo_draw_begin = MathMax(InpPeriod1, MathMax(InpPeriod2, InpPeriod3));
PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, uo_draw_begin);
PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, uo_draw_begin + InpSignalPeriod - 1);
2025-10-01 13:22:49 +02:00
IndicatorSetInteger(INDICATOR_DIGITS, 2);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function. |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(CheckPointer(g_calculator) != POINTER_INVALID)
delete g_calculator;
}
//+------------------------------------------------------------------+
//| Custom indicator calculation function. |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int, const datetime&[], const double &open[], const double &high[], const double &low[], const double &close[], const long&[], const long&[], const int&[])
{
if(CheckPointer(g_calculator) == POINTER_INVALID)
return 0;
2025-10-04 15:14:53 +02:00
g_calculator.Calculate(rates_total, open, high, low, close, BufferUO, BufferSignal);
if(InpDisplayMode == DISPLAY_UO_ONLY)
{
for(int i=0; i<rates_total; i++)
BufferSignal[i] = EMPTY_VALUE;
}
2025-10-01 13:22:49 +02:00
return(rates_total);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+