Initial Commit ...
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,173 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MA Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
// this indicator uses two ma line:
|
||||
// - fast ma;
|
||||
// - slow ma;
|
||||
//
|
||||
// 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
//
|
||||
// Fast MA ...
|
||||
input int maLength = 20; // MA Length
|
||||
input int maShift = 0; // MA Shift
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||
input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 1
|
||||
|
||||
//
|
||||
#property indicator_plots 1
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Fast Ma Buffer ...
|
||||
#property indicator_label1 "Ma"
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrYellow
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 2
|
||||
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define maBufferIndex 0
|
||||
|
||||
double maBuffer[];
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (maLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// Start Set Index Buffers ...
|
||||
//
|
||||
//
|
||||
// Ma ...
|
||||
SetIndexBuffer(maBufferIndex, maBuffer);
|
||||
SetIndexDrawBegin(maBufferIndex, maLength + 1);
|
||||
//
|
||||
// End Set Index Buffers ...
|
||||
//
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
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[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
int maxLength = MathMax(0, maLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculate Ma ...
|
||||
CalculateMa(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateMa(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Calculating Fast Ma ...
|
||||
double ma = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maLength,
|
||||
maShift,
|
||||
maMethod,
|
||||
maAppliedPrice,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
maBuffer[bar_index] = ma;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,294 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XRange Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
//
|
||||
// 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 XRange Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 14;
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 3
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
//
|
||||
// Highest High Buffer ...
|
||||
#property indicator_type1 DRAW_LINE
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
// Lowest Low Buffer ...
|
||||
#property indicator_type2 DRAW_LINE
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// Middle Buffer ...
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DASH
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
//
|
||||
#define highestHighBufferIndex 0
|
||||
#define lowestLowBufferIndex 1
|
||||
#define middleBufferIndex 2
|
||||
|
||||
//
|
||||
double highestHighBuffer[];
|
||||
double lowestLowBuffer[];
|
||||
double middleBuffer[];
|
||||
|
||||
//
|
||||
datetime startTime;
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (
|
||||
marketLength <= 0
|
||||
) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
string hhLbl = StringConcatenate(
|
||||
"XR HH(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(highestHighBufferIndex, highestHighBuffer);
|
||||
SetIndexLabel(highestHighBufferIndex, hhLbl);
|
||||
|
||||
//
|
||||
string llLbl = StringConcatenate(
|
||||
"XR LL(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer);
|
||||
SetIndexLabel(lowestLowBufferIndex, llLbl);
|
||||
|
||||
//
|
||||
string midLbl = StringConcatenate(
|
||||
"XR Mid(", marketLength, ")"
|
||||
);
|
||||
SetIndexBuffer(middleBufferIndex, middleBuffer);
|
||||
SetIndexLabel(middleBufferIndex, midLbl);
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
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[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculations ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculations ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
// Retrieve Bar Time ...
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
if (startTime == 0) {
|
||||
//
|
||||
startTime = barTime;
|
||||
SetIndicatorBuffersNone(bar_index);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
startTime
|
||||
);
|
||||
|
||||
//
|
||||
int startDistance = startBarIndex - bar_index;
|
||||
if (startDistance < marketLength) {
|
||||
//
|
||||
SetIndicatorBuffersNone(bar_index);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
int hhIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketLength,
|
||||
bar_index
|
||||
);
|
||||
double hh = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
highestHighBuffer[bar_index] = hh;
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
int llIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketLength,
|
||||
bar_index
|
||||
);
|
||||
double ll = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
lowestLowBuffer[bar_index] = ll;
|
||||
|
||||
//
|
||||
// Middle Buffer ...
|
||||
double mid = (hh + ll) / 2;
|
||||
middleBuffer[bar_index] = mid;
|
||||
|
||||
//
|
||||
// Reset Start Time ...
|
||||
startTime = 0;
|
||||
}
|
||||
|
||||
//
|
||||
void SetIndicatorBuffersNone(
|
||||
const int bar_index
|
||||
) {
|
||||
//
|
||||
int lastBarIndex = bar_index + 1;
|
||||
|
||||
//
|
||||
double lastHighestHigh;
|
||||
double lastLowestLow;
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
if (ArraySize(highestHighBuffer) > lastBarIndex) {
|
||||
lastHighestHigh = highestHighBuffer[lastBarIndex];
|
||||
} else {
|
||||
lastHighestHigh = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
if (ArraySize(lowestLowBuffer) > lastBarIndex) {
|
||||
lastLowestLow = lowestLowBuffer[lastBarIndex];
|
||||
} else {
|
||||
lastLowestLow = 0;
|
||||
}
|
||||
|
||||
//
|
||||
highestHighBuffer[bar_index] = lastHighestHigh;
|
||||
lowestLowBuffer[bar_index] = lastLowestLow;
|
||||
|
||||
//
|
||||
double mid = (lastHighestHigh + lastLowestLow) / 2;
|
||||
middleBuffer[bar_index] = mid;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
@@ -0,0 +1,275 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center Trend Power Indicator
|
||||
// ---------------------------------------------
|
||||
// saherelm implementation of above indicator ...
|
||||
// this indicator uses two ma line:
|
||||
// - fast ma;
|
||||
// - slow ma;
|
||||
//
|
||||
// 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 MA Indicator"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
input int marketLength = 7; // Market Length
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
#property indicator_separate_window
|
||||
|
||||
//
|
||||
#property indicator_plots 3
|
||||
#property indicator_buffers 3
|
||||
#property indicator_minimum 0
|
||||
#property indicator_maximum 100
|
||||
|
||||
//
|
||||
#property indicator_levelcolor clrGray
|
||||
#property indicator_levelstyle STYLE_DOT
|
||||
|
||||
//
|
||||
// Start Define Indicator Buffer Styles ...
|
||||
//
|
||||
#property indicator_type1 DRAW_HISTOGRAM
|
||||
#property indicator_color1 clrLime
|
||||
#property indicator_style1 STYLE_DOT
|
||||
#property indicator_width1 1
|
||||
|
||||
//
|
||||
#property indicator_type2 DRAW_HISTOGRAM
|
||||
#property indicator_color2 clrRed
|
||||
#property indicator_style2 STYLE_DOT
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
#property indicator_type3 DRAW_LINE
|
||||
#property indicator_color3 clrYellow
|
||||
#property indicator_style3 STYLE_DOT
|
||||
#property indicator_width3 1
|
||||
//
|
||||
// End Define Indicator Buffer Styles ...
|
||||
//
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
#define powerUpBufferIndex 0
|
||||
#define powerDownBufferIndex 1
|
||||
#define signalBufferIndex 2
|
||||
|
||||
double powerUpBuffer[];
|
||||
double powerDownBuffer[];
|
||||
double signalBuffer[];
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Event Handlers ...
|
||||
//
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit() {
|
||||
//
|
||||
// Initialize what we want ...
|
||||
if (marketLength <= 0) {
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
SetLevelValue(0, 0.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||
|
||||
//
|
||||
SetLevelValue(1, 20.0);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||
|
||||
//
|
||||
SetLevelValue(2, 50);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||
|
||||
//
|
||||
SetLevelValue(3, 100);
|
||||
IndicatorSetString(INDICATOR_LEVELTEXT,3,"");
|
||||
|
||||
//
|
||||
string pUpLbl = StringConcatenate(
|
||||
"P Up (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pDownLbl = StringConcatenate(
|
||||
"P Down (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
string pSignalLbl = StringConcatenate(
|
||||
"P Signal (", marketLength, ")"
|
||||
);
|
||||
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||
|
||||
//
|
||||
// here we specify logging enabled or not ...
|
||||
enableLogging = true;
|
||||
|
||||
//
|
||||
// this is a Tag which attached to our Logger ...
|
||||
logTag = "X_TPW_OSC";
|
||||
|
||||
//
|
||||
return INIT_SUCCEEDED;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculating what we want ...
|
||||
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[]
|
||||
) {
|
||||
//
|
||||
// this counts Available Bars ...
|
||||
int limit;
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
int maxLength = MathMax(0, marketLength);
|
||||
|
||||
//
|
||||
// input variable, we return 0 means nothing passed ...
|
||||
if (rates_total < maxLength) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// found which candles calculated before ...
|
||||
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||
|
||||
//
|
||||
// this is the main loop of calculations, for each bar index ...
|
||||
for (int i = limit - 1; i >= 0; i--) {
|
||||
//
|
||||
// Start Calculation here ...
|
||||
// i is bar_index ...
|
||||
|
||||
//
|
||||
// Calculate Buffers ...
|
||||
CalculateBuffers(i);
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
//
|
||||
// Calculating Ma ...
|
||||
void CalculateBuffers(
|
||||
const int &bar_index
|
||||
) {
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
|
||||
//
|
||||
int dailyCount = GetDailyCandleCount();
|
||||
double dailyHH = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyLL = GetMarketLowestLow(
|
||||
bar_index,
|
||||
dailyCount
|
||||
);
|
||||
double dailyDiff = dailyHH - dailyLL;
|
||||
double rate = dailyDiff / 100;
|
||||
|
||||
//
|
||||
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||
//
|
||||
XOHCL c = GetCandleModel(i);
|
||||
|
||||
//
|
||||
double cRange =
|
||||
MathAbs(c.open - c.close)
|
||||
// MathAbs(c.high - c.low)
|
||||
;
|
||||
bool isBullish = c.open < c.close;
|
||||
|
||||
//
|
||||
if (isBullish) {
|
||||
powerUp += cRange;
|
||||
} else {
|
||||
powerDown += cRange;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
powerUp = powerUp / rate;
|
||||
powerDown = powerDown / rate;
|
||||
|
||||
//
|
||||
int doubleMarketLength = (marketLength * 2);
|
||||
double ema = GetMA(
|
||||
bar_index,
|
||||
doubleMarketLength,
|
||||
0,
|
||||
MODE_EMA,
|
||||
PRICE_WEIGHTED
|
||||
);
|
||||
|
||||
//
|
||||
double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100;
|
||||
|
||||
//
|
||||
double signal = (ema / 100) * rate;
|
||||
double signalAddition = MathMin(powerUp, powerDown);
|
||||
|
||||
//
|
||||
powerUpBuffer[bar_index] = powerUp;
|
||||
powerDownBuffer[bar_index] = powerDown;
|
||||
signalBuffer[bar_index] = signal + signalAddition;
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,450 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL4 Indicator 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 library ...
|
||||
#include "../Libraries/x-saherelm.lib.mq4"
|
||||
|
||||
//
|
||||
// Includes Models library ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq4"
|
||||
|
||||
//
|
||||
// START Global Requirement Functions ...
|
||||
//
|
||||
//
|
||||
// Reading specified Buffer From ADX Indicator ...
|
||||
double ReadXMABuffer(
|
||||
const int bar_index,
|
||||
const int buffer_index,
|
||||
//
|
||||
const int marketLen,
|
||||
//
|
||||
const double stp,
|
||||
const double mxm,
|
||||
//
|
||||
const int shortCycleMult,
|
||||
const int mediumCycleMult,
|
||||
const int longCycleMult
|
||||
) {
|
||||
//
|
||||
string xmaIndicatorName = "x-saherelm.x.xma";
|
||||
|
||||
//
|
||||
double result = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xmaIndicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
stp,
|
||||
mxm,
|
||||
shortCycleMult,
|
||||
mediumCycleMult,
|
||||
longCycleMult,
|
||||
MODE_SMA,
|
||||
//
|
||||
buffer_index,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading specified Buffer from XHL Indicator ...
|
||||
double ReadXHLBuffer(
|
||||
const int bar_index,
|
||||
const int buffer_index,
|
||||
//
|
||||
const int marketLen,
|
||||
//
|
||||
const int shortCycleMult,
|
||||
const int mediumCycleMult,
|
||||
const int longCycleMult
|
||||
) {
|
||||
//
|
||||
string xhlIndicatorName = "x-saherelm.x.hl";
|
||||
|
||||
//
|
||||
double result = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xhlIndicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
shortCycleMult,
|
||||
mediumCycleMult,
|
||||
longCycleMult,
|
||||
MODE_SMA,
|
||||
//
|
||||
buffer_index,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading ADX Values ...
|
||||
double ReadADX(
|
||||
const int bar_index,
|
||||
const int marketLen,
|
||||
const int mult
|
||||
) {
|
||||
//
|
||||
double result;
|
||||
|
||||
//
|
||||
int period = marketLen * mult;
|
||||
|
||||
//
|
||||
result = iADX(
|
||||
_Symbol,
|
||||
_Period,
|
||||
period,
|
||||
PRICE_CLOSE,
|
||||
MODE_MAIN,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Pivot States ...
|
||||
XPvtState GetPVTState(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XPvtState result = {};
|
||||
|
||||
//
|
||||
double hh = GetMarketHighestHigh(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double ho = GetMarketHighestOpen(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double hc = GetMarketHighestClose(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double hl = GetMarketHighestLow(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double ll = GetMarketLowestLow(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lo = GetMarketLowestOpen(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lc = GetMarketLowestClose(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
double lh = GetMarketLowestHigh(
|
||||
bar_index,
|
||||
marketLen
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Result ...
|
||||
//
|
||||
result.hh = hh;
|
||||
result.ho = ho;
|
||||
result.hc = hc;
|
||||
result.hl = hl;
|
||||
|
||||
//
|
||||
result.ll = ll;
|
||||
result.lo = lo;
|
||||
result.lc = lc;
|
||||
result.lh = lh;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate XRange from Market ...
|
||||
static XRState lastXRState;
|
||||
XRState GetXRange(
|
||||
const int bar_index,
|
||||
const int rangeMarketLength
|
||||
) {
|
||||
//
|
||||
XRState result = {};
|
||||
|
||||
//
|
||||
datetime barTime = iTime(
|
||||
_Symbol,
|
||||
_Period,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
int marketBarIndex = bar_index + rangeMarketLength;
|
||||
|
||||
//
|
||||
// Highest High ...
|
||||
//
|
||||
int hhIdx = iHighest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_HIGH,
|
||||
marketBarIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double hh = iHigh(
|
||||
_Symbol,
|
||||
_Period,
|
||||
hhIdx
|
||||
);
|
||||
|
||||
//
|
||||
// Lowest Low ...
|
||||
//
|
||||
int llIdx = iLowest(
|
||||
_Symbol,
|
||||
_Period,
|
||||
MODE_LOW,
|
||||
marketBarIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double ll = iLow(
|
||||
_Symbol,
|
||||
_Period,
|
||||
llIdx
|
||||
);
|
||||
|
||||
//
|
||||
if (lastXRState.start == 0) {
|
||||
//
|
||||
lastXRState.start = barTime;
|
||||
lastXRState.length = rangeMarketLength;
|
||||
|
||||
//
|
||||
lastXRState.hh = hh;
|
||||
lastXRState.ll = ll;
|
||||
|
||||
//
|
||||
// Middle ...
|
||||
double mid = (hh + ll) / 2;
|
||||
lastXRState.mid = mid;
|
||||
} else {
|
||||
//
|
||||
int startBarIndex = iBarShift(
|
||||
_Symbol,
|
||||
_Period,
|
||||
lastXRState.start
|
||||
);
|
||||
|
||||
//
|
||||
if (startBarIndex - bar_index >= rangeMarketLength) {
|
||||
//
|
||||
lastXRState.start = barTime;
|
||||
lastXRState.length = rangeMarketLength;
|
||||
|
||||
//
|
||||
lastXRState.hh = hh;
|
||||
lastXRState.ll = ll;
|
||||
|
||||
//
|
||||
// Middle ...
|
||||
double mid = (hh + ll) / 2;
|
||||
lastXRState.mid = mid;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = lastXRState;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading XTPowState from Indicatoe ...
|
||||
XTPOWState GetXTPowState(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XTPOWState result = {};
|
||||
|
||||
//
|
||||
//
|
||||
double powerUp = 0;
|
||||
double powerDown = 0;
|
||||
double signal = 0;
|
||||
|
||||
//
|
||||
string indicatorName = "x-saherelm.xtpow";
|
||||
|
||||
//
|
||||
int pUpIndex = 0;
|
||||
int pDownIndex = 1;
|
||||
int signalIndex = 2;
|
||||
|
||||
//
|
||||
powerUp = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
pUpIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
powerDown = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
pDownIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
signal = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
marketLen,
|
||||
//
|
||||
signalIndex,
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
result.signal = signal;
|
||||
result.powerUp = powerUp;
|
||||
result.powerDown = powerDown;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading XRState From Indicator ...
|
||||
XRState ReadXRange(
|
||||
const int bar_index,
|
||||
const int marketLen
|
||||
) {
|
||||
//
|
||||
XRState result = {};
|
||||
|
||||
//
|
||||
// Define Buffer Indexes ...
|
||||
int hhBufferIndex = 0;
|
||||
int llBufferIndex = 1;
|
||||
int midBufferIndex = 2;
|
||||
|
||||
//
|
||||
string indicatorName = "x-saherelm.xrange";
|
||||
|
||||
//
|
||||
// Read Values From XRange Indicator ...
|
||||
|
||||
//
|
||||
double hh = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
hhBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double ll = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
llBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
double mid = iCustom(
|
||||
_Symbol,
|
||||
_Period,
|
||||
indicatorName,
|
||||
//
|
||||
// Inputs ...
|
||||
marketLen,
|
||||
//
|
||||
midBufferIndex, // Buffer Index ...
|
||||
bar_index
|
||||
);
|
||||
|
||||
//
|
||||
// Filling Result ...
|
||||
result.hh = hh;
|
||||
result.ll = ll;
|
||||
result.mid = mid;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
//
|
||||
// END Indicator Reading Data ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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);
|
||||
}
|
||||
|
||||
//
|
||||
// this used for logging series ...
|
||||
void LogSeries(
|
||||
double &series[], // which series to Log ...
|
||||
int length = 0, // number of items to Log, 0 means all ...
|
||||
int skip = 0 // number of items which skip before logging ...
|
||||
) {
|
||||
//
|
||||
string msg = "";
|
||||
|
||||
//
|
||||
int seriesSize = ArraySize(series);
|
||||
if (
|
||||
skip < 0
|
||||
|| length < 0
|
||||
|| seriesSize == 0
|
||||
|| skip > seriesSize
|
||||
|| skip + length > seriesSize
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
length = length == 0 ?
|
||||
seriesSize :
|
||||
length;
|
||||
int start = skip > 1 ?
|
||||
skip - 1 :
|
||||
skip == 1 ?
|
||||
1 :
|
||||
0;
|
||||
|
||||
//
|
||||
// Loop through series items ...
|
||||
for (int i = start; i < start + length; i++) {
|
||||
//
|
||||
msg += StringConcatenate(
|
||||
"i[", i, "]: ", series[i], ", "
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
LogMessage(msg);
|
||||
}
|
||||
//
|
||||
// End Log Messages ...
|
||||
//
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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 STATIC Variables ...
|
||||
//
|
||||
//
|
||||
static int totalSignals = 0;
|
||||
static int totalLongSignals = 0;
|
||||
static int totalShortSignals = 0;
|
||||
|
||||
//
|
||||
static double initialBalance = 0;
|
||||
|
||||
//
|
||||
static int countedBars = 0;
|
||||
static bool isNewBar = false;
|
||||
static bool isNewDay = false;
|
||||
//
|
||||
// END STATIC Variables ...
|
||||
//
|
||||
|
||||
//
|
||||
// Start Models ...
|
||||
//
|
||||
//
|
||||
// Signal Providers ...
|
||||
enum ENUM_X_SIGNAL_PROVIDER {
|
||||
X_UNKNOWN_PROVIDER,
|
||||
X_XXX_PROVIDER,
|
||||
X_XR_PROVIDER,
|
||||
X_XTPW_PROVIDER
|
||||
};
|
||||
|
||||
//
|
||||
// these are different signal types ...
|
||||
enum ENUM_X_SIGNAL_TYPE {
|
||||
X_SIGNAL_NONE,
|
||||
X_SIGNAL_LONG,
|
||||
X_SIGNAL_SHORT,
|
||||
};
|
||||
|
||||
//
|
||||
// Model Market Highs and Lows ...
|
||||
struct XPvtState {
|
||||
//
|
||||
double hh;
|
||||
double ho;
|
||||
double hc;
|
||||
double hl;
|
||||
|
||||
//
|
||||
double ll;
|
||||
double lo;
|
||||
double lc;
|
||||
double lh;
|
||||
};
|
||||
|
||||
//
|
||||
// we Model each signals as this type ...
|
||||
struct XSignal {
|
||||
//
|
||||
// Signal Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Signal Type ...
|
||||
ENUM_X_SIGNAL_TYPE type;
|
||||
|
||||
//
|
||||
// Signal ID ...
|
||||
int id;
|
||||
|
||||
//
|
||||
// Signal Ticket Number, when Opening Trade ...
|
||||
int ticket;
|
||||
|
||||
//
|
||||
// Signal Provider ...
|
||||
ENUM_X_SIGNAL_PROVIDER provider;
|
||||
|
||||
//
|
||||
// Target Point ...
|
||||
double tp;
|
||||
|
||||
//
|
||||
// Stop Loss ...
|
||||
double sl;
|
||||
|
||||
//
|
||||
// Signal Entry Price ...
|
||||
double entry;
|
||||
|
||||
//
|
||||
// Signalling Time ...
|
||||
datetime time;
|
||||
|
||||
//
|
||||
// Signal Comments ...
|
||||
string comment;
|
||||
|
||||
//
|
||||
// Signal TAG ...
|
||||
string tag;
|
||||
};
|
||||
|
||||
//
|
||||
// this is Signal Request Response model ...
|
||||
struct XSignalRequest {
|
||||
bool hasSignal;
|
||||
XSignal signal;
|
||||
ENUM_X_SIGNAL_TYPE type;
|
||||
ENUM_X_SIGNAL_PROVIDER provider;
|
||||
};
|
||||
|
||||
//
|
||||
struct XRState {
|
||||
//
|
||||
datetime start;
|
||||
int length;
|
||||
|
||||
//
|
||||
double hh;
|
||||
double ll;
|
||||
double mid;
|
||||
};
|
||||
|
||||
//
|
||||
struct XTPOWState {
|
||||
//
|
||||
double powerUp;
|
||||
double powerDown;
|
||||
|
||||
//
|
||||
double signal;
|
||||
};
|
||||
//
|
||||
// End Models ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user