add new indicators ...
This commit is contained in:
@@ -74,7 +74,7 @@ ENUM_SERIESMODE ToSeriesMode(ENUM_X_SWING_TYPE value)
|
||||
int FindSwing(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Period ...
|
||||
ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ...
|
||||
ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ...
|
||||
int mLength, // Loopback ...
|
||||
int bar_index // BarIndex ...
|
||||
)
|
||||
@@ -129,7 +129,7 @@ int FindSwing(
|
||||
int FindNextSwing(
|
||||
string mSymbol, // Trading Symbol ...
|
||||
ENUM_TIMEFRAMES mPeriod, // Trading Period ...
|
||||
ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ...
|
||||
ENUM_X_SWING_TYPE mMode, // Swing Based On Price mode ...
|
||||
int mLength, // Loopback ...
|
||||
int bar_index // BarIndex ...
|
||||
)
|
||||
@@ -5697,6 +5697,216 @@ double GetFibonacciLevel(
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double MAOnArray(
|
||||
double &array[],
|
||||
int total,
|
||||
int period,
|
||||
int ma_shift,
|
||||
int ma_method,
|
||||
int shift //
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double buf[];
|
||||
double arr[];
|
||||
|
||||
//
|
||||
if (total == 0)
|
||||
{
|
||||
total = ArraySize(array);
|
||||
}
|
||||
|
||||
//
|
||||
if (total > 0 && total <= period)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (shift > total - period - ma_shift)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// MA Method ...
|
||||
switch (ma_method)
|
||||
{
|
||||
//
|
||||
// Mode SMA ...
|
||||
case MODE_SMA:
|
||||
{
|
||||
//
|
||||
total = ArrayCopy(arr, array, 0, shift + ma_shift, period);
|
||||
if (ArrayResize(buf, total) < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double sum = 0;
|
||||
int i, pos = total - 1;
|
||||
for (i = 1; i < period; i++, pos--)
|
||||
{
|
||||
sum += arr[pos];
|
||||
}
|
||||
|
||||
//
|
||||
while (pos >= 0)
|
||||
{
|
||||
//
|
||||
sum += arr[pos];
|
||||
buf[pos] = sum / period;
|
||||
sum -= arr[pos + period - 1];
|
||||
pos--;
|
||||
}
|
||||
|
||||
//
|
||||
result = buf[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Mode EMA ...
|
||||
case MODE_EMA:
|
||||
{
|
||||
//
|
||||
if (ArrayResize(buf, total) < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int pos = total - 2;
|
||||
double pr = 2.0 / (period + 1);
|
||||
|
||||
//
|
||||
while (pos >= 0)
|
||||
{
|
||||
//
|
||||
if (pos == total - 2)
|
||||
{
|
||||
buf[pos + 1] = array[pos + 1];
|
||||
}
|
||||
|
||||
//
|
||||
buf[pos] = array[pos] * pr + buf[pos + 1] * (1 - pr);
|
||||
pos--;
|
||||
}
|
||||
|
||||
//
|
||||
result = buf[shift + ma_shift];
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Mode SMMA ...
|
||||
case MODE_SMMA:
|
||||
{
|
||||
//
|
||||
if (ArrayResize(buf, total) < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int i, kk, pos;
|
||||
double sum = 0;
|
||||
pos = total - period;
|
||||
|
||||
//
|
||||
while (pos >= 0)
|
||||
{
|
||||
//
|
||||
if (pos == total - period)
|
||||
{
|
||||
//
|
||||
for (i = 0, kk = pos; i < period; i++, kk++)
|
||||
{
|
||||
//
|
||||
sum += array[kk];
|
||||
buf[kk] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sum = buf[pos + 1] * (period - 1) + array[pos];
|
||||
}
|
||||
|
||||
//
|
||||
buf[pos] = sum / period;
|
||||
pos--;
|
||||
}
|
||||
|
||||
//
|
||||
result = buf[shift + ma_shift];
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Mode LWMA ...
|
||||
case MODE_LWMA:
|
||||
{
|
||||
//
|
||||
if (ArrayResize(buf, total) < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
double price;
|
||||
double sum = 0.0, lsum = 0.0;
|
||||
int i, weight = 0, pos = total - 1;
|
||||
|
||||
//
|
||||
for (i = 1; i <= period; i++, pos--)
|
||||
{
|
||||
//
|
||||
price = array[pos];
|
||||
sum += price * i;
|
||||
lsum += price;
|
||||
weight += i;
|
||||
}
|
||||
|
||||
//
|
||||
pos++;
|
||||
i = pos + period;
|
||||
while (pos >= 0)
|
||||
{
|
||||
//
|
||||
buf[pos] = sum / weight;
|
||||
if (pos == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
i--;
|
||||
pos--;
|
||||
price = array[pos];
|
||||
sum = sum - lsum + price * period;
|
||||
lsum -= array[i];
|
||||
lsum += price;
|
||||
}
|
||||
|
||||
//
|
||||
result = buf[shift + ma_shift];
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
default:
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Method 1
|
||||
// Normalize between 1 and 0 ...
|
||||
|
||||
Reference in New Issue
Block a user