Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MTF-Env-2B
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2012, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
/*------------------------------------------------------------------+
| MTF-Env-2B.mq4 |
| Copyright © 2011 |
| basisforex@gmail.com |
+------------------------------------------------------------------*/
#property copyright "Copyright © 2011, basisforex@gmail.com"
#property link "basisforex@gmail.com"
//----------------------------------------
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 White
#property indicator_color2 White
#property indicator_color3 Yellow
#property indicator_color4 Yellow
#property indicator_color5 Brown
#property indicator_color6 Brown
#property indicator_color7 Blue
#property indicator_color8 Blue
//-------------------------------------
extern bool TimeFrame2 = true;
extern bool TimeFrame3 = true;
extern bool TimeFrame4 = true;
//-----
extern int ma_period =13;
extern int ma_method=0;// 0 - 3
extern int ma_shift =0;
extern int applied_price=0;// 0 - 6
//-----
extern double deviation1=0.1;// Percent deviation from the main line.
extern double deviation2 = 0.2;
extern double deviation3 = 0.3;
extern double deviation4 = 0.4;
//-----
double s1[];
double s2[];
double s3[];
double s4[];
double s5[];
double s6[];
double s7[];
double s8[];
//+------------------------------------------------------------------+
int init()
{
if(Period()>240)
{
Print("Too large timeframe");
return(INIT_FAILED);
}
SetIndexBuffer(0,s1);
SetIndexBuffer(1,s2);
SetIndexBuffer(2,s3);
SetIndexBuffer(3,s4);
SetIndexBuffer(4,s5);
SetIndexBuffer(5,s6);
SetIndexBuffer(6,s7);
SetIndexBuffer(7,s8);
//-----
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexStyle(3,DRAW_LINE);
SetIndexStyle(4,DRAW_LINE);
SetIndexStyle(5,DRAW_LINE);
SetIndexStyle(6,DRAW_LINE);
SetIndexStyle(7,DRAW_LINE);
//-----
return(0);
}
//+------------------------------------------------------------------+
string GetNextTF(int curTF)
{
switch(curTF)
{
case 1:
return("5=15#30");
break;
case 5:
return("15=30#60");
break;
case 15:
return("30=60#240");
break;
case 30:
return("60=240#1440");
break;
case 60:
return("240=1440#10080");
break;
case 240:
return("1440=10080#43200");
break;
}
}
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//-----
string T= GetNextTF(Period());
int tf2 = StrToDouble(StringSubstr(T, 0, StringFind(T, "=", 0)));
int tf3 = StrToDouble(StringSubstr(T, StringFind(T, "=", 0) + 1, StringFind(T, "#", 0)));
int tf4 = StrToDouble(StringSubstr(T, StringFind(T, "#", 0) + 1, StringLen(T)));
int tf = Period();
if(tf>0 && tf2>0 && tf3>0 && tf4>0)
{
//-----
for(int i=limit-1; i>=0; i--)
{
//=============================================== __________________________________________________ st1 & st2 & st3 & st4
if(TimeFrame2==true && TimeFrame3==true && TimeFrame4==true)
{
Comment(Period()," White","\n",tf2," Yellow","\n",tf3," Brown","\n",tf4," Blue");
// iEnvelopes(NULL, 0, 13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0);
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s3[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_UPPER, i / (tf2 / tf));
s4[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_LOWER, i / (tf2 / tf));
s5[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_UPPER, i / (tf3 / tf));
s6[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_LOWER, i / (tf3 / tf));
s7[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_UPPER, i / (tf4 / tf));
s8[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_LOWER, i / (tf4 / tf));
}
//=============================================== __________________________________________________ st1 & st2 & st3
else if(TimeFrame2==true && TimeFrame3==true && TimeFrame4==false)
{
Comment(Period()," White","\n",tf2," Yellow","\n",tf3," Brown");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s3[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_UPPER, i / (tf2 / tf));
s4[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_LOWER, i / (tf2 / tf));
s5[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_UPPER, i / (tf3 / tf));
s6[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_LOWER, i / (tf3 / tf));
}
//=============================================== __________________________________________________ st1 & st2 & st4
else if(TimeFrame2==true && TimeFrame3==false && TimeFrame4==true)
{
Comment(Period()," White","\n",tf2," Yellow","\n",tf4," Blue");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s3[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_UPPER, i / (tf2 / tf));
s4[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_LOWER, i / (tf2 / tf));
s7[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_UPPER, i / (tf4 / tf));
s8[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_LOWER, i / (tf4 / tf));
}
//=============================================== __________________________________________________ st1 & st3 & st4
else if(TimeFrame2==false && TimeFrame3==true && TimeFrame4==true)
{
Comment(Period()," White","\n",tf3," Brown","\n",tf4," Blue");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s5[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_UPPER, i / (tf3 / tf));
s6[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_LOWER, i / (tf3 / tf));
s7[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_UPPER, i / (tf4 / tf));
s8[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_LOWER, i / (tf4 / tf));
}
//=============================================== __________________________________________________ st1 & st2
else if(TimeFrame2==true && TimeFrame3==false && TimeFrame4==false)
{
Comment(Period()," White","\n",tf2," Yellow");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s3[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_UPPER, i / (tf2 / tf));
s4[i] = iEnvelopes(NULL, tf2, ma_period, ma_method, ma_shift, applied_price, deviation2, MODE_LOWER, i / (tf2 / tf));
}
//=============================================== __________________________________________________ st1 & st3
else if(TimeFrame2==false && TimeFrame3==true && TimeFrame4==false)
{
Comment(Period()," White","\n",tf3," Brown");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s5[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_UPPER, i / (tf3 / tf));
s6[i] = iEnvelopes(NULL, tf3, ma_period, ma_method, ma_shift, applied_price, deviation3, MODE_LOWER, i / (tf3 / tf));
}
//=============================================== __________________________________________________ st1 & st4
else if(TimeFrame2==false && TimeFrame3==false && TimeFrame4==true)
{
Comment(Period()," White","\n",tf4," Blue");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
s7[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_UPPER, i / (tf4 / tf));
s8[i] = iEnvelopes(NULL, tf4, ma_period, ma_method, ma_shift, applied_price, deviation4, MODE_LOWER, i / (tf4 / tf));
}
//=============================================== __________________________________________________ st1
else if(TimeFrame2==false && TimeFrame3==false && TimeFrame4==false)
{
Comment(Period()," White");
s1[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_UPPER, i);
s2[i] = iEnvelopes(NULL, 0, ma_period, ma_method, ma_shift, applied_price, deviation1, MODE_LOWER, i);
}
}
}
//==============================================================================================================================================
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
---