Convergence Index Stoch+RSI+MACD - MetaTrader 5 Script - MT4/MT5 Resources




//+------------------------------------------------------------------+ //| MultiConfluence_Index.mq5 | //| Stoch+RSI+MACD Convergence Index | //+------------------------------------------------------------------+ #Property Copyright "Diversity Integration Index" # Property version "1.00" #property -indicator_separate_window #Property indicator buffer 6 #Property Indicator Chart 4 // Index main line # propertyindicatortag1 "Convergence Index" #Property indicator type 1 draw line # propertyindicatorcolor1clrdodgeblue # Property indicator width 1 3 // Neutral line #propertyindicatortag2 " zero line" #Property indicator type 2 draw line #Property indicator color 2 gray gray #property- indicator-width 2 1 #property -indicator-style2 -style_point // Area bullish extreme #PropertyIndicators Tag 3 “Area Bullish” #property indicator type 3 draw_fill #property indicator color 3 clr dark green // Extreme bearish area #PropertyIndicators Tag 4 “Area Bearish” #property indicator type 4 draw_fill #property indicator color 4 clr dark red //+------------------------------------------------------------------+ //|Input parameters | //+------------------------------------------------------------------+ Enter group "=== timeframe===" Input ENUM_TIMEFRAMES TF1 = PERIOD_CURRENT ; // time range 1 (fast) Input ENUM_TIMEFRAMES TF2= PERIOD_H1 ; // Time range 2 (medium) Input ENUM_TIMEFRAMES TF3 = PERIOD_H4 ; // Time range 3 (slow) Enter the group "===Parameters=== Input integer Stoch_K = 14 ; // random K Input integer Stoch_D = 3 ; // random D Input integer Stoch_Slowing= 3 ; // Random slowing down Input integer RSI_period = 14 ; // RSI period Input integer MACD_fast = 12 ; // MACD EMA fast Input integer MACD_Slow = 26 ;comment">// MACD EMA slow input integer MACD_signal = 9 ; // MACD signal //+------------------------------------------------------------------+ //|Buffer | //+------------------------------------------------------------------+ Double the index buffer[]; Double the zero buffer[]; Double the BullishZoneTop[]; Double the BullishZoneBottom[]; Double the BearishZoneTop[]; Double the BearishZoneBottom []; // Indicator handle integer handle_stoch_tf1, handle_stoch_tf2, handle_stoch_tf3; integer handle_rsi_tf1, handle_rsi_tf2, handle_rsi_tf3; integer handle_macd_tf1, handle_macd_tf2, handle_macd_tf3; //+--------------------------------------------------------------------------------+ // |Initialization | //+------------------------------------------------------------------+ Integer initialization time () { //Buffer set index buffer ( 0 , index buffer, INDICATOR_DATA ); set index buffer ( 1 , zero buffer, INDICATOR_DATA ); set index buffer ( 2 , bullish area top, INDICATOR_DATA ); set index buffer ( 3 , bullish area bottom, INDICATOR_DATA ) ); Set Index Buffer ( 4 , Bearish Top, INDICATOR_DATA ); Set Index Buffer ( 5 , Bearish Bottom, INDICATOR_DATA ); // config arrayset for series (index buffer, true ); arrayset for series( zero buffer, true ); arrayset for series (bullish zone top, true ); arrayset for series(bullish zone bottom, true ); arrayset for series (bearish zone top , true ); , plot_draw_start , 0 ); plot index set integer ( 3 , plot_draw_start , 0 ); // Create handle - stochastic handle _stoch_tf1 = stochastic indicator ( _symbol , TF1, Stoch_K, Stoch_D, Stoch_Slowing, mode_SMA , STO_LOWHIGH ); handle _stoch_tf2 = stochastic indicator ( _symbol , TF2, Stoch_K, Stoch_D, Stoch_Slowing, mode_SMA , STO_LOWHIGH ); handle_stoch_tf3 = Stochastic indicator (_symbol , TF3, Stoch_K, Stoch_D, Stoch_Slowing, mode_SMA , STO_LOWHIGH ); // Create handle - RSI handle _rsi_tf1 = RSI ( _symbol , TF1, RSI_PERIODS, PRICE_CLOSE ); handle_rsi_tf2 = RSI ( _SYMBOL, TF2, RSI_PERIOD, PRICE_CLOSE); handle_rsi_tf3 = RSI(_SYMBOL , TF3 , RSI_PERIODS, PRICE_CLOSE ); // Create handle - MACD handle _macd_tf1 = Smoothed Moving Average Convergence Divergence ( _SYMBOL , TF1, MACD_fast, MACD_slow, MACD_signal, PRICE_CLOSE ); handle_macd_tf2 =ndicators">Moving Average Convergence Divergence ( _symbol , TF2, macd_fast, macd_slow, macd_signal, PRICE_CLOSE ); handle_macd_tf3 = Moving Average Convergence Divergence ( _symbol , TF3, macd_fast, macd_slow, macd_signal, PRICE_CLOSE ); // Validate handle if (handle_stoch_tf1 == INVALID_HANDLE ||handle_stoch_tf2 == INVALID_HANDLE ||handle_stoch_tf3 == INVALID_HANDLE || handle_rsi_tf1 == INVALID_HANDLE ||handle_rsi_tf2 == INVALID_HANDLE ||handle_rsi_tf3 == INVALID_HANDLE || handle_macd_tf1 == INVALID_HANDLE || handle_macd_tf2 == INVALID_HANDLE || handle_macd_tf3 == INVALID_HANDLE ) { print ( "Error: Unable to create handle" ); return ( initialization failed ); } // Name and scale indicator set string ( INDICATOR_SHORTNAME , "Multiple Fusion Index" ); Indicator set integer ( INDICATOR_DIGITS , 1 ); Indicator set double ( INDICATOR_MINIMUM , - 100 ); Indicator set double ( INDICATOR_MAXIMUM , 100 ); // Level indicator set integer ( INDICATOR_LEVELS , 3 ); Indicator set double ( INDICATOR_LEVELVALUE , 0 , 0 ); Indicator set double ( INDICATOR_LEVELVALUE , 1 , 50 ); indicator set double ( INDICATOR_LEVELVALUE , 2 , - 50 ); indicator set integer ( INDICATOR_LEVELCOLOR , 0 , gray ); indicator set integer ( INDICATOR_LEVELCOLOR , 1 , clear green ); indicator set integer ( INDICATOR_LEVELCOLOR , 2 , red blood cells ); indicator set integer ( INDICATOR_LEVELSTYLE , 0 , style_entity ); indicator set integer ( INDICATOR_LEVELSTYLE , 1 , style_point ); indicator set integer ( INDICATOR_LEVELSTYLE , 2 , style_point ); print ( "Multiple pool index has been initialized - TF:" , enumeration to string (TF1), "/" , enumeration to string (TF2), "/" , enumeration to string (TF3)); return ( initialization successful ); } //+----------------------------------------------------------------------------------+ //|De-initialization | //+------------------------------------------------------------------+ Blank solution initialization ( constant integer reason) { if (handle_stoch_tf1! = INVALID_HANDLE ) indicator release (handle_stoch_tf1); if (handle_stoch_tf2! = INVALID_HANDLE ) indicator release ( handle_stoch_tf2 ); if (handle_stoch_tf3! = INVALID_HANDLE) indicator release (handle_stoch_tf3); if (handle_rsi_tf1! = INVALID_HANDLE ) indicator release (handle_rsi_tf1); if (handle_rsi_tf2! = INVALID_HANDLE ) indicator release (handle_rsi_tf2); if (handle_rsi_tf3! = INVALID_HANDLE ) indicator release (handle_rsi_tf3); if (handle_macd_tf1! = INVALID_HANDLE ) ) indicator release (handle_macd_tf1); if (handle_macd_tf2 != INVALID_HANDLE ) indicator release (handle_macd_tf2); if (handle_macd_tf3 != INVALID_HANDLE ) indicator release (handle_macd_tf3); comment ( "" ); } //+--------------------------------------------------------------------------------+ //|Main calculation | //+------------------------------------------------------------------+ when calculating integers ( const integer rate_total, const integer previously calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const integer &spread[]) { if (rate_total < 100 ) return ( 0 ); integer limit = rates_total - prev_calculated; if (limit == 0 ) limit = 1 ; if (previously calculated == 0 ) limit = rates_total - 100 ; // data array (as series matching buffer index) double stoch_k1[], stoch_d1[], stoch_k2[], stoch_d2[], stoch_k3[], stoch_d3[]; double rsi1[], rsi2[], rsi3[]; double macd_ma in1[], macd_sig1[], macd_main2[], macd_sig2[], macd_main3[], macd_sig3[]; array set is series (stoch_k1, true ); array set is series (stoch_d1, true ); array set is series(stoch_k 2, true ); array set is series (stoch_d2, true ); array set is series ( stoch_k3, true ); array set is series (stoch_d3, true ); array set is series (rsi1, true ); array set is series (rsi2, true ); array set is series (rsi3, true ); array set is series ( macd_main1, true ); array set as series (macd_sig1, true ); array set as series (macd_main2, true ); array set as series (macd_sig2, true ); array set as series (macd_main3, true ); array set as series (macd_sig3, true ); // Copy data - copy enough bars integer copy number = limit + 50 ; integer copy = 0 ; copy = copy buffer (handle_stoch_tf1, 0 , 0 , bars_to_copy, stoch_k1); if (copy <= 0 ) {ons">print( "Error: Unable to copy stoch_k1, code:" , get the last error ()); return (previously calculated); } if ( copy buffer (handle_stoch_tf1, 1 , 0 , number of copies, stoch_d1) <= 0 ) { print ( "Error: unable to copy stoch_d1" ); return (previously calculated); } if ( copy buffer (handle_stoch_tf2, 0 , 0 , bars_to_copy, stoch_k2) <= 0 ) { print ( "Error: Unable to copy stoch_k2" ); return (previously calculated); } if ( copy buffer (handle_stoch_tf2, 1 , 0 , number of copies, stoch_d2) <= 0 ) { print ( "Error: Unable to copy stoch_d2" ); return (previously calculated); } if ( copy buffer (handle_stoch_tf3, 0 , 0 , bars_to_copy, stoch_k3) <= 0 ) { print ( "Error: Unable to copy stoch_k3" ); return (previously calculated); } if ( copy buffer (handle_stoch_tf3, 1 , 0 , bars_to_copy, stoch_d3) <= 0 ) { print ( "Error: Unable to copy stoch_d3" ); return (previously calculated); } if ( copy buffer (handle_rsi_tf1, 0 , 0 , number of copied bars, rsi1) <= 0 ) { print ( "Error: failed to copy rsi1" ); return (previously calculated); } If ( copy buffer (handle_rsi_tf2, 0 , 0 , number of copies, rsi2) <= 0 ) { print ( "Error: failed to copy rsi2" ); return (previously calculated); } if ( copy buffer (handle_rsi_tf3, 0 , 0 , number of copies, rsi3) <= 0 ) { print ( "Error: failed to copy rsi3" ) ); return (previously calculated); } if ( copy buffer (handle_macd_tf1, 0 , 0 , bars_to_copy, macd_main1) <= 0 ) { print ( "Error: cannot copy macd_main1" ); return (previously calculated); } if ( copy buffer (handle_macd_tf1, 1 , 0 , bars_to_copy, macd_sig1) <= 0 ) { print ( "Error: Unable to copy macd_sig1" ); return (previously calculated); } if ( copy buffer (handle_macd_tf2, 0 , 0 , bars_to_copy, macd_main2) <= 0 ) { print ( "Error: Unable to copy macd_main2" ); return (previously calculated); } if ( copy_buffer (handle_macd_tf2, 1 , 0 , bars_to_copy, macd_sig2) <= 0 ) { print ( "Error: cannot copy macd_sig2" ); return (previously calculated); } if ( copy_buffer (handle_macd_tf3, 0 , 0 , bars_to_copy, macd_main3) <= 0 ) { print ( "Error: Unable to copy macd_main3" ); return (previously computed); } if ( copy buffer (handle_macd_tf3, 1 ,0 ,bars_to_copy,macd_sig3) <= 0 ){ print ( "Error: cannot copy macd_sig3" ); return (previous calculation); } print ( "debug: copied" , copy, "bars,limits=" , rates_total=" ,rates_total); // Calculate index - now i=0 is the nearest bar integer calculation = 0 ; for ( integer i = 0 ; i < limit; i++) { // Security checks for array access if (i >= array_size (stoch_k1) || i >= array_size (stoch_k2) || i >= array_size (stoch_k3)) { print ( "debug: skip i="" , i, "-stoch array too small" ); continue ; } if (i >= array_size (rsi1) || i >= array size (rsi2) || i >= array size (rsi3)) { print ( "Debug: Skip i=", i, "-rsi array too small" ); continue ; } if ( i >= array size (macd_main1) || i >= array size (macd_main2) || i >= array size (macd_main3)) { print ( "Debug: Skip i=", i, "- MACD array too small " ) ; continue ; } Double fraction = 0.0 ; //=== Random=== // TF1 if ( stoch_k1 [i] > stoch_d1[i]) fraction += 11.0 ; other fractions -= 11.0 ; // TF2 if (stoch_k2[i] > stoch_d2 [ i ] ) fraction += 17.0 ; other fractions - = 17.0 ; // TF3 if (stoch_k3[i] > stoch_d3 [i]) score += 17.0 ; other scores -= 17.0 ; // === RSI === // TF1 if (rsi1[i] > 50 ) score += 7.0 ; other scores -= 7.0 ; // TF2 if (rsi2[i] > 50) score += 11.0 ; other scores -= 11.0 ; // TF3 if (rsi3[i] > 50 ) scores += 11.0 ; other scores -= 11.0 ; //=== MACD === // TF1 if (macd_main1[i] > macd_sig1[i]) scores += 6.0 ; other scores -= 6.0 ; // TF2 if (macd_main2 [ i] <umber">3) // debug 3 premiere bars { print ( "debug:bars[" , i, "] score=" , score, "stoch1=" , stoch_k1[i], "rsi1=" , rsi1[i], "macd1=" , macd_main1[i]); } // Colored area if (score > 50 ) { bullish area top[i] = 100 ; BullishZoneBottom[i] = 50 ; } else { BullishZoneBottom[i] = null_VALUE ; BullishZoneBottom[i] = null_VALUE ; } if (score < - 50 ) { BearishZoneTop[i] = - 50 ; BearishZoneBottom[i] = - 100 ; } else { BearishZoneTop[i] = null_VALUE ; BearishZoneBottom[i] = null_VALUE ; } } print ( "DEBUG: Calculation" , calculated, "bar out" , limit); // Debug information on first calculation if (previously calculated == 0 ) { string_info = string format ( "Complete | Current Index: %.1f" , index_buffer[ 0 ]); print (info); comment (info); } return (rate_total); } //+------------------------------------------------------------------+
Attachment download
📎MTF_NN.mq5 (27.81 KB)
Source: MQL5 #66295
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •