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

KeyFinder 2.0 - MetaTrader 5 Script | Trading Script Download - MT4/MT5 Resources

author EAcpu | 5 reads | 0 comments |

KeyFinder 2.0 - script for MetaTrader 5

KeyFinder 2.0 - script for MetaTrader 5

KeyFinder 2.0 - script for MetaTrader 5

KeyFinder 2.0 - script for MetaTrader 5

This script finds DeMark pivot points, displays them on the chart and indicates their dimensions.

This script actually functions like a key finder . It makes no visual difference other than the button that removes the script and all associated objects from the chart.

KeyFinder 2.0 - script for MetaTrader 5

Figure 1. RTS index futures chart after applying KeyFinder 2.0 script

Although the script remains visually and functionally unchanged, its code has been significantly modified.

A CKeyFinder class has been created for the script.

KeyFinder 2.0 - script for MetaTrader 5

Figure 2. CKeyFinder class

The code for this class is provided below. Since I try to be as detailed as possible in my comments, you shouldn't have any problems.

//+------------------------------------------------------------------+
//| KeyFinder.mqh |
//| Trofimov Pavel|
//| trofimovpp@mail.ru |
//+------------------------------------------------------------------+
#Property Copyright "Trofimov Pavel"
#Property associated with "trofimovpp@mail.ru"
//+------------------------------------------------------------------+
//| KeyFinder 2.0 Class |
//+------------------------------------------------------------------+
class key finder { private :
// class variable integer minimum size; // minimum dimension of points integer maximum bar; // number of bars to process
Protected :
// Class method for internal use // Determine the upper point size integer to obtain high dimension ( Mql rate &tmp rate[], integer tmp_i, integer tmp_iCod);
// Determine the size integer of the lower point Get low dimension ( Mql rate &tmp rate[], integer tmp_i, integer tmp_iCod); people :
// Class constructor CKeyFinder();
// Class destructor ~CKeyFinder();
//Get the attribute method integer of the dimension Get the minimum size();
// Set the attribute method of the dimension blank and set the minimum size ( integer temporary value);
// Property method integer used to get the number of bars to be processed Get the maximum number of bars ();
// Set the attribute method of the number of bars to be processed . Set the maximum number of bars ( integer temporary value);
// The method to find the upper pivot point is blank. Find key points ( integer temporary iCod, Mql rates &temp_rates[]);
// Method to find lower pivot point blank Find Low Pivot Point ( integer temporary iCod, Mql rates &temp_rates[]);
// Clear the chart from the script object. integer cleanChart();
  }; //+------------------------------------------------------------------+
//| Determine the upper point size |
//+------------------------------------------------------------------+
Integer CKeyFinder::getHighDimension( Mql rate &tmp rate[], integer tmp_i, integer tmp_iCod) // This method receives an array of MqlRates type data, the number of the processed bar in the array, and the maximum index of the array {
Integer k= 1 ;
Although ((tmpRates[tmp_i].high>tmpRates[tmp_i+k].high) && (tmpRates[tmp_i].high>tmpRates[tmp_i-k].high) && ((tmp_i+k)<(tmp_iCod)) && ((tmp_i-k)> 0 )) k++;
if (((tmp_i+k)==tmp_iCod) || ((tmp_i-k)== 0 )) k=- 1 ;
return (k);
  }; //+------------------------------------------------------------------+
