Indicators Used
0
Views
0
Downloads
0
Favorites
MA Scan
//+------------------------------------------------------------------+
//| MA Scan.mq4 |
//| Copyright © 2010, Simon Kaufmann |
//| |
//+------------------------------------------------------------------+
// best placed on a 1 minute chart to get most frequent updates
#property copyright "Copyright © 2010, Simon Kaufmann"
#property link ""
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
extern string MA_Settings = "----------------------------------------------------------------------";
extern int MA1 = 13;
extern int MA2 = 21;
extern int MA3 = 34;
extern int MA4 = 55;
extern string Channel_Settings = "----------------------------------------------------------------------";
extern int Channel = 3;
extern string GUI_Settings = "----------------------------------------------------------------------";
extern color textcolor = Snow;
extern int textsize = 8;
extern color Long_Consolidated = Lime;
extern color Short_Consolidated = Red;
extern color Long = Green;
extern color Short = Crimson;
bool Monitor = true;
string objprefix = "MA-SCAN-";
string indi_name = "MA Scan";
string symbol[] = {
"AUDCAD", "AUDCHF","AUDJPY","AUDNZD","AUDUSD","CADJPY","CHFJPY","EURAUD","EURCAD","EURCHF","EURGBP","EURJPY","EURNZD","EURUSD","GBPCAD","GBPCHF","GBPJPY","GBPNZD","GBPUSD","NZDCHF","NZDJPY","NZDUSD","USDCAD","USDCHF","USDJPY"};
string tf_text[] = {"M1", "M5", "M15", "H1"};
int timeframe[] = {PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_H1};
int window;
static bool done;
int xoffset=75;
int yoffset=20;
int x, y, spacingx, spacingy;
datetime ctime, prevtime;
double iMA1,iMA2,iMA3,iMA4;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorShortName(indi_name);
string AddChar = StringSubstr(Symbol(),6,4);
for (int cc = 0; cc <= ArraySize(symbol); cc++)
{
symbol[cc] = StringConcatenate(symbol[cc], AddChar);
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
deleteObjects();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
initGraph();
scan();
done = true;
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Custom indicator delete objects function |
//+------------------------------------------------------------------+
void deleteObjects()
{
for(int i=ObjectsTotal();i >= 0;i--)
{
if(StringSubstr(ObjectName(i),0,StringLen(objprefix))==objprefix)
ObjectDelete(ObjectName(i));
}
}
//----------------------------------------
void initGraph()
{
if (done) { return; }
spacingx = textsize*7;
spacingy = textsize+8;
// draw up table of symbols and tf_text
for (int i = 0; i < ArraySize(symbol); i++)
{
x = xoffset+(spacingx*i);
objectCreate(symbol[i],x, 5, symbol[i],textsize,"Arial",textcolor);
for (int j = 0; j < ArraySize(timeframe); j++)
{
objectReset(symbol[i]+DoubleToStr(timeframe[j],0),x+10,y,Gray);
}
}
// draw timeframe headers
for (int k = 0; k < ArraySize(timeframe); k++)
{
y = yoffset + (spacingy*k);
objectCreate(tf_text[k],15,y,tf_text[k],textsize,"Arial",textcolor);
}
done = true;
}
//+------------------------------------------------------------------+
void objectCreate(string name,int x,int y,string text="-",int size=42,
string font="Arial",color colour=CLR_NONE)
{
ObjectCreate(objprefix+name,OBJ_LABEL,WindowFind(indi_name),0,0);
ObjectSet(objprefix+name,OBJPROP_CORNER,0);
ObjectSet(objprefix+name,OBJPROP_COLOR,colour);
ObjectSet(objprefix+name,OBJPROP_XDISTANCE,x);
ObjectSet(objprefix+name,OBJPROP_YDISTANCE,y);
ObjectSetText(objprefix+name,text,size,font,colour);
}
void objectReset(string name,int i,int j,color colour=CLR_NONE)
{
x = xoffset+(spacingx*i); y = yoffset+(spacingy*j);
if (ObjectFind(name)>0) { ObjectDelete(name); }
objectCreate(name,x+10,y,CharToStr(152),textsize,"Wingdings 2",colour);
}
//----------------------------------------
void scan()
{
ctime = Time[0];
if (ctime == prevtime) { return(0); }
prevtime = ctime;
// loop through array of symbols
for ( int i = 0; i< ArraySize(symbol); i++)
{
// loop through timeframes
for (int j = 0; j < ArraySize(timeframe); j++)
{
iMA1 = iMA(symbol[i],timeframe[j],MA1,0,MODE_EMA,PRICE_CLOSE,0);
iMA2 = iMA(symbol[i],timeframe[j],MA2,0,MODE_EMA,PRICE_CLOSE,0);
iMA3 = iMA(symbol[i],timeframe[j],MA3,0,MODE_EMA,PRICE_CLOSE,0);
iMA4 = iMA(symbol[i],timeframe[j],MA4,0,MODE_EMA,PRICE_CLOSE,0);
double point =MarketInfo(symbol[i],MODE_POINT);
double digits =MarketInfo(symbol[i],MODE_DIGITS);
double mult=(digits==3 || digits==5)*10+(digits==2 || digits==4);
double ChannelWidth = NormalizeDouble(Channel*point*mult,digits);
// If MA are within a certain range of each other
if ( Monitor == True )
{
if (iMA1 > iMA2 && iMA2 > iMA3 && iMA3 > iMA4) { objectReset(symbol[i]+DoubleToStr(timeframe[j],0),i,j,Green); }
if ((iMA1 > iMA2 && iMA2 > iMA3 && iMA3 > iMA4)&&(MathAbs(iMA1-iMA4)<ChannelWidth)) { objectReset(symbol[i]+DoubleToStr(timeframe[j],0),i,j,Lime); }
if (iMA4 > iMA3 && iMA3 > iMA2 && iMA2 > iMA1) { objectReset(symbol[i]+DoubleToStr(timeframe[j],0),i,j,Crimson); }
if ((iMA4 > iMA3 && iMA3 > iMA2 && iMA2 > iMA1)&&(MathAbs(iMA1-iMA4)<ChannelWidth)) { objectReset(symbol[i]+DoubleToStr(timeframe[j],0),i,j,Red); }
}
else
{
objectReset(symbol[i]+DoubleToStr(timeframe[j],0),i,j,Gray);
}
}
}
}
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
---