//+------------------------------------------------------------------+
//| Pinbar AHA 0.1.mq4 |
//| Copyright ?2006, Hua Ai (aha) |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2006, Hua Ai (aha)"
#property link ""
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Yellow
#property indicator_color2 Yellow
#property indicator_color3 Magenta
#property indicator_color4 Magenta
#property indicator_width1 0.5
#property indicator_width2 0.5
#property indicator_width3 1.0
#property indicator_width4 1.0
//---- input parameters
extern bool CheckPinBars=true;
extern bool CheckI4Bars=true;
extern int Min_Nose_Ratio=60;
extern int Max_Body_Ratio=40;
//---- buffers
double PPB[]; //Positive Pin Bar
double NPB[]; //Negative Pin Bar
double I4BTop[];
double I4BBottom[];
bool startup;
bool upalert,downalert;
bool timetocheck;
bool timetoverify;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,74);
SetIndexBuffer(0,NPB);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,74);
SetIndexBuffer(1,PPB);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,249);
SetIndexBuffer(2,I4BTop);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,249);
SetIndexBuffer(3,I4BBottom);
SetIndexEmptyValue(3,0.0);
//----
startup=true;
clearmarks(PPB, NPB);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
startup=false;
clearmarks(PPB, NPB);
//----
return(0);
}
// Determine the check time based on the chart period
void CheckTime(bool& check, bool& verify)
{
switch (Period())
{
case PERIOD_M1:
case PERIOD_M5:
case PERIOD_M15:
break;
case PERIOD_M30:
if ((Minute()>28 && Seconds()>50) || startup) check=true;
if ((Minute()<5 && Seconds()<10) || startup) verify=true;
break;
case PERIOD_H1:
//Print("I am in H1!");
if ((Minute()>58 && Seconds()>50) || startup) check=true;
if ((Minute()<10 && Seconds()<10) || startup) verify=true;
//Print("check=", check);
break;
case PERIOD_H4:
if ((MathMod(Hour(),4)==3 && Minute()>58 && Seconds()>50) || startup) check=true;
if ((MathMod(Hour(),4)==0 && Minute()<10 && Seconds()<10) || startup) verify=true;
break;
case PERIOD_D1:
if ((Hour()==23 && Minute()>58 && Seconds()>50) || startup) check=true;
if ((Hour()==0 && Minute()<10 && Seconds()<10) || startup) verify=true;
break;
case PERIOD_W1:
if ((DayOfWeek()==5 && Hour()==19 && Minute()>58 && Seconds()>50) || startup) check=true;
if ((DayOfWeek()==0 && Hour()==20 && Minute()<10 && Seconds()<10) || startup) verify=true;
break;
case PERIOD_MN1:
if ((Day()>=28 && Hour()==23 && Minute()>58 && Seconds()>50) || startup) check=true;
if ((Day()==0 && Hour()==0 && Minute()<10 && Seconds()<10) || startup) verify=true;
break;
default:
//Print("I am in default!");
check=false;
verify=false;
break;
}
//Print("check=", check);
return;
}
double CalRange(int bar_num, bool verify=false)
{
int counter, n=0;
double Range, AvgRange;
if (verify) n=1;
AvgRange=0;
for (counter=bar_num-n; counter<=bar_num+1;counter++)
{
AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
}
Range=AvgRange/2;
return(Range);
}
void clearmarks(double& PPB[], double& NPB[])
{
for (int i=0; i<= Bars-1; i++)
{
PPB[i]=0;
NPB[i]=0;
I4BTop[i]=0;
I4BBottom[i]=0;
}
return;
}
void CheckNPB(int bar_num, double& NPB[], bool verify=false)
{
double bar_length, nose_length, body_length, eye_pos;
bar_length = High[bar_num]-Low[bar_num];
nose_length = High[bar_num]-MathMax(Open[bar_num], Close[bar_num]);
body_length = MathAbs(Open[bar_num]-Close[bar_num]);
//Print("nose_length/bar_length=", nose_length/bar_length);
//Print("Min_Nose_Ratio/100=", Min_Nose_Ratio/100.0);
if( nose_length/bar_length > Min_Nose_Ratio/100.0 &&
body_length/bar_length < Max_Body_Ratio/100.0 )
{
NPB[bar_num]=High[bar_num]+0.1*CalRange(bar_num, verify);
//Print("Got a negative pin!");
}
return;
}
void CheckPPB(int bar_num, double& PPB[], bool verify=false)
{
double bar_length, nose_length, body_length, eye_pos;
bar_length = High[bar_num]-Low[bar_num];
nose_length = MathMin(Open[bar_num], Close[bar_num])-Low[bar_num];
body_length = MathAbs(Open[bar_num]-Close[bar_num]);
if( nose_length/bar_length > Min_Nose_Ratio/100.0 &&
body_length/bar_length < Max_Body_Ratio/100.0 )
{
PPB[bar_num]=Low[bar_num]-0.1*CalRange(bar_num, verify);
//Print("Got a positive pin!");
}
return;
}
void CheckI4B(int bar_num, double& I4BTop[], double& I4BBottom[], bool verify=false)
{
int dayintheweek=TimeDayOfWeek(iTime(NULL, 0, bar_num));
int bar_0, bar_1, bar_2, bar_3;
double bar_length_0, bar_length_1, bar_length_2, bar_length_3;
if (Period()==PERIOD_D1)
{
switch(dayintheweek)
{
case 4:
case 5:
bar_0 = bar_num;
bar_1 = bar_num+1;
bar_2 = bar_num+2;
bar_3 = bar_num+3;
break;
case 3:
bar_0 = bar_num;
bar_1 = bar_num+1;
bar_2 = bar_num+2;
bar_3 = bar_num+4;
break;
case 2:
bar_0 = bar_num;
bar_1 = bar_num+1;
bar_2 = bar_num+3;
bar_3 = bar_num+4;
break;
case 1:
bar_0 = bar_num;
bar_1 = bar_num+2;
bar_2 = bar_num+3;
bar_3 = bar_num+4;
break;
default:
bar_0 = bar_num;
bar_1 = bar_num;
bar_2 = bar_num;
bar_3 = bar_num;
break;
}
}
else
{
bar_0 = bar_num;
bar_1 = bar_num+1;
bar_2 = bar_num+2;
bar_3 = bar_num+3;
}
bar_length_0 = High[bar_0]-Low[bar_0];
bar_length_1 = High[bar_1]-Low[bar_1];
bar_length_2 = High[bar_2]-Low[bar_2];
bar_length_3 = High[bar_3]-Low[bar_3];
//Print("nose_length/bar_length=", nose_length/bar_length);
//Print("Min_Nose_Ratio/100=", Min_Nose_Ratio/100.0);
if( bar_length_0<bar_length_1 && bar_length_0<bar_length_2 &&
bar_length_0<bar_length_3 && High[bar_0]<High[bar_1] &&
Low[bar_0]>Low[bar_1])
{
I4BTop[bar_num]=High[bar_num]+0.1*CalRange(bar_num, verify);
I4BBottom[bar_num]=Low[bar_num]-0.1*CalRange(bar_num, verify);
//Print("Got a I4B bar!");
//Print("dayintheweek=", dayintheweek);
}
return;
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
int i;
bool timetocheck=false;
bool timetoverify=false;
//Print("dayintheweek=", DayOfWeek());
CheckTime(timetocheck, timetoverify);
if (startup)
{
//Print("I am in startup!");
for(i=Bars-1; i>=1; i--)
{
if(CheckPinBars)
{
CheckPPB(i, PPB, true);
CheckNPB(i, NPB, true);
}
if(CheckI4Bars)
CheckI4B(i, I4BTop, I4BBottom, true);
}
}
if (timetocheck)
{
//Print("I am checking!");
if(CheckPinBars)
{
CheckPPB(0, PPB);
CheckNPB(0, NPB);
}
if(CheckI4Bars)
CheckI4B(0, I4BTop, I4BBottom);
}
if (timetoverify)
{
//Print("I am verifying!");
if(CheckPinBars)
{
CheckPPB(1, PPB, true);
CheckNPB(1, NPB, true);
}
if(CheckI4Bars)
CheckI4B(1, I4BTop, I4BBottom, true);
}
startup=false;
//----
return(0);
}
//+------------------------------------------------------------------+
Comments