Miscellaneous
0
Views
0
Downloads
0
Favorites
mtf_slope
//+------------------------------------------------------------------+
//| Slope Trend_mtf.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_color1 ForestGreen
#property indicator_color2 Red
#property indicator_color3 ForestGreen
#property indicator_color4 Red
#property indicator_color5 ForestGreen
#property indicator_color6 Red
#property indicator_color7 ForestGreen
#property indicator_color8 Red
#property indicator_minimum 0
#property indicator_maximum 5
//---- input parameters
extern int SlopeTF1=1440;
extern int SlopeTF2=240;
extern int SlopeTF3=60;
extern int SlopeTF4=30;
extern int SlopePeriod=80;
extern int SlopeMethod=3;
extern int SlopePrice=0;
extern int nBars=300;
extern int Code=110;
extern int text_shift=10;
extern color text_col=DodgerBlue;
extern string font_name="Arial";
extern int font_size=4;
extern int Complect=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
double ExtMapBuffer8[];
bool downloadhistory = false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,Code);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,Code);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,Code);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,Code);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,Code);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW);
SetIndexArrow(5,Code);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW);
SetIndexArrow(6,Code);
SetIndexBuffer(6,ExtMapBuffer7);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW);
SetIndexArrow(7,Code);
SetIndexBuffer(7,ExtMapBuffer8);
SetIndexEmptyValue(7,0.0);
SetIndexLabel(0,NULL);
SetIndexLabel(1,NULL);
SetIndexLabel(2,NULL);
SetIndexLabel(3,NULL);
SetIndexLabel(4,NULL);
SetIndexLabel(5,NULL);
SetIndexLabel(6,NULL);
SetIndexLabel(7,NULL);
IndicatorShortName("Slope Trend "+(Complect+1));
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("TF1 "+Complect);
ObjectDelete("TF2 "+Complect);
ObjectDelete("TF3 "+Complect);
ObjectDelete("TF4 "+Complect);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
int limit, b, b1;
double ma, ma1;
string period1, period2, period3, period4;
if(nBars>Bars) nBars=Bars;
if(counted_bars == 0 && downloadhistory)
{
ArrayInitialize(ExtMapBuffer1, 0.0);
ArrayInitialize(ExtMapBuffer2, 0.0);
ArrayInitialize(ExtMapBuffer3, 0.0);
ArrayInitialize(ExtMapBuffer4, 0.0);
ArrayInitialize(ExtMapBuffer5, 0.0);
ArrayInitialize(ExtMapBuffer6, 0.0);
ArrayInitialize(ExtMapBuffer7, 0.0);
ArrayInitialize(ExtMapBuffer8, 0.0);
}
if(counted_bars == 0) downloadhistory = true;
//----
limit=nBars-1;
//----
for(int i=limit; i>=0; i--)
{
if(Period()>SlopeTF1)
{
ma=iCustom(NULL,SlopeTF1,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i);
ma1=iCustom(NULL,SlopeTF1,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i+1);
}
else
{
b=iBarShift(NULL,SlopeTF1,iTime(NULL,0,i),false);
b1=iBarShift(NULL,SlopeTF1,iTime(NULL,0,i+1),false);
ma=iCustom(NULL,SlopeTF1,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b);
ma1=iCustom(NULL,SlopeTF1,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b1);
}
if(ma>ma1)
{
ExtMapBuffer1[i]=4.0;
ExtMapBuffer2[i]=0.0;
}
else
if(ma<ma1)
{
ExtMapBuffer1[i]=0.0;
ExtMapBuffer2[i]=4.0;
}
else
if(ma==ma1)
{
if(ExtMapBuffer1[i+1]!=0.0)
{
ExtMapBuffer1[i]=4.0;
ExtMapBuffer2[i]=0.0;
}
else
if(ExtMapBuffer2[i+1]!=0.0)
{
ExtMapBuffer1[i]=0.0;
ExtMapBuffer2[i]=4.0;
}
}
//----
if(Period()>SlopeTF2)
{
ma=iCustom(NULL,SlopeTF2,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i);
ma1=iCustom(NULL,SlopeTF2,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i+1);
}
else
{
b=iBarShift(NULL,SlopeTF2,iTime(NULL,0,i),false);
b1=iBarShift(NULL,SlopeTF2,iTime(NULL,0,i+1),false);
ma=iCustom(NULL,SlopeTF2,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b);
ma1=iCustom(NULL,SlopeTF2,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b1);
}
if(ma>ma1)
{
ExtMapBuffer3[i]=3.0;
ExtMapBuffer4[i]=0.0;
}
else
if(ma<ma1)
{
ExtMapBuffer3[i]=0.0;
ExtMapBuffer4[i]=3.0;
}
else
if(ma==ma1)
{
if(ExtMapBuffer3[i+1]!=0.0)
{
ExtMapBuffer3[i]=3.0;
ExtMapBuffer4[i]=0.0;
}
else
if(ExtMapBuffer4[i+1]!=0.0)
{
ExtMapBuffer3[i]=0.0;
ExtMapBuffer4[i]=3.0;
}
}
//----
if(Period()>SlopeTF3)
{
ma=iCustom(NULL,SlopeTF3,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i);
ma1=iCustom(NULL,SlopeTF3,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i+1);
}
else
{
b=iBarShift(NULL,SlopeTF3,iTime(NULL,0,i),false);
b1=iBarShift(NULL,SlopeTF3,iTime(NULL,0,i+1),false);
ma=iCustom(NULL,SlopeTF3,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b);
ma1=iCustom(NULL,SlopeTF3,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b1);
}
if(ma>ma1)
{
ExtMapBuffer5[i]=2.0;
ExtMapBuffer6[i]=0.0;
}
else
if(ma<ma1)
{
ExtMapBuffer5[i]=0.0;
ExtMapBuffer6[i]=2.0;
}
else
if(ma==ma1)
{
if(ExtMapBuffer5[i+1]!=0.0)
{
ExtMapBuffer5[i]=2.0;
ExtMapBuffer6[i]=0.0;
}
else
if(ExtMapBuffer6[i+1]!=0.0)
{
ExtMapBuffer5[i]=0.0;
ExtMapBuffer6[i]=2.0;
}
}
//----
if(Period()>SlopeTF4)
{
ma=iCustom(NULL,SlopeTF4,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i);
ma1=iCustom(NULL,SlopeTF4,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,i+1);
}
else
{
b=iBarShift(NULL,SlopeTF4,iTime(NULL,0,i),false);
b1=iBarShift(NULL,SlopeTF4,iTime(NULL,0,i+1),false);
ma=iCustom(NULL,SlopeTF4,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b);
ma1=iCustom(NULL,SlopeTF4,"Slope Line",SlopePeriod,SlopeMethod,SlopePrice,0,b1);
}
if(ma>ma1)
{
ExtMapBuffer7[i]=1.0;
ExtMapBuffer8[i]=0.0;
}
else
if(ma<ma1)
{
ExtMapBuffer7[i]=0.0;
ExtMapBuffer8[i]=1.0;
}
else
if(ma==ma1)
{
if(ExtMapBuffer7[i+1]!=0.0)
{
ExtMapBuffer7[i]=1.0;
ExtMapBuffer8[i]=0.0;
}
else
if(ExtMapBuffer8[i+1]!=0.0)
{
ExtMapBuffer7[i]=0.0;
ExtMapBuffer8[i]=1.0;
}
}
}
//----
switch (SlopeTF1)
{
case 1:
period1 = "M1";
break;
case 5:
period1 = "M5";
break;
case 15:
period1 = "M15";
break;
case 30:
period1 = "M30";
break;
case 60:
period1 = "H1";
break;
case 240:
period1 = "H4";
break;
case 1440:
period1 = "D1";
break;
case 10080:
period1 = "W1";
break;
case 43200:
period1 = "MN";
break;
}
//----
switch (SlopeTF2)
{
case 1:
period2 = "M1";
break;
case 5:
period2 = "M5";
break;
case 15:
period2 = "M15";
break;
case 30:
period2 = "M30";
break;
case 60:
period2 = "H1";
break;
case 240:
period2 = "H4";
break;
case 1440:
period2 = "D1";
break;
case 10080:
period2 = "W1";
break;
case 43200:
period2 = "MN";
break;
}
//----
switch (SlopeTF3)
{
case 1:
period3 = "M1";
break;
case 5:
period3 = "M5";
break;
case 15:
period3 = "M15";
break;
case 30:
period3 = "M30";
break;
case 60:
period3 = "H1";
break;
case 240:
period3 = "H4";
break;
case 1440:
period3 = "D1";
break;
case 10080:
period3 = "W1";
break;
case 43200:
period3 = "MN";
break;
}
//----
switch (SlopeTF4)
{
case 1:
period4 = "M1";
break;
case 5:
period4 = "M5";
break;
case 15:
period4 = "M15";
break;
case 30:
period4 = "M30";
break;
case 60:
period4 = "H1";
break;
case 240:
period4 = "H4";
break;
case 1440:
period4 = "D1";
break;
case 10080:
period4 = "W1";
break;
case 43200:
period4 = "MN";
break;
}
//----
int indicatorWindow = WindowFind("Slope Trend "+(Complect+1));
ObjectDelete("TF1 "+Complect);
ObjectCreate("TF1 "+Complect, OBJ_TEXT, indicatorWindow, Time[0]+text_shift*Period()*60, 4.00);
ObjectSetText("TF1 "+Complect, period1, font_size, font_name, text_col);
ObjectDelete("TF2 "+Complect);
ObjectCreate("TF2 "+Complect, OBJ_TEXT, indicatorWindow, Time[0]+text_shift*Period()*60, 3.00);
ObjectSetText("TF2 "+Complect, period2, font_size, font_name, text_col);
ObjectDelete("TF3 "+Complect);
ObjectCreate("TF3 "+Complect, OBJ_TEXT, indicatorWindow, Time[0]+text_shift*Period()*60, 2.00);
ObjectSetText("TF3 "+Complect, period3, font_size, font_name, text_col);
ObjectDelete("TF4 "+Complect);
ObjectCreate("TF4 "+Complect, OBJ_TEXT, indicatorWindow, Time[0]+text_shift*Period()*60, 1.00);
ObjectSetText("TF4 "+Complect, period4, font_size, font_name, text_col);
//----
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
---