Indicator based on other indicator and closing price, not sure how...

 

Hey everyone, I'm currently writing code for an indicator that uses the price[i] version of OnCalculate instead of open[i],high[i],low[i],close[i] version because that's the simplest way I found, so far, to be able to choose to apply the indicator to another indicator if I want, using the parameters tab in the indicator settings. But I just realized that when I apply it to another indicator's buffer, and can no longer use price[i] to access the array of actual prices, which is something I need to do with this indicator. So I'm screwed in a way because now I think switching to the price[i] version of OnCalculate may have been useless afterall. I'm wondering what you think is the best solution for something like this... I'm a bit new to writing indicators and I want to do it the right way so if any of you have any advice, I would really appreciate it.

Applying One Indicator to Another
Applying One Indicator to Another
  • www.mql5.com
When writing an indicator that uses the short form of the OnCalculate() function call, you might miss the fact that an indicator can be calculated not only by price data, but also by data of some other indicator (no matter whether it is a built-in or custom one). Do you want to improve an indicator for its correct application to the other indicator's data? In this article we'll review all the steps required for such modification.
 
Jeepack: I'm currently writing code for an indicator that uses the price[i] version of OnCalculate instead of open[i],high[i],low[i],close[i] version because that's the simplest way I found, so far, to be able to choose to apply the indicator to another indicator if I want, using the parameters tab in the indicator settings. But I just realized that when I apply it to another indicator's buffer, and can no longer use price[i] to access the array of actual prices, which is something I need to do with this indicator. So I'm screwed in a way because now I think switching to the price[i] version of OnCalculate may have been useless afterall. I'm wondering what you think is the best solution for something like this... I'm a bit new to writing indicators and I want to do it the right way so if any of you have any advice, I would really appreciate it.

When using the "price[]" variante of OnCalculate(), you can access OHLC bar data, via the normal methods described in Access to Timeseries and Indicator Data. You just have to make sure that your indexing method is properly aligned and synchronised.

Function

Action

Bars

Returns the number of bars count in the history for a specified symbol and period

CopyRates

Gets history data of the Rates structure for a specified symbol and period into an array

CopyTime

Gets history data on bar opening time for a specified symbol and period into an array

CopyOpen

Gets history data on bar opening price for a specified symbol and period into an array

CopyHigh

Gets history data on maximal bar price for a specified symbol and period into an array

CopyLow

Gets history data on minimal bar price for a specified symbol and period into an array

CopyClose

Gets history data on bar closing price for a specified symbol and period into an array

CopyTickVolume

Gets history data on tick volumes for a specified symbol and period into an array

CopyRealVolume

Gets history data on trade volumes for a specified symbol and period into an array

CopySpread

Gets history data on spreads for a specified symbol and period into an array

iBars

Returns the number of bars of a corresponding symbol and period, available in history

iBarShift

Returns the index of the bar corresponding to the specified time

iClose

Returns the Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iHigh

Returns the High price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iLow

Returns the Low price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iOpen

Returns the Open price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iTime

Returns the opening time of the bar (indicated by the 'shift' parameter) on the corresponding chart

iTickVolume

Returns the tick volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iRealVolume

Returns the real volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iVolume

Returns the tick volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iSpread

Returns the spread value of the bar (indicated by the 'shift' parameter) on the corresponding chart

Documentation on MQL5: Timeseries and Indicators Access
Documentation on MQL5: Timeseries and Indicators Access
  • www.mql5.com
Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

When using the "price[]" variante of OnCalculate(), you can access OHLC bar data, via the normal methods described in Access to Timeseries and Indicator Data. You just have to make sure that your indexing method is properly aligned and synchronised.

Function

Action

Bars

Returns the number of bars count in the history for a specified symbol and period

CopyRates

Gets history data of the Rates structure for a specified symbol and period into an array

CopyTime

Gets history data on bar opening time for a specified symbol and period into an array

CopyOpen

Gets history data on bar opening price for a specified symbol and period into an array

CopyHigh

Gets history data on maximal bar price for a specified symbol and period into an array

CopyLow

Gets history data on minimal bar price for a specified symbol and period into an array

CopyClose

Gets history data on bar closing price for a specified symbol and period into an array

CopyTickVolume

Gets history data on tick volumes for a specified symbol and period into an array

CopyRealVolume

Gets history data on trade volumes for a specified symbol and period into an array

CopySpread

Gets history data on spreads for a specified symbol and period into an array

iBars

Returns the number of bars of a corresponding symbol and period, available in history

iBarShift

Returns the index of the bar corresponding to the specified time

iClose

Returns the Close price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iHigh

Returns the High price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iLow

Returns the Low price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iOpen

Returns the Open price of the bar (indicated by the 'shift' parameter) on the corresponding chart

iTime

Returns the opening time of the bar (indicated by the 'shift' parameter) on the corresponding chart

iTickVolume

Returns the tick volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iRealVolume

Returns the real volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iVolume

Returns the tick volume of the bar (indicated by the 'shift' parameter) on the corresponding chart

iSpread

Returns the spread value of the bar (indicated by the 'shift' parameter) on the corresponding chart

Perfect, thanks!