Scripts: KeyFinder 2.0

 

KeyFinder 2.0:

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

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

Author: Pavel Trofimov

 

The button that deletes the script (does not always work) remains on the screen (not always). MT4 terminal, Alpari, bild 765


 
I was able to simulate your situation. This behaviour is the result of using another script after KeyFinder 2.0. I haven't figured out how to overcome this at the code level yet. In terms of usage - reapply KeyFinder 2.0 and the button will be "working" again.
 
Maybe it is more reasonable to make the programme as an indicator, and clear the screen when the indicator is removed from the chart?
 
komposter:
Maybe it would be more reasonable to make the programme as an indicator, and clear the screen when the indicator is removed from the chart?
I am working on an indicator. The script is a "test of my pen".
 
Rubick:
I was able to simulate your situation. This behaviour is the result of using another script after KeyFinder 2.0. I haven't figured out how to overcome this at the code level yet. In terms of usage - reapply KeyFinder 2.0 and the button will be "working" again.
I tried to defeat the button stuck on the screen in all sorts of ways. The simplest one is to delete the currency pair window and create it again from scratch. The information displayed by the script is very useful. For example, I use a lot of things in trading (Murray levels - TirMethod, trading models Third Wave and Consolidation) and everywhere I need a similar indicator (ZigZag, ZipPips,), and the script helps to assess the correctness of the construction of figures and proportionality of extrema. Let's wait for the indicator. Keep us informed. Do you have a page in any social network? Good luck and success to you!
 
ernst.yagafarof:
I tried to defeat the button "stuck" on the screen in all sorts of ways. The simplest one is to delete the currency pair window and create it again from scratch. The information displayed by the script is very useful. For example, I use a lot of things in trading (Murray levels - TirMethod, trading models Third Wave and Consolidation) and everywhere I need a similar indicator (ZigZag, ZipPips,), and the script helps to assess the correctness of the construction of figures and proportionality of extrema. Let's wait for the indicator. Keep us informed. Do you have a page in any social network? Good luck and success to you!
I have updated my profile.
 
I have good news! I have finished designing and writing a class for the indicator, now I am writing the indicator itself, I plan to finish it next week - at most, at least over the current weekend.
 
Rubick:
I have good news! I've finished designing and writing the class for the indicator, now I'm writing the indicator itself, I plan to finish next week - at most, at least over the current weekend.
Thank you. We are looking forward to it!
 

What can I apply it to?

I put your script into the Indicator, when I switch the chart it recalculates everything.

GBPUSDH4.

//+------------------------------------------------------------------+
//|KeyFinder.mq5 |
//|Trofimov Pavel |
//|trofimovpp@mail.ru |
//+------------------------------------------------------------------+
#property copyright "Trofimov Pavel"
#property link      "trofimovpp@mail.ru"
#property version   "1.00"
#property description "Warning! This algorithm uses cycles in calculations!"
#property description "It is strongly recommended to set a maximum of 1000 bars for processing!"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//--- input parameters
input int      MinDimesion = 5;          // Minimum dimensionality of points
input int      MaxBars     = 300;        // Number of bars to be processed
input string   LabelName   = "KF_Label"; //
//+------------------------------------------------------------------+
//| Custom indicator initialisation function |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//||
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   CleanChart();
   Comment("");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
