Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Directed_Movement_Alert
//+------------------------------------------------------------------+
//| Directed Movement Alert.mq4 |
//| Yuriy Tokman (YTG) |
//| http://ytg.com.ua/ |
//+------------------------------------------------------------------+
#property copyright "Yuriy Tokman (YTG)"
#property link "http://ytg.com.ua/"
#property version "2.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color2 Red
#property indicator_color3 Lime
#property indicator_color4 Yellow
#property indicator_color5 Aqua
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1
#property indicator_width5 1
#property indicator_level1 30.0
#property indicator_level2 70.0
//----
extern int PERIOD=5;
extern double up_line = 70;
extern double dn_line = 30;
extern bool Alerts = true;
extern string Text_BUY = "BUY signal text";
extern string Text_SELL = "SELL signals text";
extern bool Send_Mail = false;
extern string subject = "subject text";
extern bool Send_Notification = false;
//---- buffers
double BU0[];
double BU1[];
double BU2[];
double BU3[];
double BU4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorShortName("Directed Movement "+DoubleToStr(PERIOD,0));
SetIndexBuffer(0, BU0);
SetIndexStyle(0, DRAW_NONE);
SetIndexBuffer(1, BU1);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,PERIOD*4);
SetIndexBuffer(2, BU2);
SetIndexStyle(2, DRAW_LINE);
SetIndexDrawBegin(2,PERIOD*4);
SetIndexBuffer(3, BU3);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,108);
SetIndexDrawBegin(3,PERIOD*4);
SetIndexBuffer(4, BU4);
SetIndexStyle(4, DRAW_ARROW);
SetIndexArrow(4,108);
SetIndexDrawBegin(4,PERIOD*4);
//---
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=rates_total - prev_calculated;
if(prev_calculated==0)limit--;
else limit++;
//----
if(prev_calculated==0)limit=Bars-PERIOD*2;
for(int i=0; i<limit && !IsStopped(); i++)
BU0[i] = iRSI(Symbol(),0,PERIOD,0,i);
//----
for(int i=0; i<limit && !IsStopped(); i++)
BU1[i] = iMAOnArray(BU0,0,PERIOD,0,0,i);
//----
for(int i=0; i<limit && !IsStopped(); i++)
BU2[i] = iMAOnArray(BU1,0,PERIOD,0,0,i);
//----
for(int i=0; i<limit && !IsStopped(); i++)
{
if(BU1[i+2]>=BU2[i+2] && BU1[i+1]<BU2[i+1] && BU2[i+2]>=up_line)
BU3[i+1] = BU2[i+1];
if(BU1[i+2]<=BU2[i+2] && BU1[i+1]>BU2[i+1] && BU2[i+2]<=dn_line)
BU4[i+1] = BU2[i+1];
}
//----
if(NewBar())
{
if(BU4[1]>0 && BU4[1]<99999)
{
if(Alerts)Alert(Text_BUY);
if(Send_Mail)SendMail(subject,Text_BUY);
if(Send_Notification)SendNotification(Text_BUY);
}
if(BU3[1]>0 && BU3[1]<99999)
{
if(Alerts)Alert(Text_SELL);
if(Send_Mail)SendMail(subject,Text_SELL);
if(Send_Notification)SendNotification(Text_SELL);
}
}
//----
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
bool NewBar(int TF = 0)
{
static datetime NewTime=0;
if(NewTime!=iTime(Symbol(),TF,0))
{
NewTime=iTime(Symbol(),TF,0);
return(true);
}
return(false);
}
//----
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
---