Skip to content

Commit

Permalink
Indicators: Fixes potential issues with OnIndicator mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kenorb committed Aug 5, 2022
1 parent de63053 commit a7669c8
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Indicators/Indi_AMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ class Indi_AMA : public Indicator<IndiAMAParams> {

break;
case IDATA_ONCALCULATE:
_value = Indi_AMA::iAMAOnIndicator(THIS_PTR, /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(), GetAMAShift(),
GetAppliedPrice() /*]*/, _mode, _ishift);
_value = Indi_AMA::iAMAOnIndicator(GetDataSource(), /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(),
GetAMAShift(), GetAppliedPrice() /*]*/, _mode, _ishift);
break;
case IDATA_INDICATOR:
_value = Indi_AMA::iAMAOnIndicator(THIS_PTR, /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(), GetAMAShift(),
GetAppliedPrice() /*]*/, _mode, _ishift);
_value = Indi_AMA::iAMAOnIndicator(GetDataSource(), /*[*/ GetPeriod(), GetFastPeriod(), GetSlowPeriod(),
GetAMAShift(), GetAppliedPrice() /*]*/, _mode, _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down
6 changes: 4 additions & 2 deletions Indicators/Indi_CCI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class Indi_CCI : public Indicator<IndiCCIParams> {
break;
case IDATA_ONCALCULATE:
// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value = Indi_CCI::iCCIOnIndicator(THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), _ishift /* + iparams.shift*/);
_value =
Indi_CCI::iCCIOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), _ishift /* + iparams.shift*/);
break;
case IDATA_ICUSTOM:
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.custom_indi_name, /* [ */ GetPeriod(),
Expand All @@ -178,7 +179,8 @@ class Indi_CCI : public Indicator<IndiCCIParams> {
ValidateSelectedDataSource();

// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value = Indi_CCI::iCCIOnIndicator(THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), _ishift /* + iparams.shift*/);
_value =
Indi_CCI::iCCIOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(), _ishift /* + iparams.shift*/);
break;
}
return _value;
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_CHO.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class Indi_CHO : public Indicator<IndiCHOParams> {
GetSlowMA(), GetSmoothMethod(), GetInputVolume() /*]*/, 0, _ishift);
break;
case IDATA_INDICATOR:
_value = Indi_CHO::iChaikinOnIndicator(THIS_PTR, /*[*/ GetFastMA(), GetSlowMA(), GetSmoothMethod(),
_value = Indi_CHO::iChaikinOnIndicator(GetDataSource(), /*[*/ GetFastMA(), GetSlowMA(), GetSmoothMethod(),
GetInputVolume() /*]*/, _mode, _ishift);
break;
default:
Expand Down
12 changes: 6 additions & 6 deletions Indicators/Indi_DEMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Indi_DEMA : public Indicator<IndiDEMAParams> {
*/
static double iDEMA(string _symbol, ENUM_TIMEFRAMES _tf, unsigned int _period, unsigned int _ma_shift,
ENUM_APPLIED_PRICE _applied_price, int _shift = 0, int _mode = 0, IndicatorBase *_obj = NULL) {
#ifdef __MQL5__XX
#ifdef __MQL5__
int _handle = Object::IsValid(_obj) ? _obj.Get<int>(IndicatorState::INDICATOR_STATE_PROP_HANDLE) : NULL;
double _res[];
if (_handle == NULL || _handle == INVALID_HANDLE) {
Expand All @@ -117,7 +117,6 @@ class Indi_DEMA : public Indicator<IndiDEMAParams> {
}
return _res[0];
#else

if (_obj == nullptr) {
Print(
"Indi_DEMA::iDEMA() can work without supplying pointer to IndicatorBase only in MQL5. In this platform the "
Expand All @@ -127,6 +126,7 @@ class Indi_DEMA : public Indicator<IndiDEMAParams> {
}

return iDEMAOnIndicator(_obj, _period, _ma_shift, _applied_price, _mode, _shift);
#endif
}

static double iDEMAOnArray(INDICATOR_CALCULATE_PARAMS_SHORT, unsigned int _ma_period, unsigned int _ma_shift,
Expand Down Expand Up @@ -204,8 +204,8 @@ class Indi_DEMA : public Indicator<IndiDEMAParams> {
_ishift, _mode, THIS_PTR);
break;
case IDATA_ONCALCULATE:
_value = Indi_DEMA::iDEMAOnIndicator(THIS_PTR, /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/, _mode,
_ishift);
_value = Indi_DEMA::iDEMAOnIndicator(GetDataSource(), /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/,
_mode, _ishift);
break;
case IDATA_ICUSTOM:
istate.handle = istate.is_changed ? INVALID_HANDLE : istate.handle;
Expand All @@ -214,8 +214,8 @@ class Indi_DEMA : public Indicator<IndiDEMAParams> {
break;
case IDATA_INDICATOR:
// Calculating DEMA value from specified indicator.
_value = Indi_DEMA::iDEMAOnIndicator(THIS_PTR, /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/, _mode,
_ishift);
_value = Indi_DEMA::iDEMAOnIndicator(GetDataSource(), /*[*/ GetPeriod(), GetMAShift(), GetAppliedPrice() /*]*/,
_mode, _ishift);
break;
}
return _value;
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_Drawer.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Indi_Drawer : public Indicator<IndiDrawerParams> {
_value = Indi_Drawer::iDrawer(GetSymbol(), GetTf(), _ishift, THIS_PTR);
break;
case IDATA_INDICATOR:
_value = Indi_Drawer::iDrawerOnIndicator(THIS_PTR, THIS_PTR, GetSymbol(), GetTf(), _ishift);
_value = Indi_Drawer::iDrawerOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_FractalAdaptiveMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ class Indi_FrAMA : public Indicator<IndiFrAIndiMAParams> {
iFrAMA(GetSymbol(), GetTf(), GetPeriod(), GetFRAMAShift(), GetAppliedPrice(), _mode, _ishift, THIS_PTR);
break;
case IDATA_ONCALCULATE:
_value = iFrAMAOnIndicator(THIS_PTR, GetPeriod(), GetFRAMAShift(), GetAppliedPrice(), _mode, _ishift);
_value = iFrAMAOnIndicator(GetDataSource(), GetPeriod(), GetFRAMAShift(), GetAppliedPrice(), _mode, _ishift);
break;
case IDATA_ICUSTOM:
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(),
GetFRAMAShift() /*]*/, 0, _ishift);
break;
case IDATA_INDICATOR:
_value = iFrAMAOnIndicator(THIS_PTR, GetPeriod(), GetFRAMAShift(), GetAppliedPrice(), _mode, _ishift);
_value = iFrAMAOnIndicator(GetDataSource(), GetPeriod(), GetFRAMAShift(), GetAppliedPrice(), _mode, _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down
8 changes: 4 additions & 4 deletions Indicators/Indi_Momentum.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
break;
case IDATA_ONCALCULATE:
// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value =
Indi_Momentum::iMomentumOnIndicator(THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), iparams.shift + _shift);
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + _shift);
if (iparams.is_draw) {
draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + _shift), _value, 1);
}
Expand All @@ -177,8 +177,8 @@ class Indi_Momentum : public Indicator<IndiMomentumParams> {
ValidateSelectedDataSource();

// @fixit Somehow shift isn't used neither in MT4 nor MT5.
_value =
Indi_Momentum::iMomentumOnIndicator(THIS_PTR, GetSymbol(), GetTf(), GetPeriod(), iparams.shift + _shift);
_value = Indi_Momentum::iMomentumOnIndicator(GetDataSource(), GetSymbol(), GetTf(), GetPeriod(),
iparams.shift + _shift);
if (iparams.is_draw) {
draw.DrawLineTo(StringFormat("%s", GetName()), GetBarTime(iparams.shift + _shift), _value, 1);
}
Expand Down
2 changes: 1 addition & 1 deletion Indicators/Indi_RSI.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class Indi_RSI : public Indicator<IndiRSIParams> {
Print(_value);
break;
case IDATA_INDICATOR:
_value = Indi_RSI::iRSIOnIndicator(THIS_PTR, THIS_PTR, GetSymbol(), GetTf(), iparams.GetPeriod(),
_value = Indi_RSI::iRSIOnIndicator(GetDataSource(), THIS_PTR, GetSymbol(), GetTf(), iparams.GetPeriod(),
iparams.GetAppliedPrice(), _ishift);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_TEMA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ class Indi_TEMA : public Indicator<IndiTEMAParams> {
THIS_PTR);
break;
case IDATA_ONCALCULATE:
_value = iTEMAOnIndicator(THIS_PTR, GetPeriod(), GetTEMAShift(), GetAppliedPrice(), _mode, _ishift);
_value = iTEMAOnIndicator(GetDataSource(), GetPeriod(), GetTEMAShift(), GetAppliedPrice(), _mode, _ishift);
case IDATA_ICUSTOM:
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod(),
GetTEMAShift() /*]*/, 0, _ishift);
break;
case IDATA_INDICATOR:
_value = iTEMAOnIndicator(THIS_PTR, GetPeriod(), GetTEMAShift(), GetAppliedPrice(), _mode, _ishift);
_value = iTEMAOnIndicator(GetDataSource(), GetPeriod(), GetTEMAShift(), GetAppliedPrice(), _mode, _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down
4 changes: 2 additions & 2 deletions Indicators/Indi_TRIX.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ class Indi_TRIX : public Indicator<IndiTRIXParams> {
THIS_PTR);
break;
case IDATA_ONCALCULATE:
_value = Indi_TRIX::iTriXOnIndicator(THIS_PTR, GetPeriod(), GetAppliedPrice(), _mode, _ishift);
_value = Indi_TRIX::iTriXOnIndicator(GetDataSource(), GetPeriod(), GetAppliedPrice(), _mode, _ishift);
break;
case IDATA_ICUSTOM:
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/ GetPeriod() /*]*/,
0, _ishift);
break;
case IDATA_INDICATOR:
_value = Indi_TRIX::iTriXOnIndicator(THIS_PTR, GetPeriod(), GetAppliedPrice(), _mode, _ishift);
_value = Indi_TRIX::iTriXOnIndicator(GetDataSource(), GetPeriod(), GetAppliedPrice(), _mode, _ishift);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down
10 changes: 6 additions & 4 deletions Indicators/Indi_VIDYA.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ class Indi_VIDYA : public Indicator<IndiVIDYAParams> {
GetAppliedPrice() /*]*/, 0, _ishift, THIS_PTR);
break;
case IDATA_ONCALCULATE:
_value = Indi_VIDYA::iVIDyAOnIndicator(THIS_PTR, GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(),
GetVIDYAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR);
_value =
Indi_VIDYA::iVIDyAOnIndicator(GetDataSource(), GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(),
GetVIDYAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR);
break;
case IDATA_ICUSTOM:
_value = iCustom(istate.handle, GetSymbol(), GetTf(), iparams.GetCustomIndicatorName(), /*[*/
Expand All @@ -192,8 +193,9 @@ class Indi_VIDYA : public Indicator<IndiVIDYAParams> {
0, _ishift);
break;
case IDATA_INDICATOR:
_value = Indi_VIDYA::iVIDyAOnIndicator(THIS_PTR, GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(),
GetVIDYAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR);
_value =
Indi_VIDYA::iVIDyAOnIndicator(GetDataSource(), GetSymbol(), GetTf(), /*[*/ GetCMOPeriod(), GetMAPeriod(),
GetVIDYAShift(), GetAppliedPrice() /*]*/, _mode, _ishift, THIS_PTR);
break;
default:
SetUserError(ERR_INVALID_PARAMETER);
Expand Down

0 comments on commit a7669c8

Please sign in to comment.