This is a Custom D1 Candle Pattern Indicator
It looked fairly easy at first but has turned out to be anything but.
If someone could look it over and tell me what I'm doing wrong.
The rules are simple.
To generate an UP arrow
Wait for a bull candle to CLOSE above the HIGH of the last and lowest closed bear candle.
after an up arrow we are in search of a down arrow.
To generate a down arrow
Wait for a bear candle to CLOSE below the LOW of the last and highest closed bull candle
after a down arrow we are in search of an up arrow.
repeat.
This is what I've come up with. See code for comments. I have also attached a screenshot.
Code: Select all
//+------------------------------------------------------------------+
//| FXPT_CC.mq4 |
//| Developed by fxprotrader |
//| http://www.fxpro-trader.com" |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2013, fxprotrader"
#property link "http://www.fxpro-trader.com"
//Description:
//Up=Wait for a bull candle to CLOSE above the HIGH of the last and lowest closed bear candle.
//Dwn=Wait for a bear candle to CLOSE below the LOW of the last and highest closed bull candle
//
//-------- HISTORY----------------
// v0.1 Initial release(02172013)
//--------------------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 LimeGreen
#property indicator_width1 2
#property indicator_width2 2
string FileName="FXPT_PAAlert";
extern int ArrowLoc = 20;//arrow location
extern int BarsBack = 8;//scan back how many bars
extern int MaxBars = 50;//limit to X Bars on main loop
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double Poin;
int lastFr = 2; //2 : neutral / 1 : up / 0 : down
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
if (Point == 0.00001) Poin = 0.0001;
else if (Point == 0.001) Poin = 0.01;
else Poin = Point;
//----
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,0,2);
SetIndexArrow(0,234);
SetIndexStyle(1,DRAW_ARROW,0,2);
SetIndexArrow(1,233);
//----
SetIndexEmptyValue(0,0.0);
SetIndexEmptyValue(1,0.0);
//---- name for DataWindow
SetIndexLabel(0,"Signal Up");
SetIndexLabel(1,"Signal Down");
string short_name = FileName;
IndicatorShortName(short_name);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit(){
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
int x,i,nCountedBars;
//temp clear out all
for (i=0;i<=1000;i++){
ExtMapBuffer2[i]=0.0;
ExtMapBuffer1[i]=0.0;
}
i=MaxBars;
double LowestHigh,HighestLow;
while(i>=0){
bool FrUp=true;
bool FrDn=true;
//---up green---//
if(Open[i] < Close[i]){
LowestHigh=0.0;
//loop thru last x-find lowest high
for (x=(i);x<= i+(BarsBack);x++){
if(Open[x] > Close[x]){
if(High[x-1] < High[x]){
//check for last given signal if false set High to LowestHigh
if(ExtMapBuffer2[x]==0){
LowestHigh=High[x];
}
else{
break;
}
}
}
}
//set arrow if close gtr than last lowest high
if(Close[i] > LowestHigh){
if (FrUp && lastFr != 1){
ExtMapBuffer2[i]=Low[i]-(ArrowLoc*Poin);
lastFr = 1;
FrDn =false;
}
}
}
//---dn red---//
else if(Open[i] > Close[i]){
HighestLow=0;
//loop thru last x-find highest low
for (x=(i-1);x<= i+(BarsBack-1);x++){
if(Open[x]< Close[x]){
if( Low[x-1] < Low[x]){
//check for last given signal if false set Low to HighestLow
if(ExtMapBuffer1[x-1]==0){
HighestLow=Low[x];
}
else{
break;
}
}
}
}
//set arrow if close lt than last highest low
if(Close[i]< HighestLow){
if (FrDn && lastFr != 0){
ExtMapBuffer1[i]=High[i]+(ArrowLoc*Poin);
lastFr = 0;
FrUp=false;
}
}
}
i--;
}
return(0);
}
FXPT_CC.mq4
The signals are correct between 12.21 and 02.04. Signals should also have been triggered on the other small yellow arrows.
chmarketscom2.PNG |