Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
ATRStops_v11.1 + alert
//+------------------------------------------------------------------+
//| ATRStops_v1.mq4 |
//| Copyright © 2006, Forex-TSD.com |
//| Written by IgorAD,igorad2003@yahoo.co.uk |
//| http://finance.groups.yahoo.com/group/TrendLaboratory |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Forex-TSD.com "
#property link "http://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Magenta
//---- input parameters
extern int Length=7;
extern int ATRperiod=9;
extern double Kv=2.5;
extern bool Alerts.On = false;
extern bool Alerts.OnCurrent = false;
extern bool Alerts.Message = true;
extern bool Alerts.Sound = false;
extern bool Alerts.Email = false;
//---- indicator buffers
double UpBuffer1[];
double DnBuffer1[];
double smin[];
double smax[];
double trend[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
IndicatorBuffers(5);
SetIndexBuffer(0,UpBuffer1);
SetIndexBuffer(1,DnBuffer1);
SetIndexBuffer(2,smin);
SetIndexBuffer(3,smax);
SetIndexBuffer(4,trend);
//---- name for DataWindow and indicator subwindow label
short_name="ATRStops("+Length+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"Up");
SetIndexLabel(1,"Dn");
//----
SetIndexDrawBegin(0,Length);
SetIndexDrawBegin(1,Length);
//----
return(0);
}
//+------------------------------------------------------------------+
//| ATRStops_v1 |
//+------------------------------------------------------------------+
int start()
{
int shift,limit, counted_bars=IndicatorCounted();
if ( counted_bars > 0 ) limit=Bars-counted_bars;
if ( counted_bars < 0 ) return(0);
if ( counted_bars ==0 ) limit=Bars-Length-1;
for(shift=limit;shift>=0;shift--)
{
smin[shift] = -100000; smax[shift] = 100000;
for (int i = Length-1;i>=0;i--)
{
smin[shift] = MathMax( smin[shift], High[shift+i] - Kv*iATR(NULL,0,ATRperiod,shift+i));
smax[shift] = MathMin( smax[shift], Low[shift+i] + Kv*iATR(NULL,0,ATRperiod,shift+i));
}
trend[shift]=trend[shift+1];
if ( Close[shift] > smax[shift+1] ) trend[shift] = 1;
if ( Close[shift] < smin[shift+1] ) trend[shift] = -1;
if ( trend[shift] >0 )
{
if( smin[shift]<smin[shift+1] ) smin[shift]=smin[shift+1];
UpBuffer1[shift]=smin[shift];
DnBuffer1[shift] = EMPTY_VALUE;
}
if ( trend[shift] <0 )
{
if( smax[shift]>smax[shift+1] ) smax[shift]=smax[shift+1];
UpBuffer1[shift]=EMPTY_VALUE;
DnBuffer1[shift] = smax[shift];
}
}
//
//
//
//
//
if (Alerts.On)
{
if (Alerts.OnCurrent)
int forBar = 1;
else forBar = 0;
Comment(trend[forBar]+" "+trend[forBar+1]);
if (trend[forBar]!=trend[forBar+1])
{
if (trend[forBar] > 0) doAlert("UP");
if (trend[forBar] < 0) doAlert("DOWN");
}
}
return(0);
}
//
//
//
//
//
void doAlert(string doWhat)
{
static string previousAlert="nothing";
static datetime previousTime;
string message;
if (previousAlert != doWhat || previousTime != Time[0]) {
previousAlert = doWhat;
previousTime = Time[0];
//
//
//
//
//
message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Atr stops trend changed to ",doWhat);
if (Alerts.Message) Alert(message);
if (Alerts.Email) SendMail(doWhat,message);
if (Alerts.Sound) PlaySound("alert2.wav");
}
}
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
---