//check history availability for the set number of bars
   int SMaxBars=Bars(Symbol(),0),iMaxBars=MaxBars;
   if(SMaxBars<MaxBars)
     {
      iMaxBars=SMaxBars;
      Comment("The MaxBars parameter is set too large."+"\n"+"For the calculations will be used "+IntegerToString(SMaxBars)+" bars.");
     };
   int clean=CleanChart();//clear the graph when reapplying it
   MqlRates  rates_array[];
   string Com="";
   int iCod=CopyRates(Symbol(),Period(),0,iMaxBars,rates_array);//number of array elements
   iCod=iCod-1;//Index of the maximum element in the array
   Com="Working...Wait for it!";
   Comment(Com);
   if(iCod>0)
     {
      FindUpKeyPoints(iCod,rates_array);//Find the top key points
      Com=Com+"\n"+"The top points have been processed."+"\n";
      Comment(Com);
      FindLowKeyPoints(iCod,rates_array);//Find lower key points
      Comment("Processing complete.");
     }
   else
      Comment("Lack of processing bars!!!");
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|| Finding the top key points|
//+------------------------------------------------------------------+
void FindUpKeyPoints(int temp_iCod,MqlRates &temp_rates[])
  {
   int HD=1;
   for(int i=temp_iCod-MinDimesion; i>(MinDimesion-1); i--)// cycle by bars from final - MinDimension to zero + MinDimension
     {
      HD=getHighDimension(temp_rates,i,temp_iCod);//get the dimensionality of the points
      if((HD>=MinDimesion) || (HD==-1))
        {
         // create a mark if it falls under MinDimension conditions
         string Ob_Name=LabelName+IntegerToString(i);
         if(HD!=-1)
           {
            ObjectCreate(0,Ob_Name,OBJ_TEXT,0,temp_rates[i].time,temp_rates[i].high);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_LOWER);
            ObjectSetString(0,Ob_Name,OBJPROP_TEXT,0,IntegerToString(HD));
            ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrRed);
           }
         else
           {
            //If we can't determine the dimension, we mark it with a ball.
            ObjectCreate(0,Ob_Name,OBJ_ARROW,0,temp_rates[i].time,temp_rates[i].high);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ARROWCODE,0,159);
            ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_BOTTOM);
            ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrRed);
           };
        };
     };
  }
//+------------------------------------------------------------------+
//|Searching for lower key points |
//+------------------------------------------------------------------+
void FindLowKeyPoints(int temp_iCod,MqlRates &temp_rates[])
  {
   int LD=1;//initialise point dimensions
   bool iCreate;
   for(int i=temp_iCod-MinDimesion; i>(MinDimesion-1); i--)
     {
      LD=getLowDimension(temp_rates,i,temp_iCod);
      if((LD>=MinDimesion) || (LD==-1))
        {
         string Ob_Name=LabelName+IntegerToString(i)+"_1";//Worry about bars where the low and high can be key points
         if(LD!=-1)
           {
            iCreate=ObjectCreate(0,Ob_Name,OBJ_TEXT,0,temp_rates[i].time,temp_rates[i].low);
            if(iCreate)
              {
               ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_UPPER);
               ObjectSetString(0,Ob_Name,OBJPROP_TEXT,0,IntegerToString(LD));
               ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrGreen);
              }
            else
               Comment("Can't create an object.");
           }
         else
           {
            iCreate=ObjectCreate(0,Ob_Name,OBJ_ARROW,0,temp_rates[i].time,temp_rates[i].low);
            if(iCreate)
              {
               ObjectSetInteger(0,Ob_Name,OBJPROP_ARROWCODE,0,159);
               ObjectSetInteger(0,Ob_Name,OBJPROP_ANCHOR,0,ANCHOR_TOP);
               ObjectSetInteger(0,Ob_Name,OBJPROP_COLOR,clrGreen);
              }
            else
               Comment("Can't create an object.");
           };
        };
     };
  }
//+------------------------------------------------------------------+
//| Determining the dimensionality of the upper point |
//+------------------------------------------------------------------+
int getHighDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod)
  {
   int k=1;
   while((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);
  }
//+------------------------------------------------------------------+
//| Determining the dimensionality of the bottom point |
//+------------------------------------------------------------------+
int getLowDimension(MqlRates &tmpRates[],int tmp_i,int tmp_iCod)
  {
   int k=1;
   while((tmpRates[tmp_i].low<tmpRates[tmp_i+k].low) && (tmpRates[tmp_i].low<tmpRates[tmp_i-k].low) && ((tmp_i+k)<(tmp_iCod)) && ((tmp_i-k)>0))
      k++;
   if(((tmp_i+k)==tmp_iCod) || ((tmp_i-k)==0))
      k=-1;
   return(k);
  }
//+-------------------------------------------------------------------------------+
//| Clearing the graph of objects created by the script in case of reapplication ||
//+-------------------------------------------------------------------------------+
int CleanChart()
  {
   string Label=LabelName;
   int obj_total=ObjectsTotal(0,0,-1),n=0;
   for(int obj=obj_total-1; obj>=0; obj--)
     {
      string objname=ObjectName(0,obj,0,-1);
      if(StringFind(objname,Label)>=0)
         ObjectDelete(0,objname);
      n++;
     }
   return(n);
  }
//+------------------------------------------------------------------+
Files:
KeyFinder.mq5  16 kb
 
I tried it and found it good ..... a couple of settings to keep it up to date.