Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Cycle - MetaTrader 5 Script | Forex Indicator Download - MT4/MT5 Resources - MetaTrader 5 Resources

author EAcpu | 5 reads | 0 comments |

Cycle Period - indicator for MetaTrader 5

Cycle Period - indicator for MetaTrader 5

This indicator is designed to measure the price change cycle of financial assets.

This indicator stores the current market cycle value in its indicator buffer, which can never stabilize for obvious reasons. The indicator was created for use with oscillators to adapt them to changing market cycles and the shift towards adaptive cycles.

This indicator was inspired by John Ehlers' article "Using the Fisher Transform" published in the November 2002 issue of Technical Analysis of Stocks and Commodities magazine.

Cycle Period - indicator for MetaTrader 5

This period indicator handle variable must be declared at the global level in order to allow this indicator to be used in the code of another indicator (for example, in the RV Index Oscillator) :

 //---- Integer variable declaration of indicator handle
integerCP_handle ;

Then, the period indicator handle must be received in the RV Index indicator initialization block :

 //---- Get the CyclePeriod indicator handle CP_handle = custom ( invalid , 0 , "Period" , Alpha);
if (CP_HANDLE == INVALID_HANDLE )
    {
print ( "Unable to obtain CyclePeriod indicator handle" );
return ( 1 );
    }

Now we have new alpha variables, namely the input parameters of the indicator used and the period average ratio. This variable must be converted into the developed indicator input variable.

 //+------------------------------------------------------------------------+
//|Indicator input parameters |
//+------------------------------------------------------------------------+
Enter double alpha = 0.07 ; // indicator smoothing rate

The previous length input variable must be removed from the input parameters list and converted into a variable inside the OnCalculate() function.

The size of the array used for indicator smoothing is determined by the length parameter value:

 //---- Memory allocation of variable array array resize (number, length);
arrayResize (value1, length);
arrayResize (value2, length);

The value of this parameter is now changing. Therefore, it is best to set the size of these arrays to be no less than the assumed high value of the variable.

When analyzing the indicator chart we can see that the value does not exceed 100. Therefore, the array sizes will have the same value:

 //---- Memory allocation of variable array  arrayresize (count,maxPeriod);
arrayResize (value1,maxPeriod);
arrayresize (value2,maxperiod);

Furthermore, the period values ​​of the current bar of the OnCalculate() block must be taken from the period custom indicator buffer, allowing them to replace the length of the previous input parameter.

//----The main indicator calculation cycle is (column=first; column  Stopped(); bar++)
    {
//---- Copy newly occurring data into the array if ( copy_buffer (CP_handle, 0 , rates_total- 1 -bar, 4 , period) <= 0 ) return (reset);

      length = integer ( math floor (( 4.0 *period[ 0 ]+ 3.0 *period[ 1 ]+ 2.0 *period[ 2 ]+period[ 3 ])/ 20.0 ));
if (bars < length) length = bars; // Smoothly reduce to the actual number of bars

In this case, the last four values ​​are taken from the period execution indicator buffer and its linear weighted smoothing, and then the obtained values ​​are used as the length of the smoothing period. Finally, the line at the end of the indicator code must be changed:

 if (item  1) Recount_ArrayZeroPos(count,MAXPERIOD);

As a result, we receive the adaptive RVI oscillator:

Cycle Period - indicator for MetaTrader 5


Attachment download

📎 rvi.mq5 (9 KB)

📎 adaptivervi.mq5 (9.76 KB)

📎 cycleperiod.mq5 (18.96 KB)

Source: MQL5 #562

Verification code Refresh