Okay, here's a breakdown of what this MetaTrader script does, explained in plain language for someone who isn't a programmer:
This script is designed to display a small, customizable panel on your trading chart. This panel gives you a quick visual summary of the direction of three popular trading indicators developed by Bill Williams: the Awesome Oscillator (AO), the Accelerator Oscillator (AC), and the MACD.
Here's how it works, step by step:
-
Initial Setup:
- The script starts by defining some settings, which you can adjust to personalize the panel. These settings include:
- MACD parameters: Settings to configure the MACD calculation like fast EMA, slow EMA and signal SMA.
- Panel Location: Where on the chart the panel should appear (X and Y coordinates, and which corner of the chart to anchor it to).
- Panel Appearance: Colors for the text, background, and the "up" or "down" direction indicators, as well as the text size. You can choose between two color themes (light and dark).
- Spacing: How far apart each indicator's row should be.
- The script starts by defining some settings, which you can adjust to personalize the panel. These settings include:
-
Indicator Calculation:
- The script constantly monitors the current market data and calculates the values of the AO, AC, and MACD indicators. It looks at the current value of each indicator and compares it to the previous value.
-
Direction Determination:
- For each indicator (AO, AC, and MACD), the script determines its direction:
- "Up": If the current value of the indicator is higher than its previous value, the script considers it to be trending "up".
- "Down": If the current value is lower than its previous value, the script considers it to be trending "down".
- For each indicator (AO, AC, and MACD), the script determines its direction:
-
Panel Display:
- The script creates a small panel on your chart that displays the name of each indicator (AO, AC, MACD).
- Next to each indicator name, it shows a symbol (an arrow in this case) that represents the indicator's direction. This symbol will change color based on whether the indicator is trending "up" or "down". Colors are defined at the beginning of the script.
-
Customization:
- The best part is that the script is customizable! You can tweak the settings (colors, location, etc.) to make the panel look and feel exactly the way you want it on your chart.
In essence, this script automates the process of quickly glancing at these three Bill Williams indicators. Instead of having to manually add each indicator to your chart and interpret them individually, the script gives you a consolidated view of their current direction in a simple, visual panel.
//+------------------------------------------------------------------+
//| Williams_Inds.mq4 |
//| Denis Orlov |
//| http://denis-or-love.narod.ru |
/*
Ïåðåìåùàåìàÿ ïàíåëü ñ èíäèêàòîðàìè Á.Âèëüÿìñà, äëÿ ñòðàòåãèè Òîðãîâûé õàîñ.
Ïîêàçûâàåò íàïðàâëåíèå èíäèêàòîðîâ AO, AC, è MACD.
http://codebase.mql4.com/ru/6318
The moved panel with the indicators of B.Williams, for strategy Trading chaos.
It shows a direction of indicators AO, AC, and MACD.
http://codebase.mql4.com/6319
Äåíèñ Îðëîâ
http://denis-or-love.narod.ru
***
Âñå ìîè èíäèêàòîðû:
http://codebase.mql4.com/ru/author/denis_orlov
***
ÏÎËÜÇÓÉÒÅÑÜ È ÏÐÎÖÂÅÒÀÉÒÅ!
*/
//+------------------------------------------------------------------+
#property copyright "Denis Orlov"
#property link "http://denis-or-love.narod.ru"
#property indicator_chart_window
#define Pref "B.Williams PanelS: "
extern string note1="Parameters of MACD:";
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern string note2="Coordinates:";
extern int X=20;
extern int Y=50;
extern int RowStep=12;
extern int ColStep=17;
extern int Corner=1;
extern int FSize=10;
//extern int H=0;
extern string note3="Colors, two themes:";
extern color RectClr=Gray;
extern color TxtClr=White;
extern color UpClr=Lime;
extern color DnClr=Red;
extern bool White_Chart_Theme=True;
extern color RectClr1=Gray;
extern color TxtClr1=Maroon;
extern color UpClr1=Green;
extern color DnClr1=Red;
int TimeX;
double PriceY;
int codeAO, codeAC, codeMACD;
color ClrAO , ClrAC, ClrMACD ;
//bool Alert_=False;
//color Alert_Clr=Red;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
if(White_Chart_Theme)
{
RectClr=RectClr1;
TxtClr=TxtClr1;
UpClr=UpClr1;
DnClr=DnClr1;
}
DrawPanel();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
Delete_My_Obj(Pref);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
if ( iAO( NULL , Period(), 1)< iAO( NULL , Period(), 0) )
{codeAO=217; ClrAO=UpClr; } else
{codeAO=218; ClrAO=DnClr;}
if (iAC( NULL , Period(), 1)<iAC( NULL , Period(), 0))
{codeAC=217; ClrAC=UpClr;} else
{codeAC=218; ClrAC=DnClr;} /* */
if( iMACD( NULL , Period(),
FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, 1)< iMACD( NULL , Period(),
FastEMA, SlowEMA, SignalSMA, PRICE_CLOSE, MODE_MAIN, 0) )
{codeMACD=217; ClrMACD=UpClr;} else
{codeMACD=218; ClrMACD=DnClr;}
/* if(Alert_)
{
if(codeAO==217 && codeAC==217 && codeMACD==217)
{Alert(Symbol()+" "+PeriodToStr(Period())
+" : AO, AC and MACD are UP at "+TimeToStr(TimeCurrent(),TIME_MINUTES));
ObjectDelete(Pref+"Unidirection Alert"); }
if(codeAO==218 && codeAC==218 && codeMACD==218)
{Alert(Symbol()+" "+PeriodToStr(Period())
+" : AO, AC and MACD are DOWN at "+TimeToStr(TimeCurrent(),TIME_MINUTES) );
ObjectDelete(Pref+"Unidirection Alert"); }
}
if(ObjectFind(Pref+"Unidirection Alert")<0)
Alert_=!Alert_;
if(Alert_)Alert_Clr=UpClr; else Alert_Clr=DnClr;*/
DrawPanel();
//----
return(0);
}
//+------------------------------------------------------------------+
int DrawText( string name, datetime T, double P, string Text, int code=0, color Clr=Green, int Fsize=10, int Win=0)
{
if (name=="") name="Text_"+T;
int Error=ObjectFind(name);// Çàïðîñ
if (Error!=Win)// Åñëè îáúåêòà â óê. îêíå íåò :(
{
ObjectCreate(name, OBJ_TEXT, Win, T, P);
}
ObjectSet(name, OBJPROP_TIME1, T);
ObjectSet(name, OBJPROP_PRICE1, P);
if(code==0)
ObjectSetText(name, Text ,Fsize,"Arial",Clr);
else
ObjectSetText(name, CharToStr(code), Fsize,"Wingdings",Clr);
}
//--------------------------------------
void DrawPanel()
{ if(Y<0) Y=0;
//if(Y>(WindowPriceMax()-WindowPriceMin())/Point-H)
// Y=(WindowPriceMax()-WindowPriceMin())/Point-H;
// TimeX=Time[WindowFirstVisibleBar()]+X*Period()*60;
// PriceY=WindowPriceMax()-Y*Point;
// DrawRect( Pref+"Rect", TimeX, PriceY, TimeX+TimeW ,PriceY-PriceH, RectClr, 1, "");
// DrawText( Pref+"Allow Hand Moving", TimeX+1*Period()*60, PriceY-1*Point, "", 73, HandClr );
//DrawText( Pref+"Unidirection Alert", TimeX+1*Period()*60, PriceY-(1+StepS)*Point, "", 37, Alert_Clr );
// DrawText( Pref+"AO", TimeX+4*Period()*60, PriceY-1*Point, "AO", 0,TxtClr );//0, 10, 0
// DrawText( Pref+"AC", TimeX+4*Period()*60, PriceY-(1+StepS)*Point, "AC", 0,TxtClr );
// DrawText( Pref+"MACD", TimeX+3*Period()*60, PriceY-(1+2*StepS)*Point, "MACD", 0,TxtClr );
// DrawText( Pref+"AO direction", TimeX+8*Period()*60, PriceY-1*Point, "", codeAO, ClrAO );
// DrawText( Pref+"AC direction", TimeX+8*Period()*60, PriceY-(1+StepS)*Point, "", codeAC, ClrAC );
// DrawText( Pref+"MACD direction", TimeX+8*Period()*60, PriceY-(1+2*StepS)*Point, "", codeMACD, ClrMACD );
DrawLabels(Pref+"AO", Corner, X, Y, "AO", 0,TxtClr, 0, FSize);
DrawLabels(Pref+"AC", Corner, X, Y+RowStep, "AC",0, TxtClr, 0, FSize);
DrawLabels(Pref+"MACD", Corner, X, Y+RowStep*2, "MACD", 0,TxtClr, 0, FSize);
DrawLabels(Pref+"AO direction", Corner, X-ColStep, Y, "", codeAO,ClrAO, 0, FSize);
DrawLabels(Pref+"AC direction", Corner, X-ColStep, Y+RowStep, "", codeAC, ClrAC, 0, FSize);
DrawLabels(Pref+"MACD direction", Corner, X-ColStep, Y+RowStep*2, "", codeMACD, ClrMACD, 0, FSize);
}
//---------------------------------
int DrawRect( string name, datetime T1, double P1,datetime T2, double P2,
color Clr=Green, int Width=1, string Text="", int Win=0)
{
if (name=="") name="Text_"+T1;
int Error=ObjectFind(name);// Çàïðîñ
if (Error!=Win)// Åñëè îáúåêòà â óê. îêíå íåò :(
{
ObjectCreate(name, OBJ_RECTANGLE, Win,T1,P1,T2,P2);//ñîçäàíèå òðåíäîâîé ëèíèè
}
ObjectSet(name, OBJPROP_TIME1 ,T1);
ObjectSet(name, OBJPROP_PRICE1,P1);
ObjectSet(name, OBJPROP_TIME2 ,T2);
ObjectSet(name, OBJPROP_PRICE2,P2);
ObjectSet(name,OBJPROP_BACK, false);
ObjectSet(name,OBJPROP_STYLE,0);
ObjectSet(name, OBJPROP_COLOR , Clr);
ObjectSet(name, OBJPROP_WIDTH , Width);
ObjectSetText(name,Text);
}
///-----------------------
void Delete_My_Obj(string Prefix)
{//Alert(ObjectsTotal());
for(int k=ObjectsTotal()-1; k>=0; k--) // Ïî êîëè÷åñòâó âñåõ îáúåêòîâ
{
string Obj_Name=ObjectName(k); // Çàïðàøèâàåì èìÿ îáúåêòà
string Head=StringSubstr(Obj_Name,0,StringLen(Prefix));// Èçâëåêàåì ïåðâûå ñèì
if (Head==Prefix)// Íàéäåí îáúåêò, ..
{
ObjectDelete(Obj_Name);
//Alert(Head+";"+Prefix);
}
}
}
///=====================
string PeriodToStr(int Per)
{
switch(Per) // Ðàñ÷¸ò äëÿ..
{ // .. ðàçëè÷íûõ ÒÔ
case 1: return("M1"); break;// Òàéìôðåéì Ì1
case 5: return("M5"); break;// Òàéìôðåéì Ì5
case 15: return("M15"); break;// Òàéìôðåéì Ì15
case 30: return("M30"); break;// Òàéìôðåéì Ì30
case 60: return("H1"); break;// Òàéìôðåéì H1
case 240: return("H4"); break;// Òàéìôðåéì H4
case 1440: return("D1"); break;// Òàéìôðåéì D1
case 10080: return("W1"); break;// Òàéìôðåéì W1
case 43200: return("ÌN"); break;// Òàéìôðåéì ÌN
}
}
//==================================
/*int CalculeH()
{
switch(Period()) // Ðàñ÷¸ò äëÿ..
{ // .. ðàçëè÷íûõ ÒÔ
case 1: return(15); break;// Òàéìôðåéì Ì1
case 5: return(15); break;// Òàéìôðåéì Ì5
case 15: return(30); break;// Òàéìôðåéì Ì15
case 30: return(45); break;// Òàéìôðåéì Ì30
case 60: return(60); break;// Òàéìôðåéì H1
case 240: return(180); break;// Òàéìôðåéì H4
case 1440: return(270); break;// Òàéìôðåéì D1
case 10080: return(450); break;// Òàéìôðåéì W1
case 43200: return(900); break;// Òàéìôðåéì ÌN
}
}*/
int DrawLabels(string name, int corn, int X, int Y, string Text, int code=0, color Clr=Green, int Win=0, int FSize=10)
{
int Error=ObjectFind(name);// Çàïðîñ
if (Error!=Win)// Åñëè îáúåêòà â óê. îêíå íåò :(
{
ObjectCreate(name,OBJ_LABEL,Win, 0,0); // Ñîçäàíèå îáúåêòà
}
ObjectSet(name, OBJPROP_CORNER, corn); // Ïðèâÿçêà ê óãëó
ObjectSet(name, OBJPROP_XDISTANCE, X); // Êîîðäèíàòà Õ
ObjectSet(name,OBJPROP_YDISTANCE,Y);// Êîîðäèíàòà Y
ObjectSetText(name,Text,FSize,"Arial",Clr);
if(code==0)
ObjectSetText(name, Text ,FSize,"Arial",Clr);
else
ObjectSetText(name, CharToStr(code), FSize,"Wingdings",Clr);
} }
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
---