Skip to content

Commit

Permalink
Indicators: Renames some variables to avoid global variable conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Jun 24, 2023
1 parent c48da70 commit 1b5830f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
22 changes: 11 additions & 11 deletions Indicators/Indi_AMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class Indi_AMA : public Indicator<IndiAMAParams> {
/**
* OnInit() method for AMA indicator.
*/
static void CalculateInit(int InpPeriodAMA, int InpFastPeriodEMA, int InpSlowPeriodEMA, int InpShiftAMA,
static void CalculateInit(int InpPeriodAMA, int _period_fast_ema, int _period_slow_ema, int _ishift_ama,
double &ExtFastSC, double &ExtSlowSC, int &ExtPeriodAMA, int &ExtSlowPeriodEMA,
int &ExtFastPeriodEMA) {
// Check for input values.
Expand All @@ -156,20 +156,20 @@ class Indi_AMA : public Indicator<IndiAMAParams> {
InpPeriodAMA, ExtPeriodAMA);
} else
ExtPeriodAMA = InpPeriodAMA;
if (InpSlowPeriodEMA <= 0) {
if (_period_slow_ema <= 0) {
ExtSlowPeriodEMA = 30;
PrintFormat(
"Input parameter InpSlowPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
InpSlowPeriodEMA, ExtSlowPeriodEMA);
"Input parameter _period_slow_ema has incorrect value (%d). Indicator will use value %d for calculations.",
_period_slow_ema, ExtSlowPeriodEMA);
} else
ExtSlowPeriodEMA = InpSlowPeriodEMA;
if (InpFastPeriodEMA <= 0) {
ExtSlowPeriodEMA = _period_slow_ema;
if (_period_fast_ema <= 0) {
ExtFastPeriodEMA = 2;
PrintFormat(
"Input parameter InpFastPeriodEMA has incorrect value (%d). Indicator will use value %d for calculations.",
InpFastPeriodEMA, ExtFastPeriodEMA);
"Input parameter _period_fast_ema has incorrect value (%d). Indicator will use value %d for calculations.",
_period_fast_ema, ExtFastPeriodEMA);
} else
ExtFastPeriodEMA = InpFastPeriodEMA;
ExtFastPeriodEMA = _period_fast_ema;

// Calculate ExtFastSC & ExtSlowSC.
ExtFastSC = 2.0 / (ExtFastPeriodEMA + 1.0);
Expand All @@ -180,14 +180,14 @@ class Indi_AMA : public Indicator<IndiAMAParams> {
* OnCalculate() method for AMA indicator.
*/
static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_SHORT, ValueStorage<double> &ExtAMABuffer, int InpPeriodAMA,
int InpFastPeriodEMA, int InpSlowPeriodEMA, int InpShiftAMA) {
int _period_fast_ema, int _period_slow_ema, int _ishift_ama) {
double ExtFastSC;
double ExtSlowSC;
int ExtPeriodAMA;
int ExtSlowPeriodEMA;
int ExtFastPeriodEMA;

CalculateInit(InpPeriodAMA, InpFastPeriodEMA, InpSlowPeriodEMA, InpShiftAMA, ExtFastSC, ExtSlowSC, ExtPeriodAMA,
CalculateInit(InpPeriodAMA, _period_fast_ema, _period_slow_ema, _ishift_ama, ExtFastSC, ExtSlowSC, ExtPeriodAMA,
ExtSlowPeriodEMA, ExtFastPeriodEMA);
int i;
// Check for rates count.
Expand Down
6 changes: 3 additions & 3 deletions Indicators/Indi_FractalAdaptiveMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ class Indi_FrAMA : public Indicator<IndiFrAIndiMAParams> {
}

static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_LONG, ValueStorage<double> &FrAmaBuffer, int InpPeriodFrAMA,
int InpShift, ENUM_APPLIED_PRICE InpAppliedPrice) {
int _ishift, ENUM_APPLIED_PRICE _applied_price) {
if (rates_total < 2 * InpPeriodFrAMA) return (0);

int start, i;
// Start calculations.
if (prev_calculated == 0) {
start = 2 * InpPeriodFrAMA - 1;
for (i = 0; i <= start; i++)
FrAmaBuffer[i] = AppliedPriceValueStorage::GetApplied(open, high, low, close, i, InpAppliedPrice);
FrAmaBuffer[i] = AppliedPriceValueStorage::GetApplied(open, high, low, close, i, _applied_price);
} else
start = prev_calculated - 1;

Expand All @@ -170,7 +170,7 @@ class Indi_FrAMA : public Indicator<IndiFrAIndiMAParams> {
double n3 = (hi3 - lo3) / (2 * InpPeriodFrAMA);
double d = (MathLog(n1 + n2) - MathLog(n3)) / math_log_2;
double alfa = MathExp(-4.6 * (d - 1.0));
double _iprice = AppliedPriceValueStorage::GetApplied(open, high, low, close, i, InpAppliedPrice);
double _iprice = AppliedPriceValueStorage::GetApplied(open, high, low, close, i, _applied_price);

FrAmaBuffer[i] = alfa * _iprice + (1 - alfa) * FrAmaBuffer[i - 1].Get();
}
Expand Down
44 changes: 22 additions & 22 deletions Indicators/Indi_MA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -267,53 +267,53 @@ class Indi_MA : public Indicator<IndiMAParams> {
* Calculates Simple Moving Average (SMA). The same as in "Example Moving Average" indicator.
*/
static void CalculateSimpleMA(int rates_total, int prev_calculated, int begin, ValueStorage<double> &price,
ValueStorage<double> &ExtLineBuffer, int _ma_period) {
ValueStorage<double> &_line_buff, int _ma_period) {
int i, start;
// First calculation or number of bars was changed.
if (prev_calculated == 0) {
start = _ma_period + begin;
// Set empty value for first start bars.
for (i = 0; i < start - 1; i++) ExtLineBuffer[i] = 0.0;
for (i = 0; i < start - 1; i++) _line_buff[i] = 0.0;
// Calculate first visible value.
double first_value = 0;
for (i = begin; i < start; i++) first_value += price[i].Get();
first_value /= _ma_period;
ExtLineBuffer[start - 1] = first_value;
_line_buff[start - 1] = first_value;
} else
start = prev_calculated - 1;
// Main loop.
for (i = start; i < rates_total && !IsStopped(); i++) {
ExtLineBuffer[i] = ExtLineBuffer[i - 1] + (price[i] - price[i - _ma_period]) / _ma_period;
_line_buff[i] = _line_buff[i - 1] + (price[i] - price[i - _ma_period]) / _ma_period;
}
}

/**
* Calculates Exponential Moving Average (EMA). The same as in "Example Moving Average" indicator.
*/
static void CalculateEMA(int rates_total, int prev_calculated, int begin, ValueStorage<double> &price,
ValueStorage<double> &ExtLineBuffer, int _ma_period) {
ValueStorage<double> &_line_buff, int _ma_period) {
int i, limit;
double SmoothFactor = 2.0 / (1.0 + _ma_period);
// First calculation or number of bars was changed.
if (prev_calculated == 0) {
limit = _ma_period + begin;
ExtLineBuffer[begin] = price[begin];
_line_buff[begin] = price[begin];
for (i = begin + 1; i < limit; i++) {
ExtLineBuffer[i] = price[i] * SmoothFactor + ExtLineBuffer[i - 1] * (1.0 - SmoothFactor);
_line_buff[i] = price[i] * SmoothFactor + _line_buff[i - 1] * (1.0 - SmoothFactor);
}
} else
limit = prev_calculated - 1;
// Main loop.
for (i = limit; i < rates_total && !IsStopped(); i++) {
ExtLineBuffer[i] = price[i] * SmoothFactor + ExtLineBuffer[i - 1] * (1.0 - SmoothFactor);
_line_buff[i] = price[i] * SmoothFactor + _line_buff[i - 1] * (1.0 - SmoothFactor);
}
}

/**
* Calculates Linearly Weighted Moving Average (LWMA). The same as in "Example Moving Average" indicator.
*/
static void CalculateLWMA(int rates_total, int prev_calculated, int begin, ValueStorage<double> &price,
ValueStorage<double> &ExtLineBuffer, int _ma_period) {
ValueStorage<double> &_line_buff, int _ma_period) {
int i, limit;
static int weightsum;
double sum;
Expand All @@ -322,7 +322,7 @@ class Indi_MA : public Indicator<IndiMAParams> {
weightsum = 0;
limit = _ma_period + begin;
// Set empty value for first limit bars.
for (i = 0; i < limit; i++) ExtLineBuffer[i] = 0.0;
for (i = 0; i < limit; i++) _line_buff[i] = 0.0;
// Calculate first visible value.
double firstValue = 0;
for (i = begin; i < limit; i++) {
Expand All @@ -331,14 +331,14 @@ class Indi_MA : public Indicator<IndiMAParams> {
firstValue += k * price[i].Get();
}
firstValue /= (double)weightsum;
ExtLineBuffer[limit - 1] = firstValue;
_line_buff[limit - 1] = firstValue;
} else
limit = prev_calculated - 1;
// Main loop.
for (i = limit; i < rates_total && !IsStopped(); i++) {
sum = 0;
for (int j = 0; j < _ma_period; j++) sum += (_ma_period - j) * price[i - j].Get();
ExtLineBuffer[i] = sum / weightsum;
_line_buff[i] = sum / weightsum;
}
//---
}
Expand All @@ -347,23 +347,23 @@ class Indi_MA : public Indicator<IndiMAParams> {
* Calculates Smoothed Moving Average (SMMA). The same as in "Example Moving Average" indicator.
*/
static void CalculateSmoothedMA(int rates_total, int prev_calculated, int begin, ValueStorage<double> &price,
ValueStorage<double> &ExtLineBuffer, int _ma_period) {
ValueStorage<double> &_line_buff, int _ma_period) {
int i, limit;
// First calculation or number of bars was changed.
if (prev_calculated == 0) {
limit = _ma_period + begin;
// Set empty value for first limit bars.
for (i = 0; i < limit - 1; i++) ExtLineBuffer[i] = 0.0;
for (i = 0; i < limit - 1; i++) _line_buff[i] = 0.0;
// Calculate first visible value.
double firstValue = 0;
for (i = begin; i < limit; i++) firstValue += price[i].Get();
firstValue /= _ma_period;
ExtLineBuffer[limit - 1] = firstValue;
_line_buff[limit - 1] = firstValue;
} else
limit = prev_calculated - 1;
// Main loop.
for (i = limit; i < rates_total && !IsStopped(); i++)
ExtLineBuffer[i] = (ExtLineBuffer[i - 1] * (_ma_period - 1) + price[i].Get()) / _ma_period;
_line_buff[i] = (_line_buff[i - 1] * (_ma_period - 1) + price[i].Get()) / _ma_period;
//---
}

Expand Down Expand Up @@ -582,30 +582,30 @@ class Indi_MA : public Indicator<IndiMAParams> {
* Calculates Moving Average. The same as in "Example Moving Average" indicator.
*/
static int Calculate(const int rates_total, const int prev_calculated, const int begin, ValueStorage<double> &price,
ValueStorage<double> &ExtLineBuffer, int _ma_method, int _ma_period) {
ValueStorage<double> &_line_buff, int _ma_method, int _ma_period) {
// Check for bars count.
if (rates_total < _ma_period - 1 + begin) {
// Not enough bars for calculation.
return (0);
}
if (prev_calculated == 0) {
// First calculation or number of bars was changed.
ArrayInitialize(ExtLineBuffer, (double)0);
ArrayInitialize(_line_buff, (double)0);
}

// Calculation.
switch (_ma_method) {
case MODE_EMA:
CalculateEMA(rates_total, prev_calculated, begin, price, ExtLineBuffer, _ma_period);
CalculateEMA(rates_total, prev_calculated, begin, price, _line_buff, _ma_period);
break;
case MODE_LWMA:
CalculateLWMA(rates_total, prev_calculated, begin, price, ExtLineBuffer, _ma_period);
CalculateLWMA(rates_total, prev_calculated, begin, price, _line_buff, _ma_period);
break;
case MODE_SMMA:
CalculateSmoothedMA(rates_total, prev_calculated, begin, price, ExtLineBuffer, _ma_period);
CalculateSmoothedMA(rates_total, prev_calculated, begin, price, _line_buff, _ma_period);
break;
case MODE_SMA:
CalculateSimpleMA(rates_total, prev_calculated, begin, price, ExtLineBuffer, _ma_period);
CalculateSimpleMA(rates_total, prev_calculated, begin, price, _line_buff, _ma_period);
break;
}
// Return value of prev_calculated for next call.
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_TEMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ class Indi_TEMA : public Indicator<IndiTEMAParams> {
/**
* OnCalculate() method for TEMA indicator.
*
* Note that InpShift is used for drawing only and thus is unused.
* Note that _ishift is used for drawing only and thus is unused.
*/
static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_SHORT, ValueStorage<double> &TemaBuffer,
ValueStorage<double> &Ema, ValueStorage<double> &EmaOfEma, ValueStorage<double> &EmaOfEmaOfEma,
int InpPeriodEMA, int InpShift) {
int InpPeriodEMA, int _ishift) {
if (rates_total < 3 * InpPeriodEMA - 3) return (0);
//---
int start;
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_VIDYA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ class Indi_VIDYA : public Indicator<IndiVIDYAParams> {
/**
* OnCalculate() method for VIDyA indicator.
*
* Note that InpShift is used for drawing only and thus is unused.
* Note that _ishift is used for drawing only and thus is unused.
*/
static int Calculate(INDICATOR_CALCULATE_METHOD_PARAMS_SHORT, ValueStorage<double> &VIDYA_Buffer, int InpPeriodCMO,
int InpPeriodEMA, int InpShift) {
int InpPeriodEMA, int _ishift) {
double ExtF = 2.0 / (1.0 + InpPeriodEMA);

if (rates_total < InpPeriodEMA + InpPeriodCMO - 1) return (0);
Expand Down

0 comments on commit 1b5830f

Please sign in to comment.