This commit is contained in:
Pierre8rTeam
2018-04-06 20:55:57 +02:00
parent e317e4c330
commit f73c061349
96 changed files with 4266 additions and 0 deletions
+135
View File
@@ -0,0 +1,135 @@
//+------------------------------------------------------------------+
//| Pivot1.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
//--- plot Pivot
#property indicator_label1 "Pivot1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkOrange
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int Variant=2;
//--- indicator buffers
double PivotBuffer[];
double HighBuffer[];
double LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,PivotBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,LowBuffer,INDICATOR_CALCULATIONS);
//---
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=1;
if(prev_calculated==0)
{
start=1;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
PivotBuffer[i]=PivotBuffer[i-1];
HighBuffer[i]=HighBuffer[i-1];
LowBuffer[i]=LowBuffer[i-1];
if(NewDay(time[i],time[i-1],Variant))
{
PivotBuffer[i]=(HighBuffer[i]+LowBuffer[i]+close[i-1])/3;
HighBuffer[i]=high[i];
LowBuffer[i]=low[i];
}
HighBuffer[i]=MathMax(HighBuffer[i],high[i]);
LowBuffer[i]=MathMin(LowBuffer[i],low[i]);
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
{
switch(aVariant)
{
case 1:
return(NewDay1(aTimeCur,aTimePre));
break;
case 2:
return(NewDay2(aTimeCur,aTimePre));
break;
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay1(datetime aTimeCur,datetime aTimePre)
{
return((aTimeCur/86400)!=(aTimePre/86400));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay2(datetime aTimeCur,datetime aTimePre)
{
MqlDateTime stm;
//--- new day
if(NewDay1(aTimeCur,aTimePre))
{
TimeToStruct(aTimeCur,stm);
switch(stm.day_of_week)
{
case 6: // Saturday
return(false);
break;
case 0: // Sunday
return(true);
break;
case 1: // Monday
TimeToStruct(aTimePre,stm);
if(stm.day_of_week!=0)
{ // preceded by any day of the week other than Sunday
return(true);
}
else
{
return(false);
}
break;
default: // any other day of the week
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
+126
View File
@@ -0,0 +1,126 @@
//+------------------------------------------------------------------+
//| Pivot2.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots 1
//--- plot Pivot
#property indicator_label1 "Pivot2"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrDarkOrange
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int Hour=14;
input int Minute=0;
//--- indicator buffers
double PivotBuffer[];
double HighBuffer[];
double LowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,PivotBuffer,INDICATOR_DATA);
SetIndexBuffer(1,HighBuffer,INDICATOR_CALCULATIONS);
SetIndexBuffer(2,LowBuffer,INDICATOR_CALCULATIONS);
//---
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=1;
if(prev_calculated==0)
{
start=1;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
PivotBuffer[i]=PivotBuffer[i-1];
HighBuffer[i]=HighBuffer[i-1];
LowBuffer[i]=LowBuffer[i-1];
if(NewCustomDay(Hour,Minute,time[i],time[i-1]))
{
PivotBuffer[i]=(HighBuffer[i]+LowBuffer[i]+close[i-1])/3;
HighBuffer[i]=high[i];
LowBuffer[i]=low[i];
}
HighBuffer[i]=MathMax(HighBuffer[i],high[i]);
LowBuffer[i]=MathMin(LowBuffer[i],low[i]);
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewCustomDay(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
{
MqlDateTime stm;
if(TimeCross(aHour,aMinute,aTimeCur,aTimePre))
{
TimeToStruct(aTimeCur,stm);
if(stm.day_of_week==0 || stm.day_of_week==6)
{
return(false);
}
else
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
{
//--- specified time since the day start
datetime PointTime=aHour*3600+aMinute*60;
//--- current time since the day start
aTimeCur=aTimeCur%86400;
//--- previous time since the day start
aTimePre=aTimePre%86400;
if(aTimeCur<aTimePre)
{
//--- going past midnight
if(aTimeCur>=PointTime || aTimePre<PointTime)
{
return(true);
}
}
else
{
if(aTimeCur>=PointTime && aTimePre<PointTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
+106
View File
@@ -0,0 +1,106 @@
//+------------------------------------------------------------------+
//| Session.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 2
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Session
#property indicator_label1 "Session"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLime
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int StartHour=10;
input int StartMinute=0;
input int StopHour=14;
input int StopMinute=0;
//--- indicator buffers
double SessionBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
PlotIndexSetInteger(0,PLOT_ARROW,159);
//---
IndicatorSetInteger(INDICATOR_DIGITS,0);
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=0;
if(prev_calculated==0)
{
start=0;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
if(TimeSession(StartHour,StartMinute,StopHour,StopMinute,time[i]))
{
SessionBuffer[i]=1;
}
else
{
SessionBuffer[i]=EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
{
//--- session start time
int StartTime=3600*aStartHour+60*aStartMinute;
//--- session end time
int StopTime=3600*aStopHour+60*aStopMinute;
//--- current time in seconds since the day start
aTimeCur=aTimeCur%86400;
if(StopTime<StartTime)
{
//--- going past midnight
if(aTimeCur>=StartTime || aTimeCur<StopTime)
{
return(true);
}
}
else
{
//--- within one day
if(aTimeCur>=StartTime && aTimeCur<StopTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
+152
View File
@@ -0,0 +1,152 @@
//+------------------------------------------------------------------+
//| SessionWeek.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 2
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Session
#property indicator_label1 "SessionWeek"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrGray
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
enum EWeekDay
{
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6
};
//--- input parameters
input EWeekDay StartDay = Monday;
input int StartHour = 3;
input int StartMinute = 0;
input EWeekDay StopDay = Friday;
input int StopHour = 18;
input int StopMinute = 0;
bool WeekDays[7];
//--- indicator buffers
double SessionBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
PlotIndexSetInteger(0,PLOT_ARROW,159);
//---
IndicatorSetInteger(INDICATOR_DIGITS,0);
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=0;
if(prev_calculated==0)
{
start=0;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
if(WeekSession(StartDay,StartHour,StartMinute,StopDay,StopHour,StopMinute,time[i]))
{
SessionBuffer[i]=1;
}
else
{
SessionBuffer[i]=EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool WeekSession(int aStartDay,int aStartHour,int aStartMinute,int aStopDay,int aStopHour,int aStopMinute,datetime aTimeCur)
{
//--- session start time since the week start
int StartTime=aStartDay*86400+3600*aStartHour+60*aStartMinute;
//--- session end time since the week start
int StopTime=aStopDay*86400+3600*aStopHour+60*aStopMinute;
//--- current time in seconds since the week start
long TimeCur=SecondsFromWeekStart(aTimeCur,false);
if(StopTime<StartTime)
{
//--- passing the turn of the week
if(TimeCur>=StartTime || TimeCur<StopTime)
{
return(true);
}
}
else
{
//--- within one week
if(TimeCur>=StartTime && TimeCur<StopTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
long SecondsFromWeekStart(datetime aTime,bool aStartsOnMonday=false)
{
return(aTime-WeekStartTime(aTime,aStartsOnMonday));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
long WeekStartTime(datetime aTime,bool aStartsOnMonday=false)
{
long tmp=aTime;
long Corrector;
if(aStartsOnMonday)
{
Corrector=259200; // duration of three days (86400*3)
}
else
{
Corrector=345600; // duration of four days (86400*4)
}
tmp+=Corrector;
tmp=(tmp/604800)*604800;
tmp-=Corrector;
return(tmp);
}
//+------------------------------------------------------------------+
+124
View File
@@ -0,0 +1,124 @@
//+------------------------------------------------------------------+
//| sTestArea.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart(){
//--- Bar generation option: 1 - no weekend bars, 2 - 4 bars at the end of Sunday, 3 - all weekend bars, 4 - Saturday bars but no Sunday bars
int Variant=1;
//---
ObjectsDeleteAll(0);
color Colors[]={clrGreen,clrBlue,0,0,0,clrRed,clrMagenta};
int ColorIndex=-1;
datetime ta[];
int size=0;
int i;
switch(Variant){
case 1:
size=24*2;
ArrayResize(ta,size);
for(i=0;i<24;i++){
ta[i]=86400+i*3600;
}
for(i=24;i<size;i++){
ta[i]=86400*3+i*3600;
}
break;
case 2:
size=24*2+4;
ArrayResize(ta,size);
for(i=0;i<24;i++){
ta[i]=86400+i*3600;
}
ta[24]=86400*4-4*3600;
ta[25]=86400*4-3*3600;
ta[26]=86400*4-2*3600;
ta[27]=86400*4-1*3600;
for(i=28;i<size;i++){
ta[i]=86400*4+(i-28)*3600;
}
break;
case 3:
size=24*4;
ArrayResize(ta,size);
for(i=0;i<size;i++){
ta[i]=86400+i*3600;
}
break;
case 4:
size=24*3;
ArrayResize(ta,size);
for(i=0;i<48;i++){
ta[i]=86400+i*3600;
}
for(i=48;i<size;i++){
ta[i]=86400*2+i*3600;
}
break;
}
MqlDateTime stm;
for(i=0;i<size;i++){
TimeToStruct(ta[i],stm);
Label("Label_Time_"+(string)i,8*i,100,TimeToString(ta[i],TIME_MINUTES),Colors[stm.day_of_week],90,"Arial",7);
}
LikeOnCalculate(size,ta);
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Main experimental function
//+------------------------------------------------------------------+
void LikeOnCalculate(const int rates_total,const datetime & time[]){
for(int i=0;i<rates_total;i++){
SetMarker(i,0,clrChocolate);
SetMarker(i,1,clrLime);
}
}
//+------------------------------------------------------------------+
// Function for setting a marker |
// Parameters: aBarIndex - bar index, aBufferIndex - marker row |
// index, aColor - marker color |
//+------------------------------------------------------------------+
void SetMarker(int aBarIndex,int aBufferIndex,color aColor){
Label("Label_Marker_"+(string)aBufferIndex+"_"+(string)aBarIndex,8*aBarIndex+1,99+8*aBufferIndex,CharToString(110),aColor,0,"Wingdings",9);
}
//+------------------------------------------------------------------+
// Function for creating the OBJ_LABEL graphical object |
//+------------------------------------------------------------------+
void Label(
string aObjName = "ObjLabel",
int aX = 30,
int aY = 30,
string aText = "ObjLabel",
color aColor = clrRed,
double aAngle = 0,
string aFont = "Arial",
int aSize = 8
){
ObjectCreate(0,aObjName,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,aObjName,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
ObjectSetInteger(0,aObjName,OBJPROP_BACK,false);
ObjectSetInteger(0,aObjName,OBJPROP_COLOR,aColor);
ObjectSetInteger(0,aObjName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,aObjName,OBJPROP_FONTSIZE,aSize);
ObjectSetInteger(0,aObjName,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,aObjName,OBJPROP_SELECTED,false);
ObjectSetInteger(0,aObjName,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,aObjName,OBJPROP_XDISTANCE,aX);
ObjectSetInteger(0,aObjName,OBJPROP_YDISTANCE,aY);
ObjectSetString(0,aObjName,OBJPROP_TEXT,aText);
ObjectSetString(0,aObjName,OBJPROP_FONT,aFont);
ObjectSetDouble(0,aObjName,OBJPROP_ANGLE,aAngle);
}
+198
View File
@@ -0,0 +1,198 @@
//+------------------------------------------------------------------+
//| sTestArea_Pivot1.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//--- Bar generation option: 1 - no weekend bars, 2 - 4 bars at the end of Sunday, 3 - all weekend bars, 4 - Saturday bars but no Sunday bars
int Variant=1;
//---
ObjectsDeleteAll(0);
color Colors[]={clrGreen,clrBlue,0,0,0,clrRed,clrMagenta};
int ColorIndex=-1;
datetime ta[];
int size=0;
int i;
switch(Variant)
{
case 1:
size=24*2;
ArrayResize(ta,size);
for(i=0;i<24;i++)
{
ta[i]=86400+i*3600;
}
for(i=24;i<size;i++)
{
ta[i]=86400*3+i*3600;
}
break;
case 2:
size=24*2+4;
ArrayResize(ta,size);
for(i=0;i<24;i++)
{
ta[i]=86400+i*3600;
}
ta[24]=86400*4-4*3600;
ta[25]=86400*4-3*3600;
ta[26]=86400*4-2*3600;
ta[27]=86400*4-1*3600;
for(i=28;i<size;i++)
{
ta[i]=86400*4+(i-28)*3600;
}
break;
case 3:
size=24*4;
ArrayResize(ta,size);
for(i=0;i<size;i++)
{
ta[i]=86400+i*3600;
}
break;
case 4:
size=24*3;
ArrayResize(ta,size);
for(i=0;i<48;i++)
{
ta[i]=86400+i*3600;
}
for(i=48;i<size;i++)
{
ta[i]=86400*2+i*3600;
}
break;
}
MqlDateTime stm;
for(i=0;i<size;i++)
{
TimeToStruct(ta[i],stm);
//Alert(stm.day_of_week);
Label("Label_Time_"+(string)i,8*i,100,TimeToString(ta[i],TIME_MINUTES),Colors[stm.day_of_week],90,"Arial",7);
}
LikeOnCalculate(size,ta);
ChartRedraw(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Main experimental function
//+------------------------------------------------------------------+
void LikeOnCalculate(const int rates_total,const datetime &time[])
{
for(int i=1;i<rates_total;i++)
{
if(NewDay(time[i],time[i-1],2))
{
SetMarker(i,0,clrChocolate);
}
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
{
switch(aVariant)
{
case 1:
return(NewDay1(aTimeCur,aTimePre));
break;
case 2:
return(NewDay2(aTimeCur,aTimePre));
break;
}
return(false);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay1(datetime aTimeCur,datetime aTimePre)
{
return((aTimeCur/86400)!=(aTimePre/86400));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewDay2(datetime aTimeCur,datetime aTimePre)
{
MqlDateTime stm;
//--- new day
if(NewDay1(aTimeCur,aTimePre))
{
TimeToStruct(aTimeCur,stm);
switch(stm.day_of_week)
{
case 6: // Saturday
return(false);
break;
case 0: // Sunday
return(true);
break;
case 1: // Monday
TimeToStruct(aTimePre,stm);
if(stm.day_of_week!=0)
{ // preceded by any day of the week other than Sunday
return(true);
}
else
{
return(false);
}
break;
default: // any other day of the week
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
// Function for setting a marker |
// Parameters: aBarIndex - bar index, aBufferIndex - marker row |
// index, aColor - marker color |
//+------------------------------------------------------------------+
void SetMarker(int aBarIndex,int aBufferIndex,color aColor)
{
Label("Label_Marker_"+(string)aBufferIndex+"_"+(string)aBarIndex,8*aBarIndex+1,99+8*aBufferIndex,CharToString(110),aColor,0,"Wingdings",9);
}
//+------------------------------------------------------------------+
// Function for creating the OBJ_LABEL graphical object |
//+------------------------------------------------------------------+
void Label(
string aObjName = "ObjLabel",
int aX = 30,
int aY = 30,
string aText = "ObjLabel",
color aColor = clrRed,
double aAngle = 0,
string aFont = "Arial",
int aSize = 8
)
{
ObjectCreate(0,aObjName,OBJ_LABEL,0,0,0);
ObjectSetInteger(0,aObjName,OBJPROP_ANCHOR,ANCHOR_LEFT_UPPER);
ObjectSetInteger(0,aObjName,OBJPROP_BACK,false);
ObjectSetInteger(0,aObjName,OBJPROP_COLOR,aColor);
ObjectSetInteger(0,aObjName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
ObjectSetInteger(0,aObjName,OBJPROP_FONTSIZE,aSize);
ObjectSetInteger(0,aObjName,OBJPROP_SELECTABLE,true);
ObjectSetInteger(0,aObjName,OBJPROP_SELECTED,false);
ObjectSetInteger(0,aObjName,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
ObjectSetInteger(0,aObjName,OBJPROP_XDISTANCE,aX);
ObjectSetInteger(0,aObjName,OBJPROP_YDISTANCE,aY);
ObjectSetString(0,aObjName,OBJPROP_TEXT,aText);
ObjectSetString(0,aObjName,OBJPROP_FONT,aFont);
ObjectSetDouble(0,aObjName,OBJPROP_ANGLE,aAngle);
}
//+------------------------------------------------------------------+
+538
View File
@@ -0,0 +1,538 @@
//+------------------------------------------------------------------+
//| TimeFuncions.mqh |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
//+------------------------------------------------------------------+
//| Function for determining the time of the first bar on a lower time frame|
//| in a bar on a higher time frame |
//+------------------------------------------------------------------+
bool LowerTFFirstBarTime(string aSymbol,ENUM_TIMEFRAMES aLowerTF,datetime aUpperTFBarTime,datetime &aLowerTFFirstBarTime)
{
datetime tm[];
//--- determine the bar time on a lower time frame corresponding to the bar time on a higher time frame
if(CopyTime(aSymbol,aLowerTF,aUpperTFBarTime,1,tm)==-1)
{
return(false);
}
if(tm[0]<aUpperTFBarTime)
{
//--- we got the time of the preceding bar
datetime tm2[];
//--- determine the time of the last bar on a lower time frame
if(CopyTime(aSymbol,aLowerTF,0,1,tm2)==-1)
{
return(false);
}
if(tm[0]<tm2[0])
{
//--- there is a bar following the bar of a lower time frame
//--- that precedes the occurrence of the bar on a higher time frame
int start=Bars(aSymbol,aLowerTF,tm[0],tm2[0])-2;
//--- the Bars() function returns the number of bars, whereas we need to determine the index of the bar
//--- following the bar with time tm[0], so
//--- 2 is subtracted. 1 for getting the index of the bar
//--- with time tm[0] and 1 for getting the index
//--- of the following bar
if(CopyTime(aSymbol,aLowerTF,start,1,tm)==-1)
{
return(false);
}
}
else
{
//---there is no bar of a lower time frame contained
//--- in the bar on a higher time frame
aLowerTFFirstBarTime=0;
return(true);
}
}
//--- assign the obtained value to the variable
aLowerTFFirstBarTime=tm[0];
return(true);
}
//+------------------------------------------------------------------+
//| Function for determining the time of the last bar on a lower time frame|
//| in a bar on a higher time frame |
//+------------------------------------------------------------------+
bool LowerTFLastBarTime(string aSymbol,ENUM_TIMEFRAMES aUpperTF,ENUM_TIMEFRAMES aLowerTF,datetime aUpperTFBarTime,datetime &aLowerTFFirstBarTime)
{
//--- time of the next bar on a higher time frame
datetime NextBarTime=aUpperTFBarTime+PeriodSeconds(aUpperTF);
datetime tm[];
if(CopyTime(aSymbol,aLowerTF,NextBarTime,1,tm)==-1)
{
return(false);
}
if(tm[0]==NextBarTime)
{
//--- There is a bar on a lower time frame corresponding to the time of the next bar on a higher time frame.
//--- Determine the time of the last bar on a lower time frame
datetime tm2[];
if(CopyTime(aSymbol,aLowerTF,0,1,tm2)==-1)
{
return(false);
}
//--- determine the preceding bar index on a lower time frame
int start=Bars(aSymbol,aLowerTF,tm[0],tm2[0]);
//--- determine the time of this bar
if(CopyTime(aSymbol,aLowerTF,start,1,tm)==-1)
{
return(false);
}
}
//--- assign the obtained value to the variable
aLowerTFFirstBarTime=tm[0];
return(true);
}
//+------------------------------------------------------------------+
//| Normalization of time by bar length |
//+------------------------------------------------------------------+
datetime BarTimeNormalize(datetime aTime,ENUM_TIMEFRAMES aTimeFrame)
{
int BarLength=PeriodSeconds(aTimeFrame);
return(BarLength*(aTime/BarLength));
}
//+------------------------------------------------------------------+
//| Function for determining time in seconds since the day start |
//| aTime - time in seconds, |
//| int &aH, int &aM, int &aS - returns hours, |
//| minutes and seconds by reference |
//+------------------------------------------------------------------+
int TimeFromDayStart(datetime aTime,int &aH,int &aM,int &aS)
{
//--- Number of seconds elapsed since the day start (aTime%86400)
//--- divided by the number of seconds in an hour is the number of hours
aH=(int)((aTime%86400)/3600);
//--- Number of seconds elapsed since the last hour (aTime%3600)
//--- divided by the number of seconds in a minute is the number of minutes
aM=(int)((aTime%3600)/60);
//--- Number of seconds elapsed since the last minute
aS=(int)(aTime%60);
//--- Number of seconds since the day start
return(int(aTime%86400));
}
//+------------------------------------------------------------------+
//| Function for determining the number of the week since the beginning of the epoch|
//| datetime aTime - time, |
//| bool aStartsOnMonday=false - the week starts on Monday |
//+------------------------------------------------------------------+
long WeekNum(datetime aTime,bool aStartsOnMonday=false)
{
//--- if the week starts on Sunday, add the duration of 4 days (Wednesday+Tuesday+Monday+Sunday),
// if it starts on Monday, add 3 days (Wednesday, Tuesday, Monday)
if(aStartsOnMonday)
{
aTime+=259200; // duration of three days (86400*3)
}
else
{
aTime+=345600; // duration of four days (86400*4)
}
return(aTime/604800);
}
//+------------------------------------------------------------------+
//| Function for determining the time of the week start |
//| datetime aTime - time, |
//| bool aStartsOnMonday=false - the week starts on Monday |
//+------------------------------------------------------------------+
long WeekStartTime(datetime aTime,bool aStartsOnMonday=false)
{
long tmp=aTime;
long Corrector;
if(aStartsOnMonday)
{
Corrector=259200; // duration of three days (86400*3)
}
else
{
Corrector=345600; // duration of four days (86400*4)
}
tmp+=Corrector;
tmp=(tmp/604800)*604800;
tmp-=Corrector;
return(tmp);
}
//+------------------------------------------------------------------+
//| Function for determining the time in seconds since the week start|
//| datetime aTime - time, |
//| bool aStartsOnMonday=false - the week starts on Monday |
//+------------------------------------------------------------------+
long SecondsFromWeekStart(datetime aTime,bool aStartsOnMonday=false)
{
return(aTime-WeekStartTime(aTime,aStartsOnMonday));
}
//+------------------------------------------------------------------+
//| Function for determining the number of the week since a given date|
//| datetime aTime - time for which the number of the week is determined,|
//| datetime aStartTime - start time, |
//| bool aStartsOnMonday=false - the week starts on Monday |
//+------------------------------------------------------------------+
long WeekNumFromDate(datetime aTime,datetime aStartTime,bool aStartsOnMonday=false)
{
long Time,StartTime,Corrector;
MqlDateTime stm;
Time=aTime;
StartTime=aStartTime;
//--- determine the beginning of the reference epoch
StartTime=(StartTime/86400)*86400;
//--- determine the time that elapsed
//--- since the beginning of the reference epoch
Time-=StartTime;
//--- determine the day of the week of the beginning of the reference epoch
TimeToStruct(StartTime,stm);
//--- if the week starts on Monday,
//--- numbers of days of the week are decreased by 1 and
//--- the day with number 0 becomes a day with number 6
if(aStartsOnMonday)
{
if(stm.day_of_week==0)
{
stm.day_of_week=6;
}
else
{
stm.day_of_week--;
}
}
//--- calculate the value of the time corrector
Corrector=86400*stm.day_of_week;
//--- time correction
Time+=Corrector;
//--- calculate and return the number of the week
return(Time/604800);
}
//+------------------------------------------------------------------+
//| Determining the time of the year start |
//| datetime aTime - time |
//+------------------------------------------------------------------+
datetime YearStartTime(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
stm.day=1;
stm.mon=1;
stm.hour=0;
stm.min=0;
stm.sec=0;
return(StructToTime(stm));
}
//+------------------------------------------------------------------+
//| Determining the time of the month start |
//| datetime aTime - time |
//+------------------------------------------------------------------+
datetime MonthStartTime(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
stm.day=1;
stm.hour=0;
stm.min=0;
stm.sec=0;
return(StructToTime(stm));
}
//+------------------------------------------------------------------+
//| Function for determining the number of the week in a year |
//| datetime aTime - time, |
//| bool aStartsOnMonday=false - the week starts on Monday |
//+------------------------------------------------------------------+
long WeekNumYear(datetime aTime,bool aStartsOnMonday=false)
{
return(WeekNumFromDate(aTime,YearStartTime(aTime),aStartsOnMonday));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
long WeekNumMonth(datetime aTime,bool aStartsOnMonday=false)
{
return(WeekNumFromDate(aTime,MonthStartTime(aTime),aStartsOnMonday));
}
//+------------------------------------------------------------------+
//| Function for determining the new calendar day |
//| datetime aTimeCur - current time, |
//| datetime aTimePre - previous time, |
//+------------------------------------------------------------------+
bool NewDay1(datetime aTimeCur,datetime aTimePre)
{
return((aTimeCur/86400)!=(aTimePre/86400));
}
//+-------------------------------------------------------------------+
//| Function for determining the new day for quotes with a Sunday bar |
//| datetime aTimeCur - current time, |
//| datetime aTimePre - previous time, |
//+-------------------------------------------------------------------+
bool NewDay2(datetime aTimeCur,datetime aTimePre)
{
MqlDateTime stm;
//--- new day
if(NewDay1(aTimeCur,aTimePre))
{
TimeToStruct(aTimeCur,stm);
switch(stm.day_of_week)
{
case 6: // Saturday
return(false);
break;
case 0: // Sunday
return(true);
break;
case 1: // Monday
TimeToStruct(aTimePre,stm);
if(stm.day_of_week!=0)
{ // preceded by any day of the week other than Sunday
return(true);
}
else
{
return(false);
}
break;
default: // any other day of the week
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining the new day |
//| datetime aTimeCur - current time, |
//| datetime aTimePre - previous time, |
//| int aVariant=1 - 1 - calendar day as is, 2 - Sunday |
//| is treated as Monday |
//+------------------------------------------------------------------+
bool NewDay(datetime aTimeCur,datetime aTimePre,int aVariant=1)
{
switch(aVariant)
{
case 1:
return(NewDay1(aTimeCur,aTimePre));
break;
case 2:
return(NewDay2(aTimeCur,aTimePre));
break;
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining an intraday session |
//| int aStartHour - start hour, |
//| int aStartMinute - start minutes, |
//| int aStopHour - end hour, |
//| int aStopMinute - end minutes, |
//| datetime aTimeCur - current time |
//+------------------------------------------------------------------+
bool TimeSession(int aStartHour,int aStartMinute,int aStopHour,int aStopMinute,datetime aTimeCur)
{
//--- session start time
int StartTime=3600*aStartHour+60*aStartMinute;
//--- session end time
int StopTime=3600*aStopHour+60*aStopMinute;
//--- current time in seconds since the day start
aTimeCur=aTimeCur%86400;
if(StopTime<StartTime)
{
//--- going past midnight
if(aTimeCur>=StartTime || aTimeCur<StopTime)
{
return(true);
}
}
else
{
//--- within one day
if(aTimeCur>=StartTime && aTimeCur<StopTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining the occurrence of a given point of time |
//| int aHour - day start hour, |
//| int aMinute - day start minutes, |
//| datetime aTimeCur - current time, |
//| datetime aTimePre - previous time |
//+------------------------------------------------------------------+
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
{
//--- specified time since the day start
datetime PointTime=aHour*3600+aMinute*60;
//--- current time since the day start
aTimeCur=aTimeCur%86400;
//--- previous time since the day start
aTimePre=aTimePre%86400;
if(aTimeCur<aTimePre)
{
//--- going past midnight
if(aTimeCur>=PointTime || aTimePre<PointTime)
{
return(true);
}
}
else
{
if(aTimeCur>=PointTime && aTimePre<PointTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining the start of a new user-defined day |
//| int aHour - day start hour, |
//| int aMinute - day start minutes, |
//| datetime aTimeCur - current time, |
//| datetime aTimePre - previous time |
//+------------------------------------------------------------------+
bool NewCustomDay(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
{
MqlDateTime stm;
if(TimeCross(aHour,aMinute,aTimeCur,aTimePre))
{
TimeToStruct(aTimeCur,stm);
if(stm.day_of_week==0 || stm.day_of_week==6)
{
return(false);
}
else
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Variables for the WeekDays_Check() function |
//+------------------------------------------------------------------+
input bool Sunday = true; // Sunday
input bool Monday = true; // Monday
input bool Tuesday = true; // Tuesday
input bool Wednesday = true; // Wednesday
input bool Thursday = true; // Thursday
input bool Friday = true; // Friday
input bool Saturday = true; // Saturday
bool WeekDays[7];
//+------------------------------------------------------------------+
//| Function for the preparation of an array for the WeekDays_Check() function|
//+------------------------------------------------------------------+
void WeekDays_Init()
{
WeekDays[0]=Sunday;
WeekDays[1]=Monday;
WeekDays[2]=Tuesday;
WeekDays[3]=Wednesday;
WeekDays[4]=Thursday;
WeekDays[5]=Friday;
WeekDays[6]=Saturday;
}
//+------------------------------------------------------------------+
//| Checking the day of the week |
//| datetime aTime - time for which we check whether |
//| a certain day of the week is allowed |
//+------------------------------------------------------------------+
bool WeekDays_Check(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
return(WeekDays[stm.day_of_week]);
}
//+------------------------------------------------------------------+
//| Function for determining a trading session within a week |
//| int aStartDay - day of the week of the session start, |
//| int aStartHour - session start hour, |
//| int aStartMinute - session start minutes, |
//| int aStopDay - day of the week of the session end, |
//| int aStopHour - session end hour, |
//| int aStopMinute - session end minutes, |
//| aTimeCur - time that we check for being or not being |
//| within the session |
//+------------------------------------------------------------------+
bool WeekSession(int aStartDay,int aStartHour,int aStartMinute,int aStopDay,int aStopHour,int aStopMinute,datetime aTimeCur)
{
//--- session start time since the week start
int StartTime=aStartDay*86400+3600*aStartHour+60*aStartMinute;
//--- session end time since the week start
int StopTime=aStopDay*86400+3600*aStopHour+60*aStopMinute;
//--- current time in seconds since the week start
long TimeCur=SecondsFromWeekStart(aTimeCur,false);
if(StopTime<StartTime)
{
//--- passing the turn of the week
if(TimeCur>=StartTime || TimeCur<StopTime)
{
return(true);
}
}
else
{
//--- within one week
if(TimeCur>=StartTime && TimeCur<StopTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining the leap year by date |
//| aTime - date-time |
//+------------------------------------------------------------------+
bool LeapYear(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
//--- a multiple of 4
if(stm.year%4==0)
{
//--- a multiple of 100
if(stm.year%100==0)
{
//--- a multiple of 400
if(stm.year%400==0)
{
return(true);
}
}
//--- not a multiple of 100
else
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
//| Function for determining the number of days in a month by date |
//| aTime - date-time |
//+------------------------------------------------------------------+
int DaysInMonth(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
if(stm.mon==2)
{
//--- February
if(LeapYear(aTime))
{
//--- February in a leap year
return(29);
}
else
{
//--- February in a non-leap year
return(28);
}
}
else
{
//--- other months
return(31-((stm.mon-1)%7)%2);
}
}
//+------------------------------------------------------------------+
+100
View File
@@ -0,0 +1,100 @@
//+------------------------------------------------------------------+
//| TimePoint.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//--- plot TimePoint
#property indicator_label1 "TimePoint"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input int Hour=14;
input int Minute=0;
//--- indicator buffers
double TimePointBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,TimePointBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
PlotIndexSetInteger(0,PLOT_ARROW,169);
PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,10);
//---
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=1;
if(prev_calculated==0)
{
start=1;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
if(TimeCross(Hour,Minute,time[i],time[i-1]))
{
TimePointBuffer[i]=low[i];
}
else
{
TimePointBuffer[i]=EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool TimeCross(int aHour,int aMinute,datetime aTimeCur,datetime aTimePre)
{
//--- specified time since the day start
datetime PointTime=aHour*3600+aMinute*60;
//--- current time since the day start
aTimeCur=aTimeCur%86400;
//--- previous time since the day start
aTimePre=aTimePre%86400;
if(aTimeCur<aTimePre)
{
//--- going past midnight
if(aTimeCur>=PointTime || aTimePre<PointTime)
{
return(true);
}
}
else
{
if(aTimeCur>=PointTime && aTimePre<PointTime)
{
return(true);
}
}
return(false);
}
//+------------------------------------------------------------------+
+105
View File
@@ -0,0 +1,105 @@
//+------------------------------------------------------------------+
//| TradeWeekDays.mq5 |
//| Copyright 2011, MetaQuotes Software Corp. |
//| http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2011, MetaQuotes Software Corp."
#property link "http://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 2
#property indicator_buffers 1
#property indicator_plots 1
//--- plot Session
#property indicator_label1 "TradeWeekDays"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- input parameters
input bool Sunday = false; // Sunday
input bool Monday = false; // Monday
input bool Tuesday = true; // Tuesday
input bool Wednesday = true; // Wednesday
input bool Thursday = true; // Thursday
input bool Friday = false; // Friday
input bool Saturday = false; // Saturday
bool WeekDays[7];
//--- indicator buffers
double SessionBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
WeekDays_Init();
//--- indicator buffers mapping
SetIndexBuffer(0,SessionBuffer,INDICATOR_DATA);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
PlotIndexSetInteger(0,PLOT_ARROW,159);
//---
IndicatorSetInteger(INDICATOR_DIGITS,0);
return(0);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start=0;
if(prev_calculated==0)
{
start=0;
}
else
{
start=prev_calculated-1;
}
for(int i=start;i<rates_total;i++)
{
if(WeekDays_Check(time[i]))
{
SessionBuffer[i]=1;
}
else
{
SessionBuffer[i]=EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void WeekDays_Init()
{
WeekDays[0]=Sunday;
WeekDays[1]=Monday;
WeekDays[2]=Tuesday;
WeekDays[3]=Wednesday;
WeekDays[4]=Thursday;
WeekDays[5]=Friday;
WeekDays[6]=Saturday;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool WeekDays_Check(datetime aTime)
{
MqlDateTime stm;
TimeToStruct(aTime,stm);
return(WeekDays[stm.day_of_week]);
}
//+------------------------------------------------------------------+