Initial Commit ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,968 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL4 Global Library
|
||||
// ---------------------------------------------
|
||||
// saherelm useful tools and definitions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Includes Logger library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq4"
|
||||
|
||||
//
|
||||
// Includes Drawing library ...
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq4"
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Determines current working is New Bar or not ...
|
||||
bool IsNewBar() {
|
||||
//
|
||||
static datetime lastbar;
|
||||
datetime curbar = (datetime)SeriesInfoInteger(_Symbol, _Period, SERIES_LASTBAR_DATE);
|
||||
|
||||
//
|
||||
if(lastbar != curbar) {
|
||||
//
|
||||
lastbar = curbar;
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve RMA on Specific Candle ...
|
||||
double GetRMA(
|
||||
int bar_index,
|
||||
int length
|
||||
) {
|
||||
//
|
||||
double shortSMA = iMA(_Symbol, _Period, length, 0, MODE_SMA, PRICE_CLOSE, bar_index);
|
||||
double mediumSMA = iMA(_Symbol, _Period, length * 2, 0, MODE_SMA, PRICE_CLOSE, bar_index);
|
||||
double longSMA = iMA(_Symbol, _Period, length * 3, 0, MODE_SMA, PRICE_CLOSE, bar_index);
|
||||
|
||||
//
|
||||
double result = longSMA - mediumSMA + shortSMA;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// this function check crossing up two Buffers ...
|
||||
bool IsCrossedOver(
|
||||
double &arr1[],
|
||||
double &arr2[],
|
||||
int index1,
|
||||
int index2 = -1
|
||||
) {
|
||||
//
|
||||
// Normalize Index 2 Value ...
|
||||
if (index2 < 0) {
|
||||
index2 = index1 + 1;
|
||||
}
|
||||
|
||||
//
|
||||
bool result = (arr1[index1] > arr2[index1]) && !(arr1[index2] > arr2[index2]);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// this function check crossing down two Buffers ...
|
||||
bool IsCrossedUnder(
|
||||
double &arr1[],
|
||||
double &arr2[],
|
||||
int index1,
|
||||
int index2 = -1
|
||||
) {
|
||||
//
|
||||
// Normalize Index 2 Value ...
|
||||
if (index2 < 0) {
|
||||
index2 = index1 + 1;
|
||||
}
|
||||
|
||||
//
|
||||
bool result = (arr1[index1] < arr2[index1]) && !(arr1[index2] < arr2[index2]);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert points to Actual Point ...
|
||||
double PointsToDouble(int points) {
|
||||
//
|
||||
double result = points * _Point;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts Pips to Points ...
|
||||
int PipsToPoints(int pips) {
|
||||
//
|
||||
int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1);
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts Pips to Double ...
|
||||
double PipsToDouble(int pips) {
|
||||
//
|
||||
double result = PointsToDouble(PipsToPoints(pips));
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts Double Value to Pips ...
|
||||
int PriceToPips(double value) {
|
||||
//
|
||||
if (value <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
double pipValue = _Point * MathPow(10, _Digits);
|
||||
int result = (int)(value / pipValue);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Converts Pips to Double ...
|
||||
double PipsToPrice(int pips) {
|
||||
//
|
||||
if (pips <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
double pipValue = _Point * MathPow(10, _Digits);
|
||||
double result = pipValue * pips;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Generate ATR StopLoss Value ...
|
||||
double CalculateATRSL(
|
||||
int period,
|
||||
double multiplier
|
||||
) {
|
||||
//
|
||||
if (period <= 0 || multiplier <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
double atrValue = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
period,
|
||||
0
|
||||
);
|
||||
|
||||
//
|
||||
double result = atrValue * multiplier;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Candle Type ...
|
||||
// Bullish => means close > open ...
|
||||
bool isBullishCandle(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Temp Result ...
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (bar_index < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double open = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double close = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
result = isBullishCandle(
|
||||
open,
|
||||
close
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isBullishCandle(
|
||||
const double open,
|
||||
const double close
|
||||
) {
|
||||
//
|
||||
// Temp Result ...
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = open < close;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Candle Type ...
|
||||
// Bearish => means close < open ...
|
||||
bool isBearishCandle(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
// Temp Result ...
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (bar_index < 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double open = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double close = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
result = isBearishCandle(
|
||||
open,
|
||||
close
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
bool isBearishCandle(
|
||||
const double open,
|
||||
const double close
|
||||
) {
|
||||
//
|
||||
// Temp Result ...
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = open > close;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Highest High Value based on Given Market ...
|
||||
double GetMarketHighestHigh(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const int marketLen // Market Length ...
|
||||
) {
|
||||
//
|
||||
// Empty Result ...
|
||||
double result = 0.0;
|
||||
|
||||
//
|
||||
// Retrieve Desired Bar Index ...
|
||||
int foundedBarIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketLen,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Price ...
|
||||
result = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
foundedBarIndex
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Highest High Value based on Given Market ...
|
||||
double GetMarketLowestLow(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const int marketLen // Market Length ...
|
||||
) {
|
||||
//
|
||||
// Empty Result ...
|
||||
double result = 0.0;
|
||||
|
||||
//
|
||||
// Retrieve Desired Bar Index ...
|
||||
int foundedBarIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketLen,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Price ...
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
foundedBarIndex
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Highest High Value based on Given Market ...
|
||||
double GetMarketHighestOpen(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const int marketLen // Market Length ...
|
||||
) {
|
||||
//
|
||||
// Empty Result ...
|
||||
double result = 0.0;
|
||||
|
||||
//
|
||||
// Retrieve Desired Bar Index ...
|
||||
int foundedBarIndex = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_OPEN,
|
||||
marketLen,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Price ...
|
||||
result = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
foundedBarIndex
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Highest High Value based on Given Market ...
|
||||
double GetMarketLowestClose(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const int marketLen // Market Length ...
|
||||
) {
|
||||
//
|
||||
// Empty Result ...
|
||||
double result = 0.0;
|
||||
|
||||
//
|
||||
// Retrieve Desired Bar Index ...
|
||||
int foundedBarIndex = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_CLOSE,
|
||||
marketLen,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve Price ...
|
||||
result = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
foundedBarIndex
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Low Price is
|
||||
// less than given price ...
|
||||
double GetLowLessCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result >= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetLowLessCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP >= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Low Price is
|
||||
// great than given price ...
|
||||
double GetLowGreatCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result >= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetLowGreatCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP >= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's High Price is
|
||||
// less than given price ...
|
||||
double GetHighLessCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result >= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetHighLessCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP >= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's High Price is
|
||||
// great than given price ...
|
||||
double GetHighGreatCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result <= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetHighGreatCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP <= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Open Price is
|
||||
// less than given price ...
|
||||
double GetOpenLessCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result >= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetOpenLessCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP >= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Open Price is
|
||||
// less than given price ...
|
||||
double GetOpenGreatCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result <= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetOpenGreatCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iOpen(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP <= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Close Price is
|
||||
// less than given price ...
|
||||
double GetCloseLessCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result >= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetCloseLessCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP >= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Find last Candle which it's Close Price is
|
||||
// great than given price ...
|
||||
double GetCloseGreatCandlePrice(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int index = bar_index + 1;
|
||||
double result = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
|
||||
//
|
||||
while (result <= price) {
|
||||
//
|
||||
index++;
|
||||
|
||||
//
|
||||
result = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
index
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
int GetCloseGreatCandleIndex(
|
||||
//
|
||||
const int bar_index, // Bar Index ...
|
||||
const double price // Position Open Price ...
|
||||
) {
|
||||
//
|
||||
int result = bar_index + 1;
|
||||
double cP = iClose(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
|
||||
//
|
||||
while (cP <= price) {
|
||||
//
|
||||
result++;
|
||||
|
||||
//
|
||||
cP = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
result
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
struct XMinMax {
|
||||
double min;
|
||||
double max;
|
||||
};
|
||||
|
||||
//
|
||||
// Find Min and Max Value of specific Buffer ...
|
||||
XMinMax GetBufferMinMax(const double &buffer[]) {
|
||||
//
|
||||
XMinMax result = {};
|
||||
|
||||
//
|
||||
int bufferSize = ArraySize(buffer);
|
||||
if (bufferSize < 1) {
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double min = buffer[0];
|
||||
double max = buffer[0];
|
||||
|
||||
//
|
||||
for (int i = 1; i < bufferSize; i++) {
|
||||
//
|
||||
if (buffer[i] < min) {
|
||||
min = buffer[i];
|
||||
} else if (buffer[i] > max) {
|
||||
max = buffer[i];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result.min = min;
|
||||
result.max = max;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,47 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL4 Draw Global Library
|
||||
// ---------------------------------------------
|
||||
// saherelm useful tools and definitions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Log Tag ...
|
||||
static string logTag = "";
|
||||
|
||||
//
|
||||
// Enable or Disable Logging ...
|
||||
static bool enableLogging = false;
|
||||
|
||||
//
|
||||
// Start Log Messages ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logging a Message, specified for this EA ...
|
||||
// using provided LogTag ...
|
||||
void LogMessage(string message) {
|
||||
//
|
||||
if (!enableLogging) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
Print(logTag, " > ", message);
|
||||
}
|
||||
|
||||
//
|
||||
// End Log Messages ...
|
||||
//
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL4 Models Global Library
|
||||
// ---------------------------------------------
|
||||
// saherelm useful tools and definitions ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// Start Models ...
|
||||
//
|
||||
|
||||
//
|
||||
// Used Indicators List ...
|
||||
const string xmaIndicatorName = "x-saherelm.xma";
|
||||
const string adxIndicatorName = "x-saherelm.adx";
|
||||
const string oscIndicatorName = "x-saherelm.osc";
|
||||
const string zigZagIndicatorName = "x-saherelm.zigzag";
|
||||
|
||||
//
|
||||
// Direction ...
|
||||
enum X_DIRECTION {
|
||||
X_UP,
|
||||
X_DOWN
|
||||
};
|
||||
|
||||
//
|
||||
// these are different signal types ...
|
||||
enum X_SIGNAL_TYPE {
|
||||
X_NONE,
|
||||
X_LONG,
|
||||
X_SHORT,
|
||||
};
|
||||
|
||||
//
|
||||
// we Model each signals as this type ...
|
||||
struct XSignal {
|
||||
int id;
|
||||
X_SIGNAL_TYPE type;
|
||||
double tp;
|
||||
double sl;
|
||||
string symbol;
|
||||
datetime time;
|
||||
double entryPrice;
|
||||
};
|
||||
|
||||
//
|
||||
// this is Signal Request Response model ...
|
||||
struct XSignalRequest {
|
||||
bool hasSignal;
|
||||
X_SIGNAL_TYPE type;
|
||||
XSignal signal;
|
||||
};
|
||||
|
||||
//
|
||||
// we model OSC Return Data ...
|
||||
struct XOSCState {
|
||||
//
|
||||
double fastOSC;
|
||||
double fastOSCPrev;
|
||||
|
||||
//
|
||||
double slowOSC;
|
||||
double slowOSCPrev;
|
||||
|
||||
//
|
||||
double powerOSC;
|
||||
double powerOSCPrev;
|
||||
|
||||
//
|
||||
double varOSC;
|
||||
double varOSCPrev;
|
||||
|
||||
//
|
||||
double tanFSOSC;
|
||||
|
||||
//
|
||||
bool isOSCCrossOver;
|
||||
bool isOSCCrossUnder;
|
||||
};
|
||||
|
||||
//
|
||||
// Define a Model to Represent Snapshot of XMA Indicator ...
|
||||
struct XMAState {
|
||||
//
|
||||
// Short Cycle ...
|
||||
//
|
||||
// FAST ...
|
||||
double scFast;
|
||||
double scFastPrev;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
double scSlow;
|
||||
double scSlowPrev;
|
||||
|
||||
//
|
||||
bool isSCTrendUp;
|
||||
|
||||
//
|
||||
// Medium Cycle ...
|
||||
//
|
||||
// FAST ...
|
||||
double mcFast;
|
||||
double mcFastPrev;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
double mcSlow;
|
||||
double mcSlowPrev;
|
||||
|
||||
//
|
||||
// Long Cycle ...
|
||||
//
|
||||
// FAST ...
|
||||
double lcFast;
|
||||
double lcFastPrev;
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
double lcSlow;
|
||||
double lcSlowPrev;
|
||||
|
||||
//
|
||||
// MIDDLEAGE ...
|
||||
double marketMiddleage;
|
||||
double marketMiddleagePrev;
|
||||
};
|
||||
|
||||
//
|
||||
// Represent ADX State ...
|
||||
struct XADXState {
|
||||
//
|
||||
double trendPower;
|
||||
double trendPowerPrev;
|
||||
|
||||
//
|
||||
double upDirection;
|
||||
double upDirectionPrev;
|
||||
|
||||
//
|
||||
double downDirection;
|
||||
double downDirectionPrev;
|
||||
|
||||
//
|
||||
bool isUpTrend;
|
||||
bool isDownTrend;
|
||||
};
|
||||
|
||||
//
|
||||
// ZigZag State ...
|
||||
struct XZigZagState {
|
||||
//
|
||||
double zigZag;
|
||||
datetime zigZagTime;
|
||||
|
||||
//
|
||||
double zigZagPrev;
|
||||
datetime zigZagPrevTime;
|
||||
|
||||
//
|
||||
double low;
|
||||
int lowBarIndex;
|
||||
datetime lowTime;
|
||||
|
||||
//
|
||||
double high;
|
||||
int highBarIndex;
|
||||
datetime highTime;
|
||||
|
||||
//
|
||||
double delta;
|
||||
|
||||
//
|
||||
bool isWaitForTrendUp;
|
||||
bool isWaitForTrendDown;
|
||||
|
||||
//
|
||||
bool isLowIsLastLow;
|
||||
bool isHighIsLastHigh;
|
||||
};
|
||||
//
|
||||
// End Models ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user