Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
SuperTrend_32_001
//+------------------------------------------------------+\\
//| SuperTrend_3.mq4 Release 20061022-1 |\\
//| Copyright © 2005-2006, jnrtrading (Jason Robinson) |\\
//| Contact @ http://www.spreadtrade2win.com/forum/ |\\
//+------------------------------------------------------+\\
#property copyright "Copyright © 2005, Jason Robinson (jnrtrading)."
#property link "http://www.jnrtrading.co.uk"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 MediumSeaGreen
#property indicator_color2 Crimson
double TrendUp[], TrendDown[], MA[];
double MA1, MA2;
bool trendIsUp;
extern int Nb_Periods = 10;
extern double Multiplier = 2;
/*extern bool Automatic_Timeframe_Settings = false;
extern int M1_Nb_Periods = 10;
extern int M5_Nb_Periods = 10;
extern int M15_Nb_Periods = 12;
extern int M30_Nb_Periods = 10;
extern int H1_Nb_Periods = 10;
extern int H4_Nb_Periods = 10;
extern int D1_Nb_Periods = 10;
extern int W1_Nb_Periods = 10;
extern int MN_Nb_Periods = 10;*/
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(3);
SetIndexBuffer(0, TrendUp);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
SetIndexBuffer(1, TrendDown);
SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, j, shift;
//double Price3;
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;
if (Multiplier == 0) Multiplier = 0.1;
for (i = limit; i >= 0; i--) {
MA1 = iMA(NULL, 0, Nb_Periods*Multiplier, 0, MODE_EMA, PRICE_TYPICAL, i);
MA2 = iMA(NULL, 0, Nb_Periods*Multiplier, 0, MODE_EMA, PRICE_TYPICAL, i+Nb_Periods);
if (MA1 >= MA2) {
if (TrendDown[i+Nb_Periods+1] != EMPTY_VALUE && TrendUp[i+Nb_Periods+2] != EMPTY_VALUE) {
TrendDown[i+Nb_Periods+1] = EMPTY_VALUE;
TrendUp[i+Nb_Periods+1] = TrendUp[i+Nb_Periods+2];
}
TrendUp[i+Nb_Periods] = Low[i+Nb_Periods]-iATR(NULL,1,18,i);
TrendDown[i+Nb_Periods] = EMPTY_VALUE;
if(TrendDown[i+Nb_Periods+1] != EMPTY_VALUE) TrendUp[i+Nb_Periods+1] = TrendDown[i+Nb_Periods+1];
if (TrendUp[i+Nb_Periods] < TrendUp[i+Nb_Periods+1] && TrendUp[i+Nb_Periods+1] != TrendDown[i+Nb_Periods+1]) TrendUp[i+Nb_Periods] = TrendUp[i+Nb_Periods+1];
trendIsUp = true;
}
else if (MA1 <= MA2) {
if (TrendUp[i+Nb_Periods+1] != EMPTY_VALUE && TrendDown[i+Nb_Periods+2] != EMPTY_VALUE) {
TrendUp[i+Nb_Periods+1] = EMPTY_VALUE;
TrendDown[i+Nb_Periods+1] = TrendDown[i+Nb_Periods+2];
}
TrendDown[i+Nb_Periods] = High[i+Nb_Periods]+iATR(NULL,1,18,i);
TrendUp[i+Nb_Periods] = EMPTY_VALUE;
if(TrendUp[i+Nb_Periods+1] != EMPTY_VALUE) TrendDown[i+Nb_Periods+1] = TrendUp[i+Nb_Periods+1];
if (TrendDown[i+Nb_Periods] > TrendDown[i+Nb_Periods+1] && TrendDown[i+Nb_Periods+1] != TrendUp[i+Nb_Periods+1]) TrendDown[i+Nb_Periods] = TrendDown[i+Nb_Periods+1];
trendIsUp = false;
}
}
// Fill the gap at the end
if (trendIsUp == true) {
//Comment("Trend Is Up");
for (j = Nb_Periods; j > 0; j--) {
TrendUp[j] = Low[j]-Point*(Digits*2);
if (TrendUp[j] < TrendUp[j+1]) {TrendUp[j] = TrendUp[j+1];}
}
}
else {
//Comment("Trend Is Down");
for (j = Nb_Periods; j > 0; j--) {
TrendDown[j] = High[j]+Point*(Digits*2);
if (TrendDown[j] > TrendDown[j+1]) {TrendDown[j] = TrendDown[j+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
---