203 lines
3.7 KiB
Plaintext
203 lines
3.7 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
// Multiply two Buffer ...
|
|
void MultiplyBuffer(
|
|
const double &buffer1[],
|
|
const double &buffer2[],
|
|
double &result[]
|
|
) {
|
|
//
|
|
int buffer1Size = ArraySize(buffer1);
|
|
int buffer2Size = ArraySize(buffer2);
|
|
|
|
//
|
|
int size = MathMax(buffer1Size, buffer2Size);
|
|
|
|
//
|
|
ArrayResize(result, size);
|
|
ArrayFill(result, 0, size, 0.0);
|
|
|
|
//
|
|
for (int i = 0; i < size; i++) {
|
|
result[i] = buffer1[i] * buffer2[i];
|
|
}
|
|
}
|
|
|
|
//
|
|
// Calculate SMA ...
|
|
double iSMA(
|
|
const double &src[],
|
|
const int len = 7,
|
|
const int bar_index = 0
|
|
) {
|
|
//
|
|
double result = 0.0;
|
|
|
|
//
|
|
for (int i = bar_index + (len - 1); i >= bar_index; i--) {
|
|
result += src[bar_index] / len;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Calculat VMA ...
|
|
double iVWMA(
|
|
const double &src[],
|
|
const long &volume[],
|
|
const int len = 7,
|
|
const int bar_index = 0
|
|
) {
|
|
//
|
|
double result = 0.0;
|
|
|
|
//
|
|
// double volume ...
|
|
int volumeSize = ArraySize(volume);
|
|
double dVolume[];
|
|
ArrayResize(dVolume, volumeSize);
|
|
ArrayFill(dVolume, 0, volumeSize, 0.0);
|
|
for (int i = 0; i < volumeSize; i++) {
|
|
dVolume[i] = volume[i] * 1.0;
|
|
};
|
|
|
|
|
|
//
|
|
double multipliedSourceVolume[];
|
|
MultiplyBuffer(
|
|
src,
|
|
dVolume,
|
|
multipliedSourceVolume
|
|
);
|
|
|
|
//
|
|
result = iSMA(
|
|
multipliedSourceVolume,
|
|
len
|
|
) / iSMA(
|
|
dVolume,
|
|
len
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
//
|
|
// END Functions ...
|
|
// |