last ...
This commit is contained in:
@@ -0,0 +1,505 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Indicator
|
||||
// -------------------------------------------------
|
||||
// Name: XOM1
|
||||
// Description: Integrates All Requirements inside
|
||||
// this indicator for analyse Markets Based on OM1 ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm XOM1 Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Definitions ...
|
||||
|
||||
//
|
||||
#define ShortName "XOM1"
|
||||
|
||||
//
|
||||
// Imports ...
|
||||
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
|
||||
//
|
||||
input group "Calculation";
|
||||
input ENUM_TIMEFRAMES obPeriod = PERIOD_H1; // Order Block Detection Period
|
||||
input ENUM_TIMEFRAMES fvgPeriod = PERIOD_M15; // Fair Value Gap Detection Period
|
||||
input ENUM_X_FIBO_LEVELS upperZoneLevel = X_FIBO_LEVEL_618; // Upper Zone Level
|
||||
input ENUM_X_FIBO_LEVELS lowerZoneLevel = X_FIBO_LEVEL_764; // Lower Zone Level
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
|
||||
input int maLength = 10; // MA Length
|
||||
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
// input bool showBars = true; // Show Bars
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
// Non Inputs ...
|
||||
|
||||
//
|
||||
#define hideColorIDX 0
|
||||
#define bullishColorIDX 1
|
||||
#define bearishColorIDX 2
|
||||
#define neuturalColorIDX 3
|
||||
|
||||
//
|
||||
#define bullishState 1
|
||||
#define neuturalState 0
|
||||
#define bearishState -1
|
||||
|
||||
//
|
||||
#define emptyValue 0.0
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 0
|
||||
#property indicator_plots 0
|
||||
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
#define mLastBufferIndex 15
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
|
||||
//
|
||||
int limit;
|
||||
|
||||
//
|
||||
int maxLength;
|
||||
|
||||
//
|
||||
int firstBarIndex;
|
||||
|
||||
//
|
||||
// Requirements ...
|
||||
CArrayObj mObjects;
|
||||
XCPOIDrawer *mDrawer;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
|
||||
/**
|
||||
* Initialize Indicator ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
bool has = false;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
has = ValidateInputs();
|
||||
if (!has)
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// because in some cases we may have more than one input for
|
||||
// calculation and we must prevent any calculation
|
||||
// untill we pass the biggest input length, here we get max Input length
|
||||
// and then wait until pass it ...
|
||||
maxLength = ExtractMaxLengthOfInputs();
|
||||
|
||||
//
|
||||
// Initial Requirements ...
|
||||
has = InitRequirements();
|
||||
if (!has)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// Define Index Buffers ...
|
||||
DefineBuffers();
|
||||
|
||||
//
|
||||
// Set Indicator ShortName ...
|
||||
SetIndicatorName();
|
||||
|
||||
//
|
||||
// Init Succeed ...
|
||||
return INIT_SUCCEEDED;
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* De Initialize Indicator ...
|
||||
*
|
||||
* @param reason: Integer, De Initialization Reason ...
|
||||
*/
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
//
|
||||
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
|
||||
// REASON_REMOVE 1 Program removed from a chart
|
||||
// REASON_RECOMPILE 2 Program recompiled
|
||||
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
|
||||
// REASON_CHARTCLOSE 4 Chart closed
|
||||
// REASON_PARAMETERS 5 Inputs changed by a user
|
||||
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
|
||||
// REASON_TEMPLATE 7 Another chart template applied
|
||||
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
|
||||
// REASON_CLOSE 9 Terminal closed
|
||||
|
||||
//
|
||||
delete mDrawer;
|
||||
ZeroMemory(mDrawer);
|
||||
|
||||
//
|
||||
mObjects.Clear();
|
||||
|
||||
//
|
||||
// De Initialize all Handlers and etc ...
|
||||
// IndicatorRelease(scMaHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Bars ...
|
||||
*
|
||||
* @param rates_total: Integer, Total Bars on Chart ...
|
||||
* @param prev_calculated: Integer, Total Calculated Bars on Charts ...
|
||||
* @param time: DateTime Array, History of Open Time ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param tick_volume: Long, History of Tick Volumes on Bar ...
|
||||
* @param volume: Long, History of Trade Volumes ...
|
||||
* @param spread: Double, History of Spread Price ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OnCalculate(
|
||||
const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Prepare Buffers ...
|
||||
ArraySetAsSeries(time, true);
|
||||
ArraySetAsSeries(open, true);
|
||||
ArraySetAsSeries(high, true);
|
||||
ArraySetAsSeries(low, true);
|
||||
ArraySetAsSeries(close, true);
|
||||
ArraySetAsSeries(tick_volume, true);
|
||||
ArraySetAsSeries(volume, true);
|
||||
ArraySetAsSeries(spread, true);
|
||||
|
||||
//
|
||||
// Validate Calculated Bars ...
|
||||
|
||||
//
|
||||
// int scCalculatedBars = BarsCalculated(scMaHandler);
|
||||
|
||||
// //
|
||||
// bool isPassedRequiredCalculatedBars =
|
||||
// //
|
||||
// // SC ...
|
||||
// scCalculatedBars >= maxLength
|
||||
// //
|
||||
// ;
|
||||
// if (!isPassedRequiredCalculatedBars)
|
||||
// {
|
||||
// return prev_calculated;
|
||||
// }
|
||||
|
||||
// //
|
||||
// limit = (prev_calculated > rates_total || prev_calculated <= 0)
|
||||
// ? rates_total
|
||||
// : (rates_total - prev_calculated) + 1;
|
||||
|
||||
//
|
||||
// Buffers Copy ...
|
||||
|
||||
// //
|
||||
// int copiedSCs = CopyBuffer(scMaHandler, MAIN_LINE, 0, limit, scMaBuffer);
|
||||
|
||||
// //
|
||||
// // Validate Copied Items ...
|
||||
// bool isPassedRequiredCopiedItems =
|
||||
// //
|
||||
// // SC ...
|
||||
// copiedSCs >= limit
|
||||
// //
|
||||
// ;
|
||||
// if (!isPassedRequiredCopiedItems)
|
||||
// {
|
||||
// return prev_calculated;
|
||||
// }
|
||||
|
||||
//
|
||||
// Main Loop ...
|
||||
for (int i = limit - 1; i >= 0 && !IsStopped(); i--)
|
||||
{
|
||||
//
|
||||
CalculateBuffers(
|
||||
i,
|
||||
prev_calculated,
|
||||
rates_total,
|
||||
//
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tick_volume //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
/**
|
||||
* Set Indicator Short Name and also we can define Buffers Labels ...
|
||||
*/
|
||||
void SetIndicatorName()
|
||||
{
|
||||
//
|
||||
IndicatorSetInteger(INDICATOR_DIGITS, _Digits);
|
||||
IndicatorSetString(INDICATOR_SHORTNAME, ShortName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate Input Args for Initialization ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
false
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Max Length of Inputs ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int ExtractMaxLengthOfInputs()
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
result = MathMax(result, 0);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define Required Buffers ...
|
||||
*/
|
||||
void DefineBuffers()
|
||||
{
|
||||
//
|
||||
// Plot Buffers ...
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Initial all Indicator Requirements ...
|
||||
*
|
||||
* @return ( false )
|
||||
*
|
||||
*/
|
||||
bool InitRequirements()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
// Handlers ...
|
||||
|
||||
// //
|
||||
// // SC ...
|
||||
// scMaHandler = iMA(
|
||||
// _Symbol,
|
||||
// _Period,
|
||||
// mSCMALength,
|
||||
// 0,
|
||||
// maMethod,
|
||||
// maAppliedTo //
|
||||
// );
|
||||
// result = scMaHandler != INVALID_HANDLE;
|
||||
// if (!result)
|
||||
// {
|
||||
// return result;
|
||||
// }
|
||||
|
||||
//
|
||||
mDrawer = new XCPOIDrawer();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Custom Buffers ...
|
||||
*
|
||||
* @param barIndex: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
* @param tickVolume: Long, History of Tick Volumes on Bar ...
|
||||
*/
|
||||
void CalculateBuffers(
|
||||
int barIndex,
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
// Calculate Bars Limit and First Bar Index ...
|
||||
int barsLimit = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: 0;
|
||||
if (barsLimit == 0)
|
||||
{
|
||||
//
|
||||
barsLimit = ratesTotal;
|
||||
firstBarIndex = barsLimit - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
firstBarIndex = startCalculationForLastBars;
|
||||
}
|
||||
|
||||
//
|
||||
// bool canCalculate = true;
|
||||
bool canCalculate =
|
||||
barIndex <= barsLimit;
|
||||
if (canCalculate)
|
||||
{
|
||||
//
|
||||
// Calculate Values ...
|
||||
CalculateValues(
|
||||
barIndex,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
FillBuffersZero(barIndex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill All Bufers to Zero Vlue for Specified Bar Index ...
|
||||
*
|
||||
* @param barIndex: Integer ...
|
||||
*/
|
||||
void FillBuffersZero(int barIndex)
|
||||
{
|
||||
//
|
||||
// TODO: Fill Buffers as Empty ...
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Values ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculateValues(
|
||||
int barIndex,
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = barIndex + 1;
|
||||
int maxBarIndex = startCalculationForLastBars > 0
|
||||
? startCalculationForLastBars
|
||||
: ratesTotal;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? barIndex == startCalculationForLastBars
|
||||
: barIndex == firstBarIndex;
|
||||
}
|
||||
|
||||
//
|
||||
Reference in New Issue
Block a user