Price Data Components
Miscellaneous
0
Views
0
Downloads
0
Favorites
3_Candles
//+------------------------------------------------------------------+
//| 3 Candles.mq4 |
//| Copyright 2016, Tor |
//| http://einvestor.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Tor"
#property link "http://einvestor.ru/"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
input int maxBar1=300;// Max Bar #1 size for disable Volume filter, pips
input bool CheckVolume=true;// Volume filter disable/enable
input bool alerts=true;// Alerts disable/enable
double up[],down[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,up);
SetIndexBuffer(1,down);
IndicatorShortName("3 Candles");
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,clrBlue);//Buy
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1,clrRed);//Sell
SetIndexArrow(0,233);
SetIndexArrow(1,234);
SetIndexLabel(0,"Buy");
SetIndexLabel(1,"Sell");
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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 limit;
static bool alrt=false;
static datetime altime=0;
//---
if(rates_total<=1){ return(0); }
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit=limit+4;
for(int x=limit-3; x>=0; x--)
{
bool chkVol=true;
up[x]=EMPTY_VALUE;
down[x]=EMPTY_VALUE;
if((iHigh(_Symbol,_Period,x+3)-iLow(_Symbol,_Period,x+3))/_Point>maxBar1){ chkVol=false; }
if(iOpen(_Symbol,_Period,x+3)<iClose(_Symbol,_Period,x+3) && iOpen(_Symbol,_Period,x+2)<iClose(_Symbol,_Period,x+2) &&
iClose(_Symbol,_Period,x+2)<iHigh(_Symbol,_Period,x+3) && iOpen(_Symbol,_Period,x+1)>iClose(_Symbol,_Period,x+1) &&
iClose(_Symbol,_Period,x+1)<iOpen(_Symbol,_Period,x+2))
{
if(CheckVolume && chkVol)
{
if((iVolume(_Symbol,_Period,x+3)<iVolume(_Symbol,_Period,x+2)) ||
((iVolume(_Symbol,_Period,x+1)>iVolume(_Symbol,_Period,x+2)) || (iVolume(_Symbol,_Period,x+1)>iVolume(_Symbol,_Period,x+3))))
{
down[x]=iOpen(_Symbol,_Period,x);
}
}else{
down[x]=iOpen(_Symbol,_Period,x);
}
}
if(iOpen(_Symbol,_Period,x+3)>iClose(_Symbol,_Period,x+3) && iOpen(_Symbol,_Period,x+2)>iClose(_Symbol,_Period,x+2) &&
iClose(_Symbol,_Period,x+2)>iLow(_Symbol,_Period,x+3) && iOpen(_Symbol,_Period,x+1)<iClose(_Symbol,_Period,x+1) &&
iClose(_Symbol,_Period,x+1)>iOpen(_Symbol,_Period,x+2))
{
if(CheckVolume && chkVol)
{
if((iVolume(_Symbol,_Period,x+3)<iVolume(_Symbol,_Period,x+2)) ||
((iVolume(_Symbol,_Period,x+1)>iVolume(_Symbol,_Period,x+2)) || (iVolume(_Symbol,_Period,x+1)>iVolume(_Symbol,_Period,x+3))))
{
up[x]=iOpen(_Symbol,_Period,x);
}
}else{
up[x]=iOpen(_Symbol,_Period,x);
}
}
}
if(down[0]!=EMPTY_VALUE && down[0]>0)
{
if(alerts && Time[0]!=altime)
{
Alert("Signal Sell "+_Symbol+" TF "+(string)_Period);
altime=Time[0];
}
}
if(up[0]!=EMPTY_VALUE && up[0]>0)
{
if(alerts && Time[0]!=altime)
{
Alert("Signal Buy "+_Symbol+" TF "+(string)_Period);
altime=Time[0];
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---