Indicators Used
0
Views
0
Downloads
0
Favorites
SuperTrend_Clean_mtf_001
//+------------------------------------------------------------------+
//| mladen SuperTrend Clean.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
extern string timeFrame = "Current time frame";
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
//
//
//
//
//
double Trend[];
double TrendDown[];
double UpDown[];
int TimeFrame;
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Trend);
SetIndexBuffer(1, TrendDown);
SetIndexBuffer(2, UpDown);
SetIndexLabel(0,"SuperTrend");
SetIndexLabel(1,NULL);
//
//
//
//
//
TimeFrame = stringToTimeFrame(timeFrame);
IndicatorShortName("SuperTrend "+TimeFrameToString(TimeFrame));
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
int limit,i;
double cciTrend;
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
limit = Bars-counted_bars;
//
//
// MTF mode operating
//
//
if (TimeFrame != Period())
{
limit = MathMax(limit,TimeFrame/Period());
datetime TimeArray[];
ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame);
//
//
//
//
//
for(i=0,int y=0; i<limit; i++) {
if(Time[i]<TimeArray[y]) y++;
Trend[i] = iCustom(NULL,TimeFrame,"SuperTrend_Clean_mtf",0,y);
TrendDown[i] = iCustom(NULL,TimeFrame,"SuperTrend_Clean_mtf",1,y);
}
return(0);
}
//
//
//
//
//
for(i = limit; i >= 0; i--) {
cciTrend = iCCI(NULL, 0, 50, PRICE_TYPICAL, i);
//
//
//
//
//
if(UpDown[i+1]==1) TrendDown[i+1] = EMPTY_VALUE;
TrendDown[i] = EMPTY_VALUE;
if (cciTrend > 0){ Trend[i] = MathMax(Low[i] - iATR(NULL, 0, 5, i),Trend[i+1]); UpDown[i] = 1; }
else { Trend[i] = MathMin(High[i] + iATR(NULL, 0, 5, i),Trend[i+1]); UpDown[i] = -1;
TrendDown[i] = Trend[i];
TrendDown[i+1] = Trend[i+1];
}
}
return(0);
}
//+------------------------------------------------------------------+
//|
//+------------------------------------------------------------------+
int stringToTimeFrame(string tfs)
{
int tf=0;
tfs = StringUpperCase(tfs);
if (tfs=="M1" || tfs=="1") tf=PERIOD_M1;
if (tfs=="M5" || tfs=="5") tf=PERIOD_M5;
if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15;
if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30;
if (tfs=="H1" || tfs=="60") tf=PERIOD_H1;
if (tfs=="H4" || tfs=="240") tf=PERIOD_H4;
if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1;
if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
if (tf<Period()) tf=Period();
return(tf);
}
string TimeFrameToString(int tf)
{
string tfs="Current time frame";
switch(tf) {
case PERIOD_M1: tfs="M1" ; break;
case PERIOD_M5: tfs="M5" ; break;
case PERIOD_M15: tfs="M15" ; break;
case PERIOD_M30: tfs="M30" ; break;
case PERIOD_H1: tfs="H1" ; break;
case PERIOD_H4: tfs="H4" ; break;
case PERIOD_D1: tfs="D1" ; break;
case PERIOD_W1: tfs="W1" ; break;
case PERIOD_MN1: tfs="MN1";
}
return(tfs);
}
//
//
//
//
//
string StringUpperCase(string str)
{
string s = str;
int lenght = StringLen(str) - 1;
int char;
while(lenght >= 0)
{
char = StringGetChar(s, lenght);
//
//
//
//
//
if((char > 96 && char < 123) || (char > 223 && char < 256))
s = StringSetChar(s, lenght, char - 32);
else
if(char > -33 && char < 0)
s = StringSetChar(s, lenght, char + 224);
lenght--;
}
//
//
//
//
//
return(s);
}
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
---