//| Determine the lower point size |
//+------------------------------------------------------------------+
Integer CKeyFinder::getLowDimension( Mql rate &tmp rate[], integer tmp_i, integer tmp_iCod) // This method receives MqlRatesArray of type data, the number of processed bars in the array and the maximum index of the array { integer k= 1 ; although ((tmpRates[tmp_i].low  0 ; //|Method SetMinDimension | //+------------------------------------------------------------------+Blank CKeyFinder:: SetMinDimension(integer temporary value) { if (temporary value > 1 ) MinDimension = temp_Val ; else { Message box ("The set dimension is too low. " + "\n " + "The default size of 5 will be used " , " Warning !", MB_OK + MB_ICON warning ) ; minimum size = 5 ; }; }; // +------------------------------------------------------------------+ // | Method GetMaxBars | //+------------------------------------------------------------------+ Integer CKeyFinder::GetMaxBars() { return (maximum number of bars );}; // +------------------------------------------------------------------+ //| Method SetMaxBars | // +------------------------------------------------------------------ + Blank CKeyFinder ::SetMaxBars( integer temporary value) { // Check the availability of the history of a set number of bars integer SMaxBars = bars ( symbol (), 0 ); if (SMaxBars  // Set the maximum number of available bars message box ( "MaxBars parameter is too high." + "\n" + "only" + integer to string (temp_Val) + "Bar charts will be used for calculations." , "Warning!" , MB_OK + MB_ICON warning ); }; // Check if the number of bars is too few if (temp_Val<( 2 * minimum size)) { message box ( "The number of columns set is too few." + "\n" + "The default number of 300 will be used" , "Warning!" , MB_OK + MB_ICON warning ); Temporary value = 300 ; }; MaxBars=temp_Val; }; //+------------------------------------------------------------------+ //| Method FindKeyPoints - Find up key points | //+------------------------------------------------------------------+ Blank CKeyFinder::FindUpKeyPoints( Integer temporary iCod, MqlRates &temp_rates[]) // The method receives the maximum array element and the index of the MqlRates array { integer HD = 1 ; //initialize the point dimensions to ( integer i=temp_iCod-MinDimension; i>(minimum size - 1 ); i-) // loop from the last bar - MinDimension to the zero bar + MinDimension {HD=getHighDimension(temp_rates,i,temp_iCod); //Get the dimension of the point if ((HD>=minimum size) || (HD==- 1 )) { //If the MinDimension condition is met, create a mark string observation name = "KF_label" + integer to string (i); if (HD!=- 1 ) { Object creation ( 0 , observation name, object text , 0 ,temp_rates[i].time,temp_rates[i].high); object set integer ( 0 , observation name, OBJPROP_Anchor , 0 , ANCHOR_LOWER ); object set string ( 0 , observation name, OBJPROP_TEXT , 0 , integer to string (HD)); object set integer ( 0 , observation name, OBJPROP_COLOR , red blood cells ); } other { //If the size cannot be determined, use the ball marker object to create ( 0 , observation name, OBJ_arrow , 0 , temp_rates[i].time, temp_rates[i].high); object set integer ( 0 , observation name, OBJPROP_ARROWCODE , 0 , 159 ); object set integer ( 0 , observation name, OBJPROP_Anchor , 0 , anchor bottom ); object set integer ( 0 , observation name, OBJPROP_COLOR , red blood cells ); }; }; }; }; //+------------------------------------------------------------------+ //| Method FindLowKeyPoints - Find lower key points | //+------------------------------------------------------------------+ Blank CKeyFinder::FindLowKeyPoints( integer temporary iCod, MqlRates &temp_rates[]) // The method receives the maximum array element and the index of the MqlRates array { integer LD = 1 ; // Initialization point size boolean i created; for ( integer i = temp_iCod-MinDimension; i>(minimum size - 1 ); i - ) // Loop from the last bar - MinDimension to the zero bar + MinDimension { LD=getLowDimension(temp_rates,i,temp_iCod); if ((LD>=minimum size) || (LD==- 1 )) { Thin rope observation name = "KF_label" + integer to string (1) + "_1" ; //Bars avoiding the lowest and highest points may be key points if (LD!=- 1 ) { I create = object creation ( 0 , observation name, object text , 0 ,temp_rates[i].time,temp_rates[i].low); if (i creates) { object set integer ( 0 , observation name, OBJPROP_Anchor , 0 , anchor_upper ); object set string ( 0 , observation name, OBJPROP_TEXT , 0 , integer to string (LD)); object set integer ( 0 , observation name, OBJPROP_COLOR , clear green ); } other comments ( "Unable to create object" ); } other { I created = object created ( 0 , observation name,ro">OBJ_arrow, 0 , temp_rates[i].time, temp_rates[i].low); if (i create) { object set integer ( 0 , observation name, OBJPROP_ARROWCODE , 0 , 159 ); object set integer ( 0 , observation name, OBJPROP_Anchor , 0 , anchor top ); object set integer ( 0 , Observation name, OBJPROP_COLOR , clear green ); } Other comments ( "Unable to create object" ); }; }; }; }; //+------------------------------------------------------------------+ //| Method CleanChart - clear chart from object | //+------------------------------------------------------------------+ Integer CKeyFinder::CleanChart( blank ) { string label = "KF_label" ; integer total number of objects = total number of objects ( 0 , 0 ) , - 1 ), n = 0 ; for ( integer obj = obj_total- 1 ; object >= 0 ; object --) // clear objects created by script via name mask { string object name = object name ( 0 , object name, label ) >= 0 ; if ( string lookup (object name, label) >= 0 ) object delete ( 0 , object name); n++; } return (n); } //+------------------------------------------------------------------+ //|Class constructor | //+------------------------------------------------------------------+ CKeyFinder::CKeyFinder(){}; //+------------------------------------------------------------------+ //| Class destructor | //+------------------------------------------------------------------+ CKeyFinder::~CKeyFinder(){}; //+----------------------------------------------------------------------------------+

