337 lines
7.4 KiB
Plaintext
337 lines
7.4 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XMA Indicator
|
|
// ---------------------------------------------
|
|
// saherelm implementation of above oscillator ...
|
|
//
|
|
// 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 XMA Indicator"
|
|
#property strict
|
|
|
|
//
|
|
// START Inputs ...
|
|
//
|
|
//
|
|
// Set the R2R Length ...
|
|
input int swingLoopback = 7; // Swing Loopback
|
|
input int xmaFlowMultiplier = 3; // XMA Flow Multiplier
|
|
input int xmaMarkMultiplier = 5; // XMA Mark Multiplier
|
|
input int xmaFastMultiplier = 7; // XMA Fast Multiplier
|
|
input int xmaSlowMultiplier = 14; // XMA Slow Multiplier
|
|
//
|
|
// END Inputs ...
|
|
//
|
|
|
|
//
|
|
// START Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
#property indicator_chart_window
|
|
|
|
//
|
|
// define indicator buffers ...
|
|
#property indicator_buffers 6
|
|
#property indicator_plots 6
|
|
|
|
//
|
|
// XMA High ...
|
|
#property indicator_label1 "XMA High"
|
|
#property indicator_type1 DRAW_LINE
|
|
#property indicator_color1 clrLime
|
|
#property indicator_style1 STYLE_SOLID
|
|
#property indicator_width1 1
|
|
|
|
//
|
|
// XMA Low ...
|
|
#property indicator_label2 "XMA Low"
|
|
#property indicator_type2 DRAW_LINE
|
|
#property indicator_color2 clrOrange
|
|
#property indicator_style2 STYLE_SOLID
|
|
#property indicator_width2 1
|
|
|
|
//
|
|
// XMA Mark ...
|
|
#property indicator_label3 "XMA Mark"
|
|
#property indicator_type3 DRAW_LINE
|
|
#property indicator_color3 clrCornflowerBlue
|
|
#property indicator_style3 STYLE_DASH
|
|
#property indicator_width3 1
|
|
|
|
//
|
|
// XMA Mid ...
|
|
#property indicator_label4 "XMA Mid"
|
|
#property indicator_type4 DRAW_LINE
|
|
#property indicator_color4 clrBisque
|
|
#property indicator_style4 STYLE_DASHDOT
|
|
#property indicator_width4 1
|
|
|
|
//
|
|
// XMA Fast ...
|
|
#property indicator_label5 "XMA Fast"
|
|
#property indicator_type5 DRAW_LINE
|
|
#property indicator_color5 clrGreen
|
|
#property indicator_style5 STYLE_DOT
|
|
#property indicator_width5 1
|
|
|
|
//
|
|
// XMA Slow ...
|
|
#property indicator_label6 "XMA Slow"
|
|
#property indicator_type6 DRAW_LINE
|
|
#property indicator_color6 clrRed
|
|
#property indicator_style6 STYLE_DOT
|
|
#property indicator_width6 1
|
|
|
|
//
|
|
// Declare Buffers ...
|
|
#define xmaHighBufferIndex 0
|
|
#define xmaLowBufferIndex 1
|
|
#define xmaMarkBufferIndex 2
|
|
#define xmaMidBufferIndex 3
|
|
#define xmaFastBufferIndex 4
|
|
#define xmaSlowBufferIndex 5
|
|
|
|
//
|
|
double xmaHighBuffer[];
|
|
double xmaLowBuffer[];
|
|
double xmaMarkBuffer[];
|
|
double xmaMidBuffer[];
|
|
double xmaFastBuffer[];
|
|
double xmaSlowBuffer[];
|
|
//
|
|
// END Global Definitions: Variables, Properties and etc ...
|
|
//
|
|
|
|
//
|
|
// Start Event Handlers ...
|
|
//
|
|
//
|
|
// Initialization ...
|
|
int OnInit() {
|
|
//
|
|
// Initialize what we want ...
|
|
|
|
|
|
//
|
|
// Validating Input Parameters ...
|
|
if (swingLoopback <= 0) {
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// XMA High ...
|
|
SetIndexBuffer(xmaHighBufferIndex, xmaHighBuffer);
|
|
SetIndexDrawBegin(xmaHighBufferIndex, swingLoopback * xmaFlowMultiplier);
|
|
|
|
//
|
|
// XMA Low ...
|
|
SetIndexBuffer(xmaLowBufferIndex, xmaLowBuffer);
|
|
SetIndexDrawBegin(xmaLowBufferIndex, swingLoopback * xmaFlowMultiplier);
|
|
|
|
//
|
|
// XMA Mark ...
|
|
SetIndexBuffer(xmaMarkBufferIndex, xmaMarkBuffer);
|
|
SetIndexDrawBegin(xmaMarkBufferIndex, swingLoopback * xmaMarkMultiplier);
|
|
|
|
//
|
|
// XMA Mid ...
|
|
SetIndexBuffer(xmaMidBufferIndex, xmaMidBuffer);
|
|
SetIndexDrawBegin(xmaMidBufferIndex, swingLoopback);
|
|
|
|
//
|
|
// XMA Fast ...
|
|
SetIndexBuffer(xmaFastBufferIndex, xmaFastBuffer);
|
|
SetIndexDrawBegin(xmaFastBufferIndex, swingLoopback * xmaFastMultiplier);
|
|
|
|
//
|
|
// XMA Slow ...
|
|
SetIndexBuffer(xmaSlowBufferIndex, xmaSlowBuffer);
|
|
SetIndexDrawBegin(xmaSlowBufferIndex, swingLoopback * xmaSlowMultiplier);
|
|
|
|
//
|
|
// initialization done ...
|
|
return(INIT_SUCCEEDED);
|
|
}
|
|
|
|
//
|
|
// Do Calculation ...
|
|
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, swingLoopback);
|
|
|
|
//
|
|
// 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 XMA Flow ...
|
|
CalculateXMAFlow(i);
|
|
|
|
//
|
|
// Calculate XMA Mark ...
|
|
CalculateXMAMark(i);
|
|
|
|
//
|
|
// Calculate XMA Mid ...
|
|
CalculateXMAMid(i);
|
|
|
|
//
|
|
// Calculate XMA Fast/Slow ...
|
|
CalculateXMAFastSlow(i);
|
|
}
|
|
|
|
//
|
|
return rates_total;
|
|
}
|
|
//
|
|
// END Event Handlers ...
|
|
//
|
|
|
|
//
|
|
// START Functions ...
|
|
//
|
|
//
|
|
// Calculate XMA Flow ...
|
|
void CalculateXMAFlow(const int &bar_index) {
|
|
//
|
|
int xmaFlowLength = swingLoopback * xmaFlowMultiplier;
|
|
|
|
//
|
|
// Calculating XMa High ...
|
|
double xmaHigh = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
xmaFlowLength,
|
|
0,
|
|
MODE_SMA,
|
|
PRICE_HIGH,
|
|
bar_index
|
|
);
|
|
xmaHighBuffer[bar_index] = xmaHigh;
|
|
|
|
//
|
|
// Calculating XMa Low ...
|
|
double xmaLow = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
xmaFlowLength,
|
|
0,
|
|
MODE_SMA,
|
|
PRICE_LOW,
|
|
bar_index
|
|
);
|
|
xmaLowBuffer[bar_index] = xmaLow;
|
|
}
|
|
|
|
//
|
|
// Calculate XMA Mark ...
|
|
void CalculateXMAMark(const int &bar_index) {
|
|
//
|
|
int xmaMarkLength = swingLoopback * xmaMarkMultiplier;
|
|
|
|
//
|
|
// Calculating XMa Mark ...
|
|
double xmaMark = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
xmaMarkLength,
|
|
0,
|
|
MODE_SMA,
|
|
PRICE_HIGH,
|
|
bar_index
|
|
);
|
|
xmaMarkBuffer[bar_index] = xmaMark;
|
|
}
|
|
|
|
//
|
|
// Calculate XMA Mid ...
|
|
void CalculateXMAMid(const int &bar_index) {
|
|
//
|
|
// Calculating XMa Mid ...
|
|
double xmaMid = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
swingLoopback,
|
|
0,
|
|
MODE_EMA,
|
|
PRICE_HIGH,
|
|
bar_index
|
|
);
|
|
xmaMidBuffer[bar_index] = xmaMid;
|
|
}
|
|
|
|
//
|
|
// Calculate XMA Fast/Slow ...
|
|
void CalculateXMAFastSlow(const int &bar_index) {
|
|
//
|
|
int xmaFastLength = swingLoopback * xmaFastMultiplier;
|
|
int xmaSlowLength = swingLoopback * xmaSlowMultiplier;
|
|
|
|
//
|
|
// Calculating XMa Fast ...
|
|
double xmaFast = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
xmaFastLength,
|
|
0,
|
|
MODE_SMA,
|
|
PRICE_CLOSE,
|
|
bar_index
|
|
);
|
|
xmaFastBuffer[bar_index] = xmaFast;
|
|
|
|
//
|
|
// Calculating XMa Slow ...
|
|
double xmaSlow = iMA(
|
|
_Symbol,
|
|
_Period,
|
|
xmaSlowLength,
|
|
0,
|
|
MODE_SMA,
|
|
PRICE_CLOSE,
|
|
bar_index
|
|
);
|
|
xmaSlowBuffer[bar_index] = xmaSlow;
|
|
}
|
|
//
|
|
// END Functions ...
|
|
// |