Develop function iRSI multitimeframes

23

Hi everybody,

I try to develop in MQL5 a function multi iRSI, i wish send in a parameter the TimeFrame for calculate and this return the value. I have this example but i need write a function for each timeframe, it's not practique. How i develop just a function multi time frames?

Thanks :)

```double CalculateRSIByPeriod_M1(int CalculateRSIAveragePeriod = 14)
{
double myRSIArray[];
ArraySetAsSeries(myRSIArray, true);
int myRSIDefinition = iRSI(_Symbol, PERIOD_M1, CalculateRSIAveragePeriod, PRICE_CLOSE);
CopyBuffer(myRSIDefinition, 0, 1, 3, myRSIArray);
double myRSIValue = NormalizeDouble(myRSIArray[0],2);
return  myRSIValue;
}

double CalculateRSIByPeriod_M5(int CalculateRSIAveragePeriod = 14)
{
double myRSIArray[];
ArraySetAsSeries(myRSIArray, true);
int myRSIDefinition = iRSI(_Symbol, PERIOD_M5, CalculateRSIAveragePeriod, PRICE_CLOSE);
CopyBuffer(myRSIDefinition, 0, 1, 3, myRSIArray);
double myRSIValue = NormalizeDouble(myRSIArray[0],2);
return  myRSIValue;
}
```
23

If somebody need the code is this:

```input ENUM_TIMEFRAMES RSI_TimeFrame             = PERIOD_M15; // TimeFrame for RSI

double CalculateRSIByPeriod(ENUM_TIMEFRAMES Period_ = PERIOD_CURRENT, int CalculateRSIAveragePeriod = 14)
{
double      myRSIArray[];
ArraySetAsSeries(myRSIArray, true);
int         myRSIDefinition      = iRSI(_Symbol, Period_, CalculateRSIAveragePeriod, PRICE_CLOSE);
CopyBuffer(myRSIDefinition, 0, 1, 3, myRSIArray);
double      myRSIValue           = NormalizeDouble(myRSIArray[0],2);
return      myRSIValue;
}

double RSIValue               = CalculateRSIByPeriod(RSI_TimeFrame, RSI_Period);```
Moderator
208129

In MQL5, the indicator handle MUST BE CREATED ONCE - IN OnInit ().

You create indicator handles haphazardly and repeatedly. It is unacceptable. This is a gross mistake.

You need to do this: determine the parameters and timeframes of the RSI indicators - and create all indicators in OnInit. And only then, in your custom function, use CopyBuffer .

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
• www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
Moderator
208129