Author: budimir
PROvidets

This script is designed as a specialized analytical tool for the MetaTrader platform, used to calculate specific historical price statistics based on user-defined dates and timeframes. Its primary purpose is to identify a precise point in historical data and perform a linear calculation over a set number of preceding bars.

Core Functionality

1. Environment and Input Validation The script begins by ensuring the trading environment meets specific requirements. It checks that the user is viewing either a 1-Hour (H1) or a 4-Hour (H4) chart. If these conditions aren't met, the script will alert the user. It also validates the date and time inputs—such as Year, Month, Day, and Hour—to ensure they fall within realistic historical ranges.

2. Historical Data Localization The tool is designed to "travel back in time" to a specific moment defined by the user. It scans through the historical price history until it finds the exact bar that matches the date and time provided in the settings. Once this starting point is located, it establishes a reference for the calculation.

3. Statistical Calculation Once the correct historical point is found, the script looks at a specific number of bars (the "Count" defined by the user) leading up to that moment. It performs a weighted mathematical operation on the closing prices of those bars.

Specifically, it calculates:

  • A sum of the closing prices weighted by their position in the sequence.
  • A secondary calculation involving the squares of those positions.

4. Output Generation After completing the calculations, the script generates a formatted alert on the screen. This alert displays the asset name (Symbol), the timeframe, the number of bars analyzed, and two final numerical results (labeled as 'a' and 'b'). These values represent the finalized output of the mathematical formula applied to that specific historical window.

Summary of Usage

Essentially, this tool allows a trader to "lock onto" a specific date in history and instantly see a calculated statistical snapshot of the price action occurring just before that moment. It removes the need for manual calculation by automating the retrieval of historical data and the application of a specific mathematical sequence.

Miscellaneous
It issuies visual alerts to the screen
11 Views
0 Downloads
0 Favorites
PROvidets
//+------------------------------------------------------------------+
//|                                                    PROvidets.mq4 |
//|                                                          budimir |
//|                                              tartar27@bigmir.net |
//+------------------------------------------------------------------+
#property copyright "budimir"
#property link      "tartar27@bigmir.net"
#property show_inputs
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
extern int  Count_bars=12;
extern int    Year_PRO=2009;
extern int   Month_PRO=3;
extern int     Day_PRO=3;
extern int    Hour_PRO=3;
//ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
string  ss="Incorrect data input !",
        st="Not that timeframe !",
        sz="?",
        sp=" ___:___ ";
int     i,z,num,x;
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
    if(Period()== 60) sz="H1";
    if(Period()==240) sz="H4";
    if (sz=="?") { Alert(st);
                  return (0);
                 }
          bool hour_correct=false;
   if(Period()== 60 &&  Hour_PRO>-1 &&  Hour_PRO <24) hour_correct=true;
   if(Period()==240 &&  Hour_PRO>-1 &&  Hour_PRO < 6) hour_correct=true;
    //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
   if(    Year_PRO  <1970  ||  Year_PRO  >2037  ||  
          Month_PRO <1     ||  Month_PRO >12    ||
          Day_PRO   <1     ||  Day_PRO   >31    ||
          Hour_PRO  <0     ||  Hour_PRO  >23    ||
          Count_bars<3   )
          
                 { Alert(ss);
                  return (0);
                 }  
          
    //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
    
    bool correct=false;    if (Period()== 60) {x=1;} else { x=4;}
    
      for(i=Bars;i>=1;i--) { 
      
      if( Year_PRO==    TimeYear (Time[i])     &&  
          Month_PRO==   TimeMonth(Time[i])     &&   
          Day_PRO==     TimeDay  (Time[i])     && 
          Hour_PRO*x==  TimeHour (Time[i])     && 
          hour_correct                         && 
          Count_bars<=i)
      
                               { correct=true;num=i;
                               }
                if (correct)  break;
       
                           } // -----end_for------
    //oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
    
  if (!correct)  { Alert(ss);
                 return (0);
                  }
   //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
      double s1=0,s2=0,a1=0,a2=0,b1=0,b2= Count_bars;
      
       for ( z=1; z<=b2; z++) {     s1=s1+Close[num+1-z]*z;
                                    s2=s2+Close[num+1-z];
                                    a1=a1+z*z;
                                    a2=a2+z;
                              }
            b1=a2; double dif=Op(a1,b1,a2,b2);
    //oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
    Alert(sp+Symbol()+sp+sz+sp+Bars+sp+"a="+
      DoubleToStr(Op(s1,b1,s2,b2)/dif,8)+sp+"b="+DoubleToStr(Op(a1,s1,a2,s2)/dif,4)+sp);
      
    
    
    
    //ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
    
//----
   return(0);
  }
//oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
double Op( double c1,double d1,double c2,double d2) { return (c1*d2-c2*d1);}

Comments