Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
SuperTrend_005
//+------------------------------------------------------------------+
//| Supertrend.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color3 Red
#property indicator_color4 Lime
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
double TrendUp[];
double TrendDown[];
double Up[];
double Down[];
extern int st = 10;
//extern int SlowerEMA = 6;
extern bool arrows = true ;
extern bool Sound.Alert = true ;
double alertBar;
//+------------------------------------------------------------------+
//| Custom indicator initialization function|
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID);
SetIndexBuffer(1, TrendDown);
SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(2, 234);
SetIndexBuffer(2, Up);
SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID);
SetIndexArrow(3, 233);
SetIndexBuffer(3, Down);
/*SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 159);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 159);
SetIndexBuffer(1, TrendDown);
for(int i = 0; i < Bars; i++) {
TrendUp[i] = NULL;
TrendDown[i] = NULL;
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function|
//+------------------------------------------------------------------+
int deinit()
{
//----
/*for(int i = 0; i < Bars; i++) {
TrendUp[i] = NULL;
TrendDown[i] = NULL;
}*/
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function|
//+------------------------------------------------------------------+
int start()
{
int limit, i, counter;
double Range, AvgRange, cciTrendNow, cciTrendPrevious, var;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0) return(-1);
//---- last counted bar will be recounted
if(counted_bars > 0) counted_bars--;
limit=Bars-counted_bars;
for(i = limit; i >= 0; i--) {
cciTrendNow = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
cciTrendPrevious = iCCI(NULL, 0, 50, PRICE_TYPICAL, i+1);
//st = st * 100;
counter = i;
Range = 0;
AvgRange = 0;
for (counter = i; counter >= i-9; counter--) {
AvgRange = AvgRange + MathAbs(High[counter]-Low[counter]);
}
Range = AvgRange/10;
if (cciTrendNow >= st && cciTrendPrevious < st) {
TrendUp[i+1] = TrendDown[i+1];
if(arrows == true && Up[i] != 0) Down[i] = TrendUp[i+1];
if(Sound.Alert == true && i == 0 && Down[i]!=0 && Down[i] != EMPTY_VALUE && Bars>alertBar) {Alert("SuperTrend Alert Up " + Symbol() + " on the " + Period() + " minute chart ");alertBar = Bars;}
}
if (cciTrendNow <= st && cciTrendPrevious > st) {
TrendDown[i+1] = TrendUp[i+1];
if(arrows == true && Up[i] != 0) Up[i] = TrendDown[i+1];
if(Sound.Alert == true && i == 0 && Up[i]!=0 && Up[i] != EMPTY_VALUE && Bars>alertBar) {Alert("SuperTrend Alert Down " + Symbol() + " on the " + Period() + " minute chart ");alertBar = Bars;}
}
if (cciTrendNow >= st) {
TrendUp[i] = Low[i] - iATR(NULL, 0, 5, i);
if (TrendUp[i] < TrendUp[i+1]) {
TrendUp[i] = TrendUp[i+1];
}
}
else if (cciTrendNow <= st) {
TrendDown[i] = High[i] + iATR(NULL, 0, 5, i);
if (TrendDown[i] > TrendDown[i+1]) {
TrendDown[i] = TrendDown[i+1];
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
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
---