The main script code is very compact since most of the code has been moved into classes.

//+------------------------------------------------------------------+
//| KeyFinder2.mq5 |
//| Trofimov Pavel|
//| trofimovpp@mail.ru |
//+------------------------------------------------------------------+
#Property Copyright "Trofimov Pavel"
#Property associated with "trofimovpp@mail.ru"
# Property version "2.00"
# Property description "Warning! This algorithm uses loops for calculations!"
# Property description "It is recommended to set no more than 1000 to handle!"
#Property script display input
//--- input parameters
Input integer minimum size = 5 ; //minimum dimension of point
Enter an integer, the maximum number of bars = 300 ; //The number of bars to be processed
#Include "KeyFinder.mqh"
#include //+------------------------------------------------------------------+
//|Script variables |
//+------------------------------------------------------------------+ CKeyFinder m_keyfinder; //Declare the СKeyFinder class variable CChartObjectButton m_button_close; //Declare the CChartObjectButton class variable
//+------------------------------------------------------------------+
//|Script program startup function |
//+------------------------------------------------------------------+
blank start ()
  { //-Initialize variable Mql rates rates_array[];
String com= “\n\n\n” ;
integer iCod = CopyRate ( symbol (), Period (), 0 , MaxBars, rates_array); // The number of elements in the MqlRates array we are able to copy integer west = 10 ; // Button position if ( ChartGetInteger ( 0 , CHART_SHOW_OHLC ))
      West += 16 ; //-Set necessary parameters m_keyfinder.SetMaxBars(MaxBars);
  m_keyfinder.SetMinDimension(MinDimesion);
  m_keyfinder.CleanChart(); //Clear the object in the chart on the second use iCod=iCod- 1 ; //Index of the largest element in rates_array[] communication += "Working... Please wait!" ; //- Create a button and set its properties m_button_close.Create( 0 , "Close button" , 0 , 10 ,sy, 100 , 20 );
  m_button_close.description( "Close script" );
  m_button_close.Color(blue);
  m_button_close.FontSize( 8 );
Comment (Communication); //-Use CKeyFinder class method to process column chart if (iCod> 0 )
    {
      m_keyfinder.FindUpKeyPoints(iCod,rates_array); //Search for upper key points Communication += "\nThe above points have been processed.\n" ;
Comments (Newsletter);
      m_keyfinder.FindLowKeyPoints(iCod,rates_array); //Search for lower key point comments ( "\n\n\nProcessing completed" );
    }
class="keyword">Other comments ( "\n\n\nNo columns to process!!!" ); m_button_close.State( false ); //- Loop the script until the button is pressed although (!(m_button_close.State())) { //--- Redraw the chart chart redraw (); sleep ( 250 ); }; //- Clear the chart when the button is pressed m_keyfinder.CleanChart(); Comments ( "" ); }

Finally, I've included some helpful links and explanations:

I look forward to reading your comments, feedback and suggestions. Good luck with the transaction!


Attachment download

📎 keyfinder2.mq5 (6.22 KB)

📎 keyfinder.mqh (19.26 KB)

Source: MQL5 #12439

Verification code Refresh