LGP-Pivot%20DJ-2
Download scriptThis script is designed to serve as a specialized analytical tool for traders who want to identify key price levels—specifically "Pivot Points"—based on specific timeframes and regions. Instead of providing a visual line or an automated trade, it acts as a data processor that calculates significant price boundaries for the European and US markets.
Core Logic Overview
The script focuses on two distinct trading sessions: Europe and the USA. For each of these regions, it looks back at historical price action to determine three critical values: the Highest Price (High), the Lowest Price (Low), and the Closing Price. It then uses these figures to calculate a "Pivot Point," which is the mathematical average of the High, Low, and Close prices for that specific period.
How the Calculation Works
The logic follows a structured step-by-step process:
- Time Synchronization: The script utilizes specific user-defined inputs to identify when a session ends (e.g., the end of the European trading window vs. the US window). It maps these times onto a 5-minute price interval system to ensure accuracy.
- Dynamic Lookback: Once the script identifies the correct "end time" for a session, it calculates how far back into the past it needs to look based on the requested calculation period. It then scans that specific window of time to find the absolute highest and lowest points reached by the market.
- Pivot Generation: By combining the highest high, the lowest low, and the closing price of that specific timeframe, the script generates a Pivot level. This serves as a reference point for where price might face resistance or support.
User Experience
Rather than cluttering your chart with graphics, this tool provides a clean, text-based summary directly on the screen. It displays:
- The European Pivot Data: Showing the calculated Pivot, High, Low, and Close for the European session.
- The USA Pivot Data: Showing the same metrics for the US session.
If one of the sessions is not currently active or valid based on the time settings, the script intelligently adjusts to show only the data that is available. This allows traders to quickly see "market benchmarks" at a glance, helping them understand the price boundaries established by major global markets throughout the day.
//+------------------------------------------------------------------+
//| LGP-Pivot DJ-2 (ëåîíèä).mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| LGP-Pivot DJ-2 |
//| Copyright © 2005, LGP |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
// 17-10-05
// 17-11-05
#property copyright "Copyright © 2005, LGP"
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
//---- input parameters
extern double forEurope_periodRascheta_hour=9;
extern double forUSA_periodRascheta_hour=6;
extern double forEurope_end_hourMT4=7;
extern double forEurope_end_minuteMT4=15;
extern double forUSA_end_hourMT4=13;
extern double forUSA_end_minuteMT4=0;
//
double nClose=0;
double nPivot=0;
double nMaxHigh=0;
double nMinLow=99999999;
//---- buffers
//
double mas[][6];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Comment (" ");
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
Comment (" ");
return(0);
}
//------------------------------------------------------------------
void funPivot(double PeriodHour, double hourMT4, double minuteMT4)
{
//
nPivot=0;
nMaxHigh=0;
nMinLow=99999999;
nClose=0;
//
string sTimeMT4=DoubleToStr(Year(),0)+"."+DoubleToStr(Month(),0)+"."+DoubleToStr(Day(),0)+" "
+ DoubleToStr(hourMT4,0)+":"+DoubleToStr(minuteMT4,0)+":00";
datetime dTimeMT4=StrToTime(sTimeMT4);
//
int k=0;
int n=3000;
for (int i=0; i<n; i++)
{
if (mas[i][0]==dTimeMT4)
{
k=i;
break;
}
}
if (k==0)
return(1);
//
int m=(PeriodHour *12)+(minuteMT4/5);
//
for (i=k; i<=(k+m); i++)
{
if (mas[i][2]<nMinLow) nMinLow=mas[i][2]; //low
if (mas[i][3]>nMaxHigh) nMaxHigh=mas[i][3]; //High
}
//
nClose=mas[k][4]; //Close
nPivot=(nMaxHigh+nMinLow+nClose)/3;
//
return(0);
}
int start()
{
/* double mas1[][6];
ArrayCopyRates(mas1,Symbol(), PERIOD_M1);
0 - time,
1 - open,
2 - low,
3 - high,
4 - close,
5 - volume.
*/
ArrayCopyRates(mas,Symbol(), PERIOD_M5); //M5
//----------------------------------------------
double PeriodHour_ = forEurope_periodRascheta_hour;
double hourMT4_ = forEurope_end_hourMT4;
double minuteMT4_ = forEurope_end_minuteMT4;
//
funPivot(PeriodHour_, hourMT4_, minuteMT4_);
//
double nPivotEurope = nPivot;
double nMaxHighE = nMaxHigh;
double nMinLowE = nMinLow;
double nCloseE = nClose;
//----------------------------------------------
PeriodHour_ = forUSA_periodRascheta_hour;
hourMT4_ = forUSA_end_hourMT4;
minuteMT4_ = forUSA_end_minuteMT4;
//
funPivot(PeriodHour_, hourMT4_, minuteMT4_);
//
double nPivotUSA = nPivot;
double nMaxHighU = nMaxHigh;
double nMinLowU = nMinLow;
double nCloseU = nClose;
//
if (nPivotEurope!=0 && nPivotUSA!=0 )
Comment( "\n","PivotEurope=",nPivotEurope,
", ","High=",nMaxHighE,
", ","Low=",nMinLowE,
", ","Close=",nCloseE,
"\n","PivotUSA =",nPivotUSA,
", ","High=",nMaxHighU,
", ","Low=",nMinLowU,
", ","Close=",nCloseU);
else
if (nPivotEurope!=0)
Comment( "\n","PivotEurope=",nPivotEurope,
" ","High=",nMaxHighE,
" ","Low=",nMinLowE,
", ","Close=",nCloseE);
return(0);
}
//+------------------------------------------------------------------+
Comments